admin-bro
Version:
Admin panel for apps written in node.js
218 lines (217 loc) • 7.13 kB
TypeScript
import AdminBroOptions, { AdminBroOptionsWithDefault } from './admin-bro-options.interface';
import BaseResource from './backend/adapters/base-resource';
import BaseDatabase from './backend/adapters/base-database';
import BaseRecord from './backend/adapters/base-record';
import BaseProperty from './backend/adapters/base-property';
import Filter from './backend/utils/filter';
import ValidationError from './backend/utils/validation-error';
import { RouterType } from './backend/router';
import Action from './backend/actions/action.interface';
export declare const VERSION: any;
declare type ActionsMap = {
[key: string]: Action;
};
declare type UserComponentsMap = {
[key: string]: string;
};
export declare type Adapter = {
Database: typeof BaseDatabase;
Resource: typeof BaseResource;
};
/**
* Main class for AdminBro extension. It takes {@link AdminBroOptions} as a
* parameter and creates an admin instance.
*
* Its main responsibility is to fetch all the resources and/or databases given by a
* user. Its instance is a currier - injected in all other classes.
*
* @example
* const { AdminBro } = require('admin-bro')
* const admin = new AdminBro(AdminBroOptions)
*
*/
declare class AdminBro {
resources: Array<BaseResource>;
options: AdminBroOptionsWithDefault;
static registeredAdapters: Array<Adapter>;
static Router: RouterType;
static BaseDatabase: typeof BaseDatabase;
static BaseRecord: typeof BaseRecord;
static BaseResource: typeof BaseResource;
static BaseProperty: typeof BaseProperty;
static Filter: typeof Filter;
static ValidationError: typeof ValidationError;
static ACTIONS: ActionsMap;
static VERSION: string;
static UserComponents: UserComponentsMap;
/**
* @param {AdminBroOptions} options options passed to adminBro
*/
constructor(options?: AdminBroOptions);
/**
* Registers various database adapters written for AdminBro.
*
* @example
* const AdminBro = require('admin-bro')
* const MongooseAdapter = require('admin-bro-mongoose')
* AdminBro.registerAdapter(MongooseAdapter)
*
* @param {Object} options
* @param {typeof BaseDatabase} options.Database subclass of BaseDatabase
* @param {typeof BaseResource} options.Resource subclass of BaseResource
*/
static registerAdapter({ Database, Resource }: {
Database: typeof BaseDatabase;
Resource: typeof BaseResource;
}): void;
/**
* Initializes AdminBro instance in production. This function should be called by
* all external plugins.
*/
initialize(): Promise<void>;
/**
* Renders an entire login page with email and password fields
* using {@link Renderer}.
*
* Used by external plugins
*
* @param {Object} options
* @param {String} options.action login form action url - it could be
* '/admin/login'
* @param {String} [options.errorMessage] optional error message. When set,
* renderer will print this message in
* the form
* @return {Promise<string>} HTML of the rendered page
*/
static renderLogin({ action, errorMessage }: {
action: any;
errorMessage: any;
}): Promise<string>;
/**
* Returns resource base on its ID
*
* @example
* const User = admin.findResource('users')
* await User.findOne(userId)
*
* @param {String} resourceId ID of a resource defined under {@link BaseResource#id}
* @return {BaseResource} found resource
* @throws {Error} when resource with given id cannot be found
*/
findResource(resourceId: any): BaseResource;
/**
* Requires given .jsx/.tsx file, that it can be bundled to the frontend.
* It will be available under AdminBro.UserComponents[componentId].
*
* @param {String} src path to a file containing react component.
*
* @return {String} componentId - uniq id of a component
*
* @example
* const adminBroOptions = {
* dashboard: {
* component: AdminBro.bundle('./path/to/component'),
* }
* }
*/
static bundle(src: string): string;
}
export declare const registerAdapter: typeof AdminBro.registerAdapter;
export declare const bundle: typeof AdminBro.bundle;
export default AdminBro;
/**
* @description
* Contains set of routes availables within the application.
* It is used by external plugins.
*
* @example
* const { Router } = require('admin-bro')
* Router.routes.forEach(route => {
* // map your framework routes to admin-bro routes
* // see how `admin-bro-expressjs` plugin does it.
* })
*
* @memberof AdminBro
* @static
* @name Router
* @alias AdminBro.Router
* @type RouterType
*/
/**
* abstract class for all databases. External adapters have to implement that.
* @memberof AdminBro
* @static
* @abstract
* @name AdminBro.BaseDatabase
* @type {typeof BaseDatabase}
*/
/**
* abstract class for all records. External adapters have to implement that or at least
* their BaseResource implementation should return records of this type.
* @memberof AdminBro
* @static
* @abstract
* @name AdminBro.BaseRecord
* @type {typeof BaseRecord}
*/
/**
* abstract class for all resources. External adapters have to implement that.
* @memberof AdminBro
* @static
* @abstract
* @name AdminBro.BaseResource
* @type {typeof BaseResource}
*/
/**
* abstract class for all properties. External adapters have to implement that or at least
* their BaseResource implementation should return records of this type.
* @memberof AdminBro
* @static
* @abstract
* @name AdminBro.BaseProperty
* @type {typeof BaseProperty}
*/
/**
* Filter object passed to find method of BaseResource. External adapters have to use it
* @memberof AdminBro
* @static
* @abstract
* @name AdminBro.Filter
* @type {typeof Filter}
*/
/**
* Validation error which is thrown when record fails validation. External adapters have
* to use it.
* @memberof AdminBro
* @static
* @name AdminBro.ValidationError
* @type {typeof ValidationError}
*/
/**
* List of all default actions. If you want to change behaviour for all actions lika list,
* edit, show and delete you can do this here.
*
* @example <caption>Modifying accessibility rules for all show actions</caption>
* const { ACTIONS } = require('admin-bro')
* ACTIONS.show.isAccessible = () => {...}
*
*
* @memberof AdminBro
* @static
* @name AdminBro.ACTIONS
* @type {ActionsMap}
*/
/**
* AdminBro version
* @memberof AdminBro
* @static
* @name AdminBro.VERSION
* @type {string}
*/
/**
* List of all bundled components
* @memberof AdminBro
* @static
* @name AdminBro.UserComponents
* @type {UserComponentsMap}
*/