how it works a.k.a. writing your Adapters.
Adapter is an object with 2 properties:
- Database (class extending BaseDatabase)
- Resource (class extending BaseResource)
When you pass SomeDataModel to databases[] or resources[], AdminBro will automatically run all the registered adapters and check
their corresponding BaseDatabase.isAdapterFor or BaseResource.isAdapterFor methods. If Adapter returns true
AdminBro feeds it (in the constructor) with SomeDataModel.
To write your own adapter, you have to create these 2 classes and implement all methods like find, create, etc.
HINT: You can also write only a Resource class (extending BaseResource) and pass its instance to AdminBroOptions#resources like this:
class MyApiAdapter extends BaseResource {
//... all abstract methods from BaseResource
}
const adminBro = new AdminBro({
resources: [User, {
resource: new MyApiAdapter(),
options: {
//...
},
}],
})
AdminBro will see, that what you passed is already a BaseDatabase instance, so it wont need to be wrapped by an Adapter.