Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: add hooks support for wiki caching customization #10

Open
raje-sh opened this issue Aug 31, 2024 · 11 comments
Open

[Feature]: add hooks support for wiki caching customization #10

raje-sh opened this issue Aug 31, 2024 · 11 comments
Assignees

Comments

@raje-sh
Copy link
Owner

raje-sh commented Aug 31, 2024

Feature description

@raje-sh raje-sh self-assigned this Aug 31, 2024
@rajesh-sundaram-hcl
Copy link
Contributor

NPM Dependencies: use dynamic import inside callback-function definition.
accept npm-dependenices in yaml-config, dynamically install it via node child_process in either app-boot and docker build stage.

module.exports = async (data) => {
    const axios = require('axios'); // Example dependency

    console.log('Custom Callback: Data received:', data);

    // Use axios to send the data somewhere
    await axios.post('https://example.com/api', data);
};
const fs = require('fs');
const path = require('path');

class HookManager {
    constructor() {
        this.hooks = {};
    }

    registerHook(name, callback) {
        if (!this.hooks[name]) {
            this.hooks[name] = [];
        }
        this.hooks[name].push(callback);
    }

    async executeHooks(name, ...args) {
        if (this.hooks[name]) {
            for (const callback of this.hooks[name]) {
                await callback(...args);
            }
        }
    }

    async loadAndRegisterHooks(hookConfigPath) {
        const config = require(hookConfigPath);
        for (const hookName in config.hooks) {
            const hookFiles = config.hooks[hookName];
            for (const hookFile of hookFiles) {
                const hookPath = path.resolve(hookFile);

                // Dynamically load the callback
                const callback = require(hookPath);

                // Register the callback
                this.registerHook(hookName, callback);
            }
        }
    }
}

module.exports = HookManager;
const HookManager = require('./HookManager');
const hookManager = new HookManager();

// Load hooks from a configuration file (JSON or YAML)
(async () => {
    await hookManager.loadAndRegisterHooks('./hooks.yaml');

    // Trigger the hook to see it in action
    hookManager.executeHooks('onDataReceived', { id: 1, name: 'Sample Data' });
})();

@raje-sh
Copy link
Owner Author

raje-sh commented Aug 31, 2024

nodejs/node#37440

build package like webpack and conf

@raje-sh
Copy link
Owner Author

raje-sh commented Sep 1, 2024

Implement a middleware system where users can add functions to be executed at specific stages.
Each middleware function receives the context and can modify it before passing it to the next function.

@raje-sh
Copy link
Owner Author

raje-sh commented Sep 1, 2024

@raje-sh
Copy link
Owner Author

raje-sh commented Sep 1, 2024

@raje-sh
Copy link
Owner Author

raje-sh commented Sep 1, 2024

@raje-sh
Copy link
Owner Author

raje-sh commented Sep 1, 2024

https://github.com/adaltas/node-plug-and-play/tree/master

@raje-sh
Copy link
Owner Author

raje-sh commented Sep 1, 2024

@raje-sh
Copy link
Owner Author

raje-sh commented Sep 1, 2024

@raje-sh
Copy link
Owner Author

raje-sh commented Sep 1, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants