Skip to content

declare module for direct import of BaseAdapter class - #98

Closed
saeedtabrizi wants to merge 2 commits into
moleculerjs:masterfrom
saeedtabrizi:patch-1
Closed

declare module for direct import of BaseAdapter class#98
saeedtabrizi wants to merge 2 commits into
moleculerjs:masterfrom
saeedtabrizi:patch-1

Conversation

@saeedtabrizi

Copy link
Copy Markdown

In some cases may needed to write a custom Adapter .so you may need to import directly BaseAdapter class not only type of BaseAdapter . this declaration helps to import directly base class and use BaseAdapter typing declared in @moleculer/database module .

In some cases may needed to write a custom Adapter .so you may need to import directly `BaseAdapter` class not only type of `BaseAdapter `.  this declaration helps to import directly base class and use `BaseAdapter` typing declared in `@moleculer/database` module .
Add Adapters to access register method directly
@icebob-ai

Copy link
Copy Markdown
Contributor

Thanks for the PR! However, what you're trying to achieve is already possible without a deep import: the BaseAdapter class is exported (with typings) as Adapters.Base:

import { Adapters } from "@moleculer/database";

class MyAdapter extends Adapters.Base {
    // ...
}

or in CommonJS:

const { Adapters } = require("@moleculer/database");

class MyAdapter extends Adapters.Base {
    // ...
}

The typings declare it as export const Base: typeof BaseAdapter, so you get the class itself (not just the type) and you can extend it directly.

Regarding the proposed declarations themselves: src/adapters/base.js is a CommonJS module (module.exports = BaseAdapter), so the accurate typing would be export = rather than export default (the default import would break without esModuleInterop). The @moleculer/database/index declaration is also inaccurate, since index.js exports the whole module, not just Adapters.

So I'm closing this without merging — please use Adapters.Base instead. If you run into a case that it doesn't cover, feel free to open an issue.

@icebob-ai icebob-ai closed this Aug 21, 2026
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

Successfully merging this pull request may close these issues.

2 participants