AbimongoBootstrap
@abimongo/core / AbimongoBootstrap
Class: AbimongoBootstrap
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:97
AbimongoBootstrap is the main entry point for initializing and managing the Abimongo application stack when you opt for the CLI. It handles MongoDB, Redis, and GraphQL setup, along with custom hooks for post-connection logic.
Examples
npx abimongo-core my-project
cd my-project
This will create a new Abimongo project in the 'my-project' directory. You can then customize the configuration file and start using Abimongo in your application.
Add flags as needed:
npx abimongo-core my-project --withRedis --withGraphQL --multiTenant
cd my-project
This will create a new Abimongo project with Redis caching, GraphQL support, and multi-tenancy enabled. enabling them in the configuration file.
You can also use AbimongoBootstrap programmatically in your application:
@example
import { AbimongoBootstrapFactory } from '@abimongo/core';
async function start() {
const abimongo = await AbimongoBootstrapFactory.create();
const db = abimongo.getMongoClient();
await db.connect();
const graphql = await abimongo.getGraphQL();
// You can now use the GraphQL instance to generate schema or start a server
// or perform other GraphQL related operations
graphql.generateSchema();
abimongo.getRedisClient();
}
start();
// With custom configuration file
import { AbimongoBootstrapFactory } from '@abimongo/core';
export async function start() {
const abimongo = await AbimongoBootstrapFactory.create('path/to/custom-abimongo.config.json');
const db = abimongo.getMongoClient();
await db.connect();
const graphql = await abimongo.getGraphQL();
// You can now use the GraphQL instance to generate schema or start a server
// or perform other GraphQL related operations
graphql.generateSchema();
abimongo.getRedisClient();
}
abimongo.registerMultiTenancy(app, {
'tenant1': 'mongodb://localhost:27017/tenant1db',
'tenant2': 'mongodb://localhost:27017/tenant2db',
}, {
headerKey: 'x-tenant-id',
initOptions: { /* custom options * / } // This where you can lazily initialize tenants if needed
});
};
*
Param
Optional path to a custom configuration file or a config object. If not provided, it defaults to 'abimongo.config.json'.
Constructors
Constructor
new AbimongoBootstrap():
AbimongoBootstrap
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:109
Returns
AbimongoBootstrap
Properties
logger
logger:
ILogger|AbimongoLogger
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:103
Methods
cache()
cache<
T>(key,fetcher,options):Promise<T>
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:281
Type Parameters
T
T
Parameters
key
string
fetcher
() => Promise<T>
options
namespace?
string
prefix?
string
tenantId?
string
ttlSeconds?
number
Returns
Promise<T>
getGCRunner()
getGCRunner():
AbimongoGC|undefined
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:333
Returns
AbimongoGC | undefined
getGraphQL()
getGraphQL():
AbimongoGraphQL|undefined
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:329
Returns
AbimongoGraphQL | undefined
getModel()
getModel():
AbimongoModel<Document> |undefined
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:322
Returns
AbimongoModel<Document> | undefined
getMongoClient()
getMongoClient():
AbimongoClient|undefined
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:314
Returns
AbimongoClient | undefined
getRedisClient()
getRedisClient():
Promise<any>
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:306
Returns the Redis client if Redis is enabled in the configuration.
Returns
Promise<any>
A promise that resolves to the Redis client.
getSchema()
getSchema():
AbimongoSchema<Document> |undefined
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:325
Returns
AbimongoSchema<Document> | undefined
initialize()
initialize(
configFilePathOrObject?):Promise<void>
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:127
Initializes the Abimongo application stack. This method sets up MongoDB, Redis, and GraphQL connections, and executes any registered onConnect hooks.
Parameters
configFilePathOrObject?
Optional path to a custom configuration file or a config object. If not provided, it defaults to 'abimongo.config.json'.
string | AbimongoConfig
Returns
Promise<void>
invalidateCache()
invalidateCache(
tenantId,namespace?):Promise<void>
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:295
Parameters
tenantId
string
namespace?
string
Returns
Promise<void>
onConnect()
onConnect(
hook):void
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:116
Register a hook to be called after the connection is established. This can be used for custom initialization logic that depends on the database being ready.
Parameters
hook
OnConnectHook
A function that will be called after the connection is established.
Returns
void
registerMultiTenancy()
registerMultiTenancy(
application,tenants,options):Promise<void>
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:257
Parameters
application
Application
tenants
Record<string, string>
options
headerKey?
string
initOptions?
Returns
Promise<void>
shutdown()
shutdown():
Promise<void>
Defined in: core/src/lib-core/bootstrap/AbimongoBootstrap.ts:337
Returns
Promise<void>