bun_plugins 1.2.2 ā 1.2.5
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 +125 -1
- package/dist/examples/action-registry-declarative.d.ts +14 -0
- package/dist/examples/action-registry-declarative.d.ts.map +1 -0
- package/dist/examples/action-registry-declarative.js +130 -0
- package/dist/examples/action-registry-declarative.js.map +1 -0
- package/dist/examples/action-registry-example.d.ts +31 -0
- package/dist/examples/action-registry-example.d.ts.map +1 -0
- package/dist/examples/action-registry-example.js +84 -0
- package/dist/examples/action-registry-example.js.map +1 -0
- package/dist/examples/index-declarative.d.ts +32 -0
- package/dist/examples/index-declarative.d.ts.map +1 -0
- package/dist/examples/index-declarative.js +206 -0
- package/dist/examples/index-declarative.js.map +1 -0
- package/dist/examples/logger-declarative.d.ts +109 -0
- package/dist/examples/logger-declarative.d.ts.map +1 -0
- package/dist/examples/logger-declarative.js +330 -0
- package/dist/examples/logger-declarative.js.map +1 -0
- package/dist/examples/logger-simple.d.ts +8 -0
- package/dist/examples/logger-simple.d.ts.map +1 -0
- package/dist/examples/logger-simple.js +165 -0
- package/dist/examples/logger-simple.js.map +1 -0
- package/dist/examples/server-declarative.d.ts +46 -0
- package/dist/examples/server-declarative.d.ts.map +1 -0
- package/dist/examples/server-declarative.js +205 -0
- package/dist/examples/server-declarative.js.map +1 -0
- package/dist/examples/shared/action-registry.d.ts +45 -0
- package/dist/examples/shared/action-registry.d.ts.map +1 -0
- package/dist/examples/shared/action-registry.js +65 -0
- package/dist/examples/shared/action-registry.js.map +1 -0
- package/dist/examples/shared/plugin-builder.d.ts +41 -0
- package/dist/examples/shared/plugin-builder.d.ts.map +1 -0
- package/dist/examples/shared/plugin-builder.js +85 -0
- package/dist/examples/shared/plugin-builder.js.map +1 -0
- package/dist/examples/storage-declarative.d.ts +13 -0
- package/dist/examples/storage-declarative.d.ts.map +1 -0
- package/dist/examples/storage-declarative.js +203 -0
- package/dist/examples/storage-declarative.js.map +1 -0
- package/dist/plugins/ActionRegistryPlugin.d.ts +0 -9
- package/dist/plugins/ActionRegistryPlugin.d.ts.map +1 -1
- package/dist/plugins/ActionRegistryPlugin.js +6 -10
- package/dist/plugins/ActionRegistryPlugin.js.map +1 -1
- package/dist/plugins/ExamplePlugin.d.ts +3 -0
- package/dist/plugins/ExamplePlugin.d.ts.map +1 -0
- package/dist/plugins/ExamplePlugin.js +24 -0
- package/dist/plugins/ExamplePlugin.js.map +1 -0
- package/dist/plugins/MathPlugin.d.ts.map +1 -1
- package/dist/plugins/MathPlugin.js +5 -0
- package/dist/plugins/MathPlugin.js.map +1 -1
- package/dist/plugins/TypedExamplePlugin.d.ts +10 -0
- package/dist/plugins/TypedExamplePlugin.d.ts.map +1 -0
- package/dist/plugins/TypedExamplePlugin.js +61 -0
- package/dist/plugins/TypedExamplePlugin.js.map +1 -0
- package/dist/src/PluginManager.d.ts +4 -0
- package/dist/src/PluginManager.d.ts.map +1 -1
- package/dist/src/PluginManager.js +35 -11
- package/dist/src/PluginManager.js.map +1 -1
- package/dist/src/managers/ContextFactory.d.ts.map +1 -1
- package/dist/src/managers/ContextFactory.js +17 -15
- package/dist/src/managers/ContextFactory.js.map +1 -1
- package/dist/src/types/plugin-registry-base.d.ts +10 -6
- package/dist/src/types/plugin-registry-base.d.ts.map +1 -1
- package/dist/src/types/plugin-registry-base.js +1 -1
- package/dist/src/types.d.ts +8 -5
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +2 -2
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/pluginValidator.d.ts.map +1 -1
- package/dist/src/utils/pluginValidator.js +0 -1
- package/dist/src/utils/pluginValidator.js.map +1 -1
- package/dist/src/worker/WorkerRunner.js +5 -0
- package/dist/src/worker/WorkerRunner.js.map +1 -1
- package/package.json +4 -2
- package/dist/src/types/arktype_converter.d.ts +0 -19
- package/dist/src/types/arktype_converter.d.ts.map +0 -1
- package/dist/src/types/arktype_converter.js +0 -73
- package/dist/src/types/arktype_converter.js.map +0 -1
- package/dist/src/types/generator.d.ts +0 -9
- package/dist/src/types/generator.d.ts.map +0 -1
- package/dist/src/types/generator.js +0 -9
- package/dist/src/types/generator.js.map +0 -1
- package/dist/src/types/interfaces.d.ts +0 -55
- package/dist/src/types/interfaces.d.ts.map +0 -1
- package/dist/src/types/interfaces.js +0 -5
- package/dist/src/types/interfaces.js.map +0 -1
- package/dist/src/types/plugin-registry.d.ts +0 -2
- package/dist/src/types/plugin-registry.d.ts.map +0 -1
- package/dist/src/types/plugin-registry.js +0 -4
- package/dist/src/types/plugin-registry.js.map +0 -1
- package/dist/src/types/plugin_generator.d.ts +0 -56
- package/dist/src/types/plugin_generator.d.ts.map +0 -1
- package/dist/src/types/plugin_generator.js +0 -619
- package/dist/src/types/plugin_generator.js.map +0 -1
package/README.md
CHANGED
|
@@ -182,6 +182,130 @@ export class ConsumerPlugin implements IPlugin {
|
|
|
182
182
|
|
|
183
183
|
---
|
|
184
184
|
|
|
185
|
-
##
|
|
185
|
+
## šÆ Type Safety & Autocompletion
|
|
186
|
+
|
|
187
|
+
The plugin system provides **full type safety and autocompletion** for inter-plugin communication using declaration merging.
|
|
188
|
+
|
|
189
|
+
### š Complete Guide
|
|
190
|
+
|
|
191
|
+
For detailed documentation on the type system, see [`docs/types-guide.md`](docs/types-guide.md).
|
|
192
|
+
|
|
193
|
+
### š Quick Start
|
|
194
|
+
|
|
195
|
+
#### Step 1: Create a types file
|
|
196
|
+
|
|
197
|
+
Create a `.d.ts` file in your project (e.g., `plugins/types.d.ts`):
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import type { BasePluginApi } from "bun_plugins/src/types/plugin-registry-base";
|
|
201
|
+
|
|
202
|
+
// Define the API interface for your plugin
|
|
203
|
+
export interface MathPluginApi extends BasePluginApi {
|
|
204
|
+
add(a: number, b: number): number;
|
|
205
|
+
multiply(a: number, b: number): number;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Extend the PluginFactory with your plugin
|
|
209
|
+
declare module "bun_plugins" {
|
|
210
|
+
export interface PluginFactory {
|
|
211
|
+
"math-plugin": {
|
|
212
|
+
name: "math-plugin";
|
|
213
|
+
version: "1.0.0";
|
|
214
|
+
class: any;
|
|
215
|
+
api: MathPluginApi;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### Step 2: Register the API in your plugin
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { Plugin, PluginContext } from "bun_plugins";
|
|
225
|
+
|
|
226
|
+
export class MathPlugin extends Plugin {
|
|
227
|
+
name = "math-plugin";
|
|
228
|
+
version = "1.0.0";
|
|
229
|
+
|
|
230
|
+
override onLoad(context: PluginContext) {
|
|
231
|
+
// Register the API for other plugins to use
|
|
232
|
+
context.registerApi({
|
|
233
|
+
add: this.add.bind(this),
|
|
234
|
+
multiply: this.multiply.bind(this)
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
add(a: number, b: number): number {
|
|
239
|
+
return a + b;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
multiply(a: number, b: number): number {
|
|
243
|
+
return a * b;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
#### Step 3: Use with full autocompletion
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import { definePlugin } from "bun_plugins";
|
|
252
|
+
|
|
253
|
+
export default definePlugin({
|
|
254
|
+
name: "my-app",
|
|
255
|
+
version: "1.0.0",
|
|
256
|
+
|
|
257
|
+
async onLoad(context) {
|
|
258
|
+
// ā
Full autocompletion and type safety!
|
|
259
|
+
const mathPlugin = await context.getPlugin('math-plugin');
|
|
260
|
+
|
|
261
|
+
if (mathPlugin) {
|
|
262
|
+
const result = mathPlugin.add(1, 2); // ā
Autocompletion works
|
|
263
|
+
context.log.info(`Result: ${result}`);
|
|
264
|
+
|
|
265
|
+
// TypeScript will show errors for non-existent methods
|
|
266
|
+
// mathPlugin.nonExistentMethod(); // ā Error!
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### ⨠Benefits
|
|
273
|
+
|
|
274
|
+
- šÆ **Full Autocompletion**: Your IDE shows all available methods
|
|
275
|
+
- š **Type Safety**: TypeScript catches errors at compile time
|
|
276
|
+
- š **Self-Documenting**: Interfaces serve as API documentation
|
|
277
|
+
- š **Refactor-Friendly**: Safe method renaming and refactoring
|
|
278
|
+
- š **Works with External Plugins**: Extend types for npm packages too
|
|
279
|
+
|
|
280
|
+
### š Examples
|
|
281
|
+
|
|
282
|
+
- [`plugins/types.d.ts`](plugins/types.d.ts) - Complete example for this project
|
|
283
|
+
- [`plugins/TypedExamplePlugin.ts`](plugins/TypedExamplePlugin.ts) - Plugin using typed access
|
|
284
|
+
- [`examples/types-extension-example.d.ts`](examples/types-extension-example.d.ts) - Standalone example
|
|
285
|
+
|
|
286
|
+
### š§ TypeScript Configuration
|
|
287
|
+
|
|
288
|
+
Ensure your `tsconfig.json` includes the types file:
|
|
289
|
+
|
|
290
|
+
```json
|
|
291
|
+
{
|
|
292
|
+
"include": [
|
|
293
|
+
"src/**/*",
|
|
294
|
+
"plugins/**/*",
|
|
295
|
+
"**/*.d.ts"
|
|
296
|
+
]
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### š” Tips
|
|
301
|
+
|
|
302
|
+
1. **Match names exactly**: The plugin name in `PluginFactory` must match `plugin.name`
|
|
303
|
+
2. **Register APIs**: Always use `context.registerApi()` to expose your plugin's API
|
|
304
|
+
3. **Extend BasePluginApi**: Your API interfaces should extend `BasePluginApi` for consistency
|
|
305
|
+
4. **External plugins**: You can extend types for third-party plugins the same way
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## License
|
|
186
310
|
|
|
187
311
|
MIT Ā© [memelser](https://github.com/nglmercer)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative Action Registry Example
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates a clean, declarative approach to building
|
|
5
|
+
* plugins with action registries using shared utilities.
|
|
6
|
+
*/
|
|
7
|
+
declare const createRegistryPlugin: () => import("bun_plugins").IPlugin;
|
|
8
|
+
declare const createMathPlugin: () => import("bun_plugins").IPlugin;
|
|
9
|
+
declare const createTextPlugin: () => import("bun_plugins").IPlugin;
|
|
10
|
+
declare const createUtilityPlugin: () => import("bun_plugins").IPlugin;
|
|
11
|
+
declare const demonstrateDeclarativeActionRegistry: () => Promise<void>;
|
|
12
|
+
declare const demonstrateDynamicLoading: () => Promise<void>;
|
|
13
|
+
export { createRegistryPlugin, createMathPlugin, createTextPlugin, createUtilityPlugin, demonstrateDeclarativeActionRegistry, demonstrateDynamicLoading };
|
|
14
|
+
//# sourceMappingURL=action-registry-declarative.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-registry-declarative.d.ts","sourceRoot":"","sources":["../../examples/action-registry-declarative.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,QAAA,MAAM,oBAAoB,qCAUxB,CAAC;AAGH,QAAA,MAAM,gBAAgB,qCAMpB,CAAC;AAEH,QAAA,MAAM,gBAAgB,qCAMpB,CAAC;AAEH,QAAA,MAAM,mBAAmB,qCAMvB,CAAC;AA4CH,QAAA,MAAM,oCAAoC,qBA2CzC,CAAC;AAGF,QAAA,MAAM,yBAAyB,qBAS9B,CAAC;AAGF,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,oCAAoC,EACpC,yBAAyB,EAC1B,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative Action Registry Example
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates a clean, declarative approach to building
|
|
5
|
+
* plugins with action registries using shared utilities.
|
|
6
|
+
*/
|
|
7
|
+
import { PluginManager } from "../src/PluginManager";
|
|
8
|
+
import { mathActions, textActions, utilityActions, createActionRegistry } from "./shared/action-registry";
|
|
9
|
+
import { createPlugin, createActionPlugin, runDemo } from "./shared/plugin-builder";
|
|
10
|
+
// Central registry plugin - declarative definition
|
|
11
|
+
const createRegistryPlugin = () => createPlugin({
|
|
12
|
+
name: "action-registry",
|
|
13
|
+
version: "1.0.0",
|
|
14
|
+
description: "Central action registry for all plugins",
|
|
15
|
+
onLoad: async (context) => {
|
|
16
|
+
context.log.info("ActionRegistry initialized");
|
|
17
|
+
},
|
|
18
|
+
sharedApi: createActionRegistry()
|
|
19
|
+
});
|
|
20
|
+
// Action plugins - declarative definitions
|
|
21
|
+
const createMathPlugin = () => createActionPlugin({
|
|
22
|
+
name: "math-actions",
|
|
23
|
+
version: "1.0.0",
|
|
24
|
+
description: "Mathematical operations",
|
|
25
|
+
registryName: "action-registry",
|
|
26
|
+
actionCategories: [mathActions]
|
|
27
|
+
});
|
|
28
|
+
const createTextPlugin = () => createActionPlugin({
|
|
29
|
+
name: "text-actions",
|
|
30
|
+
version: "1.0.0",
|
|
31
|
+
description: "Text transformation operations",
|
|
32
|
+
registryName: "action-registry",
|
|
33
|
+
actionCategories: [textActions]
|
|
34
|
+
});
|
|
35
|
+
const createUtilityPlugin = () => createActionPlugin({
|
|
36
|
+
name: "utility-actions",
|
|
37
|
+
version: "1.0.0",
|
|
38
|
+
description: "Utility functions",
|
|
39
|
+
registryName: "action-registry",
|
|
40
|
+
actionCategories: [utilityActions]
|
|
41
|
+
});
|
|
42
|
+
// Demo runner with declarative test cases
|
|
43
|
+
const runActionTests = async (registry) => {
|
|
44
|
+
const testCases = [
|
|
45
|
+
{ category: "Math", tests: [
|
|
46
|
+
{ action: "sum", args: [5, 3], expected: 8 },
|
|
47
|
+
{ action: "multiply", args: [4, 7], expected: 28 },
|
|
48
|
+
{ action: "power", args: [2, 8], expected: 256 }
|
|
49
|
+
] },
|
|
50
|
+
{ category: "Text", tests: [
|
|
51
|
+
{ action: "uppercase", args: ["hello world"], expected: "HELLO WORLD" },
|
|
52
|
+
{ action: "reverse", args: ["javascript"], expected: "tpircsavaj" }
|
|
53
|
+
] },
|
|
54
|
+
{ category: "Utility", tests: [
|
|
55
|
+
{ action: "timestamp", args: [], validator: (result) => result > 0 }
|
|
56
|
+
] }
|
|
57
|
+
];
|
|
58
|
+
for (const { category, tests } of testCases) {
|
|
59
|
+
console.log(`\n${category} Operations:`);
|
|
60
|
+
for (const test of tests) {
|
|
61
|
+
try {
|
|
62
|
+
const result = registry.execute(test.action, ...test.args);
|
|
63
|
+
if ('expected' in test && test.expected !== undefined) {
|
|
64
|
+
console.log(` ${test.action}(${test.args.join(', ')}) = ${result}`);
|
|
65
|
+
}
|
|
66
|
+
else if ('validator' in test && test.validator) {
|
|
67
|
+
console.log(` ${test.action}() = ${test.validator(result) ? 'ā' : 'ā'}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error(` ${test.action} failed:`, error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
// Main demonstration
|
|
77
|
+
const demonstrateDeclarativeActionRegistry = async () => {
|
|
78
|
+
const manager = new PluginManager();
|
|
79
|
+
// Create plugin instances
|
|
80
|
+
const registryPlugin = createRegistryPlugin();
|
|
81
|
+
const mathPlugin = createMathPlugin();
|
|
82
|
+
const textPlugin = createTextPlugin();
|
|
83
|
+
const utilityPlugin = createUtilityPlugin();
|
|
84
|
+
// Register plugins in dependency order
|
|
85
|
+
await manager.register(registryPlugin);
|
|
86
|
+
await manager.register(mathPlugin);
|
|
87
|
+
await manager.register(textPlugin);
|
|
88
|
+
await manager.register(utilityPlugin);
|
|
89
|
+
// Get the registry
|
|
90
|
+
const registry = manager.getPluginApi("action-registry");
|
|
91
|
+
if (!registry) {
|
|
92
|
+
throw new Error("Registry plugin not found");
|
|
93
|
+
}
|
|
94
|
+
console.log("\nAvailable Actions:");
|
|
95
|
+
registry.list().forEach(action => console.log(` - ${action}`));
|
|
96
|
+
// Run tests
|
|
97
|
+
await runActionTests(registry);
|
|
98
|
+
// Error handling demo
|
|
99
|
+
console.log("\nError Handling:");
|
|
100
|
+
try {
|
|
101
|
+
registry.execute("non-existent-action");
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.log(` Caught error: ${error.message}`);
|
|
105
|
+
}
|
|
106
|
+
// Plugin info
|
|
107
|
+
console.log("\nPlugin Information:");
|
|
108
|
+
["math-actions", "text-actions", "utility-actions"].forEach(pluginName => {
|
|
109
|
+
const api = manager.getPluginApi(pluginName);
|
|
110
|
+
if (api?.actions) {
|
|
111
|
+
console.log(` ${pluginName}: ${api.actions.join(", ")}`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
// Dynamic loading example
|
|
116
|
+
const demonstrateDynamicLoading = async () => {
|
|
117
|
+
const { join } = await import("node:path");
|
|
118
|
+
const manager = new PluginManager();
|
|
119
|
+
console.log("\nLoading plugins dynamically from directory...");
|
|
120
|
+
await manager.loadPluginsFromDirectory(join(process.cwd(), "plugins"));
|
|
121
|
+
const loaded = manager.listPlugins();
|
|
122
|
+
console.log(`Loaded ${loaded.length} plugins: ${loaded.join(", ")}`);
|
|
123
|
+
};
|
|
124
|
+
// Export for use
|
|
125
|
+
export { createRegistryPlugin, createMathPlugin, createTextPlugin, createUtilityPlugin, demonstrateDeclarativeActionRegistry, demonstrateDynamicLoading };
|
|
126
|
+
// Run if called directly
|
|
127
|
+
if (import.meta.main) {
|
|
128
|
+
runDemo("Declarative Action Registry Demo", demonstrateDeclarativeActionRegistry);
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=action-registry-declarative.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-registry-declarative.js","sourceRoot":"","sources":["../../examples/action-registry-decl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AM,CAAC,WAAW,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC;IAEpC,OAAO,CAAC,GAAG,CAAC,iDAAiD,CAAC,CAAC;IAC/D,MAAM,OAAO,CAAC,wBAAwB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IAEvE,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,UAAU,MAAM,CAAC,MAAM,aAAa,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACvE,CAAC,CAAC;AAEF,iBAAiB;AACjB,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,oCAAoC,EACpC,yBAAyB,EAC1B,CAAC;AAEF,yBAAyB;AACzB,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACrB,OAAO,CAAC,kCAAkC,EAAE,oCAAoC,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action Registry Example - Simple implementation for testing
|
|
3
|
+
*/
|
|
4
|
+
import type { IPlugin, PluginContext } from "../src/types";
|
|
5
|
+
export declare class ActionRegistryPlugin implements IPlugin {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
private actionRegistry;
|
|
9
|
+
constructor();
|
|
10
|
+
onLoad(context: PluginContext): void;
|
|
11
|
+
onUnload(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare class MathActionsPlugin implements IPlugin {
|
|
14
|
+
name: string;
|
|
15
|
+
version: string;
|
|
16
|
+
dependencies: {
|
|
17
|
+
"action-registry": string;
|
|
18
|
+
};
|
|
19
|
+
onLoad(context: PluginContext): Promise<void>;
|
|
20
|
+
onUnload(): void;
|
|
21
|
+
}
|
|
22
|
+
export declare class TextActionsPlugin implements IPlugin {
|
|
23
|
+
name: string;
|
|
24
|
+
version: string;
|
|
25
|
+
dependencies: {
|
|
26
|
+
"action-registry": string;
|
|
27
|
+
};
|
|
28
|
+
onLoad(context: PluginContext): Promise<void>;
|
|
29
|
+
onUnload(): void;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=action-registry-example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-registry-example.d.ts","sourceRoot":"","sources":["../../examples/action-registry-example.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA4B3D,qBAAa,oBAAqB,YAAW,OAAO;IAClD,IAAI,SAAqB;IACzB,OAAO,SAAW;IAClB,OAAO,CAAC,cAAc,CAAiB;;IAMvC,MAAM,CAAC,OAAO,EAAE,aAAa;IAa7B,QAAQ;CAGT;AAED,qBAAa,iBAAkB,YAAW,OAAO;IAC/C,IAAI,SAAkB;IACtB,OAAO,SAAW;IAClB,YAAY;;MAEV;IAEI,MAAM,CAAC,OAAO,EAAE,aAAa;IAWnC,QAAQ;CAGT;AAED,qBAAa,iBAAkB,YAAW,OAAO;IAC/C,IAAI,SAAkB;IACtB,OAAO,SAAW;IAClB,YAAY;;MAEV;IAEI,MAAM,CAAC,OAAO,EAAE,aAAa;IAYnC,QAAQ;CAGT"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action Registry Example - Simple implementation for testing
|
|
3
|
+
*/
|
|
4
|
+
class ActionRegistry {
|
|
5
|
+
actionHandlers = new Map();
|
|
6
|
+
registerAction(type, handler) {
|
|
7
|
+
this.actionHandlers.set(type, handler);
|
|
8
|
+
}
|
|
9
|
+
executeAction(type, ...args) {
|
|
10
|
+
const handler = this.actionHandlers.get(type);
|
|
11
|
+
if (!handler) {
|
|
12
|
+
throw new Error(`Acción no encontrada: ${type}`);
|
|
13
|
+
}
|
|
14
|
+
return handler(...args);
|
|
15
|
+
}
|
|
16
|
+
listActions() {
|
|
17
|
+
return Array.from(this.actionHandlers.keys());
|
|
18
|
+
}
|
|
19
|
+
hasAction(type) {
|
|
20
|
+
return this.actionHandlers.has(type);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class ActionRegistryPlugin {
|
|
24
|
+
name = "action-registry";
|
|
25
|
+
version = "1.0.0";
|
|
26
|
+
actionRegistry;
|
|
27
|
+
constructor() {
|
|
28
|
+
this.actionRegistry = new ActionRegistry();
|
|
29
|
+
}
|
|
30
|
+
onLoad(context) {
|
|
31
|
+
context.log.info("ActionRegistry initialized");
|
|
32
|
+
// Register the API manually using the new system
|
|
33
|
+
context.registerApi({
|
|
34
|
+
registerAction: this.actionRegistry.registerAction.bind(this.actionRegistry),
|
|
35
|
+
executeAction: this.actionRegistry.executeAction.bind(this.actionRegistry),
|
|
36
|
+
listActions: this.actionRegistry.listActions.bind(this.actionRegistry),
|
|
37
|
+
hasAction: this.actionRegistry.hasAction.bind(this.actionRegistry),
|
|
38
|
+
actions: this.actionRegistry.listActions()
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
onUnload() {
|
|
42
|
+
// Cleanup is handled by the plugin manager
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export class MathActionsPlugin {
|
|
46
|
+
name = "math-actions";
|
|
47
|
+
version = "1.0.0";
|
|
48
|
+
dependencies = {
|
|
49
|
+
"action-registry": "1.0.0"
|
|
50
|
+
};
|
|
51
|
+
async onLoad(context) {
|
|
52
|
+
const actionRegistry = await context.getPlugin("action-registry");
|
|
53
|
+
if (actionRegistry) {
|
|
54
|
+
actionRegistry.registerAction("sum", (a, b) => a + b);
|
|
55
|
+
actionRegistry.registerAction("multiply", (a, b) => a * b);
|
|
56
|
+
actionRegistry.registerAction("power", (base, exp) => Math.pow(base, exp));
|
|
57
|
+
context.log.info("Math actions registered");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
onUnload() {
|
|
61
|
+
// Cleanup is handled by the plugin manager
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export class TextActionsPlugin {
|
|
65
|
+
name = "text-actions";
|
|
66
|
+
version = "1.0.0";
|
|
67
|
+
dependencies = {
|
|
68
|
+
"action-registry": "1.0.0"
|
|
69
|
+
};
|
|
70
|
+
async onLoad(context) {
|
|
71
|
+
const actionRegistry = await context.getPlugin("action-registry");
|
|
72
|
+
if (actionRegistry) {
|
|
73
|
+
actionRegistry.registerAction("uppercase", (text) => text.toUpperCase());
|
|
74
|
+
actionRegistry.registerAction("lowercase", (text) => text.toLowerCase());
|
|
75
|
+
actionRegistry.registerAction("reverse", (text) => text.split('').reverse().join(''));
|
|
76
|
+
actionRegistry.registerAction("wordCount", (text) => text.trim().split(/\s+/).filter(word => word.length > 0).length);
|
|
77
|
+
context.log.info("Text actions registered");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
onUnload() {
|
|
81
|
+
// Cleanup is handled by the plugin manager
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=action-registry-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-registry-example.js","sourceRoot":"","sources":["../../examples/action-registry-example.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,cAAc;IACR,cAAc,GAAqC,IAAI,GAAG,EAAE,CAAC;IAEvE,cAAc,CAAC,IAAY,EAAE,OAA4B;QACvD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,aAAa,CAAC,IAAY,EAAE,GAAG,IAAW;QACxC,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;QACnD,CAA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K,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;YAC9F,cAAc,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC9H,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,QAAQ;QACN,2CAA2C;IAC7C,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative Examples Index
|
|
3
|
+
*
|
|
4
|
+
* This file serves as the main entry point for all declarative examples,
|
|
5
|
+
* providing a clean overview and easy access to different use cases.
|
|
6
|
+
*/
|
|
7
|
+
import { demonstrateDeclarativeActionRegistry } from "./action-registry-declarative";
|
|
8
|
+
import { demonstrateDeclarativeStorage } from "./storage-declarative";
|
|
9
|
+
import { demonstrateDeclarativeLogging } from "./logger-declarative";
|
|
10
|
+
import { demonstrateDeclarativeServer } from "./server-declarative";
|
|
11
|
+
declare const exampleCatalog: ({
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
file: string;
|
|
16
|
+
demo: () => Promise<void>;
|
|
17
|
+
features: string[];
|
|
18
|
+
} | {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
file: string;
|
|
23
|
+
demo: () => Promise<Bun.Server<undefined>>;
|
|
24
|
+
features: string[];
|
|
25
|
+
})[];
|
|
26
|
+
declare const showMainMenu: () => void;
|
|
27
|
+
declare const runExample: (index: number) => Promise<void>;
|
|
28
|
+
declare const runAllExamples: () => Promise<void>;
|
|
29
|
+
declare const interactiveMenu: () => Promise<void>;
|
|
30
|
+
declare const quickRun: (exampleId: string) => Promise<void>;
|
|
31
|
+
export { exampleCatalog, showMainMenu, runExample, runAllExamples, interactiveMenu, quickRun, demonstrateDeclarativeActionRegistry, demonstrateDeclarativeStorage, demonstrateDeclarativeLogging, demonstrateDeclarativeServer };
|
|
32
|
+
//# sourceMappingURL=index-declarative.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-declarative.d.ts","sourceRoot":"","sources":["../../examples/index-declarative.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAE,oCAAoC,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAGpE,QAAA,MAAM,cAAc;;;;;;;;;;;;;;IAyDnB,CAAC;AAGF,QAAA,MAAM,YAAY,YAejB,CAAC;AAGF,QAAA,MAAM,UAAU,GAAU,OAAO,MAAM,kBAkBtC,CAAC;AAGF,QAAA,MAAM,cAAc,qBAgBnB,CAAC;AAGF,QAAA,MAAM,eAAe,qBAwCpB,CAAC;AAGF,QAAA,MAAM,QAAQ,GAAU,WAAW,MAAM,kBAmBxC,CAAC;AAGF,OAAO,EACL,cAAc,EACd,YAAY,EACZ,UAAU,EACV,cAAc,EACd,eAAe,EACf,QAAQ,EAER,oCAAoC,EACpC,6BAA6B,EAC7B,6BAA6B,EAC7B,4BAA4B,EAC7B,CAAC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative Examples Index
|
|
3
|
+
*
|
|
4
|
+
* This file serves as the main entry point for all declarative examples,
|
|
5
|
+
* providing a clean overview and easy access to different use cases.
|
|
6
|
+
*/
|
|
7
|
+
import { runDemo } from "./shared/plugin-builder";
|
|
8
|
+
// Import all declarative examples
|
|
9
|
+
import { demonstrateDeclarativeActionRegistry } from "./action-registry-declarative";
|
|
10
|
+
import { demonstrateDeclarativeStorage } from "./storage-declarative";
|
|
11
|
+
import { demonstrateDeclarativeLogging } from "./logger-declarative";
|
|
12
|
+
import { demonstrateDeclarativeServer } from "./server-declarative";
|
|
13
|
+
// Example catalog with descriptions
|
|
14
|
+
const exampleCatalog = [
|
|
15
|
+
{
|
|
16
|
+
id: 'action-registry',
|
|
17
|
+
name: 'Action Registry',
|
|
18
|
+
description: 'Declarative plugin system with action registration and execution',
|
|
19
|
+
file: 'action-registry-declarative.ts',
|
|
20
|
+
demo: demonstrateDeclarativeActionRegistry,
|
|
21
|
+
features: [
|
|
22
|
+
'Declarative action definitions',
|
|
23
|
+
'Plugin-based architecture',
|
|
24
|
+
'Dynamic action registration',
|
|
25
|
+
'Error handling',
|
|
26
|
+
'Plugin discovery'
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: 'storage',
|
|
31
|
+
name: 'Storage System',
|
|
32
|
+
description: 'Clean storage operations with declarative configuration',
|
|
33
|
+
file: 'storage-declarative.ts',
|
|
34
|
+
demo: demonstrateDeclarativeStorage,
|
|
35
|
+
features: [
|
|
36
|
+
'Declarative storage operations',
|
|
37
|
+
'CRUD operations',
|
|
38
|
+
'Configuration management',
|
|
39
|
+
'Data validation',
|
|
40
|
+
'Plugin isolation support'
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 'logging',
|
|
45
|
+
name: 'Logging System',
|
|
46
|
+
description: 'Flexible logging with multiple adapters and configurations',
|
|
47
|
+
file: 'logger-declarative.ts',
|
|
48
|
+
demo: demonstrateDeclarativeLogging,
|
|
49
|
+
features: [
|
|
50
|
+
'Multiple logger adapters',
|
|
51
|
+
'Hierarchical logging',
|
|
52
|
+
'Structured logging',
|
|
53
|
+
'Performance monitoring',
|
|
54
|
+
'Plugin-specific loggers'
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'server',
|
|
59
|
+
name: 'HTTP Server',
|
|
60
|
+
description: 'Plugin-powered HTTP server with declarative routing',
|
|
61
|
+
file: 'server-declarative.ts',
|
|
62
|
+
demo: demonstrateDeclarativeServer,
|
|
63
|
+
features: [
|
|
64
|
+
'Declarative route definitions',
|
|
65
|
+
'Plugin-based handlers',
|
|
66
|
+
'Error handling',
|
|
67
|
+
'JSON API',
|
|
68
|
+
'Action execution'
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
];
|
|
72
|
+
// Main menu system
|
|
73
|
+
const showMainMenu = () => {
|
|
74
|
+
console.log("\nšÆ Declarative Plugin System Examples");
|
|
75
|
+
console.log("=====================================\n");
|
|
76
|
+
exampleCatalog.forEach((example, index) => {
|
|
77
|
+
console.log(`${index + 1}. ${example.name}`);
|
|
78
|
+
console.log(` ${example.description}`);
|
|
79
|
+
console.log(` File: ${example.file}`);
|
|
80
|
+
console.log(` Features: ${example.features.join(', ')}`);
|
|
81
|
+
console.log();
|
|
82
|
+
});
|
|
83
|
+
console.log("0. Run all examples");
|
|
84
|
+
console.log("q. Quit");
|
|
85
|
+
console.log();
|
|
86
|
+
};
|
|
87
|
+
// Run specific example
|
|
88
|
+
const runExample = async (index) => {
|
|
89
|
+
const example = exampleCatalog[index];
|
|
90
|
+
if (!example) {
|
|
91
|
+
console.log("ā Invalid example number");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// Wrap server demo to return void
|
|
95
|
+
const wrappedDemo = async () => {
|
|
96
|
+
if (example.id === 'server') {
|
|
97
|
+
await example.demo();
|
|
98
|
+
console.log("\nš Server is running. Press Ctrl+C to stop.");
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
await example.demo();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
await runDemo(`${example.name} Example`, wrappedDemo);
|
|
105
|
+
};
|
|
106
|
+
// Run all examples (excluding server which blocks)
|
|
107
|
+
const runAllExamples = async () => {
|
|
108
|
+
console.log("\nš Running all declarative examples...\n");
|
|
109
|
+
for (const example of exampleCatalog) {
|
|
110
|
+
if (example.id === 'server') {
|
|
111
|
+
console.log(`āļø Skipping ${example.name} (server blocks execution)`);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
// Wrap demo to ensure it returns void
|
|
115
|
+
const wrappedDemo = async () => {
|
|
116
|
+
await example.demo();
|
|
117
|
+
};
|
|
118
|
+
await runDemo(example.name, wrappedDemo);
|
|
119
|
+
}
|
|
120
|
+
console.log("\nā
All examples completed!");
|
|
121
|
+
};
|
|
122
|
+
// Interactive menu
|
|
123
|
+
const interactiveMenu = async () => {
|
|
124
|
+
const readline = await import('readline');
|
|
125
|
+
const rl = readline.createInterface({
|
|
126
|
+
input: process.stdin,
|
|
127
|
+
output: process.stdout
|
|
128
|
+
});
|
|
129
|
+
const askQuestion = (question) => {
|
|
130
|
+
return new Promise(resolve => {
|
|
131
|
+
rl.question(question, resolve);
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
while (true) {
|
|
135
|
+
showMainMenu();
|
|
136
|
+
const answer = await askQuestion("Select an example (number) or 'q' to quit: ");
|
|
137
|
+
if (answer.toLowerCase() === 'q') {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
if (answer === '0') {
|
|
141
|
+
await runAllExamples();
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const index = parseInt(answer) - 1;
|
|
145
|
+
if (!isNaN(index)) {
|
|
146
|
+
await runExample(index);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
console.log("ā Invalid input");
|
|
150
|
+
}
|
|
151
|
+
const continueAnswer = await askQuestion("\nPress Enter to continue or 'q' to quit: ");
|
|
152
|
+
if (continueAnswer.toLowerCase() === 'q') {
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
rl.close();
|
|
157
|
+
};
|
|
158
|
+
// Quick run function
|
|
159
|
+
const quickRun = async (exampleId) => {
|
|
160
|
+
const example = exampleCatalog.find(e => e.id === exampleId);
|
|
161
|
+
if (!example) {
|
|
162
|
+
console.log(`ā Example '${exampleId}' not found`);
|
|
163
|
+
console.log("Available examples:", exampleCatalog.map(e => e.id).join(', '));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
// Wrap server demo to return void
|
|
167
|
+
const wrappedDemo = async () => {
|
|
168
|
+
if (example.id === 'server') {
|
|
169
|
+
await example.demo();
|
|
170
|
+
console.log("\nš Server is running. Press Ctrl+C to stop.");
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
await example.demo();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
await runDemo(example.name, wrappedDemo);
|
|
177
|
+
};
|
|
178
|
+
// Export everything
|
|
179
|
+
export { exampleCatalog, showMainMenu, runExample, runAllExamples, interactiveMenu, quickRun,
|
|
180
|
+
// Individual demos
|
|
181
|
+
demonstrateDeclarativeActionRegistry, demonstrateDeclarativeStorage, demonstrateDeclarativeLogging, demonstrateDeclarativeServer };
|
|
182
|
+
// Run if called directly
|
|
183
|
+
if (import.meta.main) {
|
|
184
|
+
const args = process.argv.slice(2);
|
|
185
|
+
if (args.length === 0) {
|
|
186
|
+
// Interactive mode
|
|
187
|
+
interactiveMenu().catch(console.error);
|
|
188
|
+
}
|
|
189
|
+
else if (args[0] === '--all') {
|
|
190
|
+
// Run all examples
|
|
191
|
+
runAllExamples().catch(console.error);
|
|
192
|
+
}
|
|
193
|
+
else if (args[0] === '--example' && args[1]) {
|
|
194
|
+
// Run specific example
|
|
195
|
+
quickRun(args[1]).catch(console.error);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
console.log("\nšÆ Declarative Plugin System Examples");
|
|
199
|
+
console.log("Usage:");
|
|
200
|
+
console.log(" bun run examples/index-declarative.ts # Interactive menu");
|
|
201
|
+
console.log(" bun run examples/index-declarative.ts --all # Run all examples");
|
|
202
|
+
console.log(" bun run examples/index-declarative.ts --example <id> # Run specific example");
|
|
203
|
+
console.log("\nAvailable examples:", exampleCatalog.map(e => e.id).join(', '));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=index-declarative.js.map
|