mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
Merge pull request #85 from bknd-io/refactor/app-options-manager
refactor app constructor params to move manager into app options
This commit is contained in:
@@ -26,6 +26,10 @@ export class AppFirstBoot extends AppEvent {
|
|||||||
}
|
}
|
||||||
export const AppEvents = { AppConfigUpdatedEvent, AppBuiltEvent, AppFirstBoot } as const;
|
export const AppEvents = { AppConfigUpdatedEvent, AppBuiltEvent, AppFirstBoot } as const;
|
||||||
|
|
||||||
|
export type AppOptions = {
|
||||||
|
plugins?: AppPlugin[];
|
||||||
|
manager?: Omit<ModuleManagerOptions, "initial" | "onUpdated">;
|
||||||
|
};
|
||||||
export type CreateAppConfig = {
|
export type CreateAppConfig = {
|
||||||
connection?:
|
connection?:
|
||||||
| Connection
|
| Connection
|
||||||
@@ -36,8 +40,7 @@ export type CreateAppConfig = {
|
|||||||
}
|
}
|
||||||
| LibSqlCredentials;
|
| LibSqlCredentials;
|
||||||
initialConfig?: InitialModuleConfigs;
|
initialConfig?: InitialModuleConfigs;
|
||||||
plugins?: AppPlugin[];
|
options?: AppOptions;
|
||||||
options?: Omit<ModuleManagerOptions, "initial" | "onUpdated">;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AppConfig = InitialModuleConfigs;
|
export type AppConfig = InitialModuleConfigs;
|
||||||
@@ -47,15 +50,16 @@ export class App {
|
|||||||
static readonly Events = AppEvents;
|
static readonly Events = AppEvents;
|
||||||
adminController?: AdminController;
|
adminController?: AdminController;
|
||||||
private trigger_first_boot = false;
|
private trigger_first_boot = false;
|
||||||
|
private plugins: AppPlugin[];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private connection: Connection,
|
private connection: Connection,
|
||||||
_initialConfig?: InitialModuleConfigs,
|
_initialConfig?: InitialModuleConfigs,
|
||||||
private plugins: AppPlugin[] = [],
|
private options?: AppOptions
|
||||||
moduleManagerOptions?: ModuleManagerOptions
|
|
||||||
) {
|
) {
|
||||||
|
this.plugins = options?.plugins ?? [];
|
||||||
this.modules = new ModuleManager(connection, {
|
this.modules = new ModuleManager(connection, {
|
||||||
...moduleManagerOptions,
|
...(options?.manager ?? {}),
|
||||||
initial: _initialConfig,
|
initial: _initialConfig,
|
||||||
onUpdated: async (key, config) => {
|
onUpdated: async (key, config) => {
|
||||||
// if the EventManager was disabled, we assume we shouldn't
|
// if the EventManager was disabled, we assume we shouldn't
|
||||||
@@ -199,5 +203,5 @@ export function createApp(config: CreateAppConfig = {}) {
|
|||||||
throw new Error("Invalid connection");
|
throw new Error("Invalid connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new App(connection, config.initialConfig, config.plugins, config.options);
|
return new App(connection, config.initialConfig, config.options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ export function serve({
|
|||||||
distPath,
|
distPath,
|
||||||
connection,
|
connection,
|
||||||
initialConfig,
|
initialConfig,
|
||||||
plugins,
|
|
||||||
options,
|
options,
|
||||||
port = config.server.default_port,
|
port = config.server.default_port,
|
||||||
onBuilt,
|
onBuilt,
|
||||||
@@ -44,7 +43,6 @@ export function serve({
|
|||||||
const app = await createApp({
|
const app = await createApp({
|
||||||
connection,
|
connection,
|
||||||
initialConfig,
|
initialConfig,
|
||||||
plugins,
|
|
||||||
options,
|
options,
|
||||||
onBuilt,
|
onBuilt,
|
||||||
buildConfig,
|
buildConfig,
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ The easiest to get started is using SQLite in-memory. When serving the API in th
|
|||||||
the function accepts an object with connection details. To use an in-memory database, you can either omit the object completely or explicitly use it as follows:
|
the function accepts an object with connection details. To use an in-memory database, you can either omit the object completely or explicitly use it as follows:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "libsql",
|
|
||||||
"config": {
|
|
||||||
"url": ":memory:"
|
"url": ":memory:"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -29,10 +26,7 @@ Just like the in-memory option, using a file is just as easy:
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "libsql",
|
|
||||||
"config": {
|
|
||||||
"url": "file:<path/to/your/database.db>"
|
"url": "file:<path/to/your/database.db>"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Please note that using SQLite as a file is only supported in server environments.
|
Please note that using SQLite as a file is only supported in server environments.
|
||||||
@@ -47,10 +41,7 @@ turso dev
|
|||||||
The command will yield a URL. Use it in the connection object:
|
The command will yield a URL. Use it in the connection object:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "libsql",
|
|
||||||
"config": {
|
|
||||||
"url": "http://localhost:8080"
|
"url": "http://localhost:8080"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -59,11 +50,8 @@ If you want to use LibSQL on Turso, [sign up for a free account](https://turso.t
|
|||||||
connection object to your new database:
|
connection object to your new database:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"type": "libsql",
|
|
||||||
"config": {
|
|
||||||
"url": "libsql://your-database-url.turso.io",
|
"url": "libsql://your-database-url.turso.io",
|
||||||
"authToken": "your-auth-token"
|
"authToken": "your-auth-token"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -44,18 +44,21 @@ import type { Connection } from "bknd/data";
|
|||||||
import type { Config } from "@libsql/client";
|
import type { Config } from "@libsql/client";
|
||||||
|
|
||||||
type AppPlugin = (app: App) => Promise<void> | void;
|
type AppPlugin = (app: App) => Promise<void> | void;
|
||||||
|
type ManagerOptions = {
|
||||||
|
basePath?: string;
|
||||||
|
trustFetched?: boolean;
|
||||||
|
onFirstBoot?: () => Promise<void>;
|
||||||
|
seed?: (ctx: ModuleBuildContext) => Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
type CreateAppConfig = {
|
type CreateAppConfig = {
|
||||||
connection?:
|
connection?:
|
||||||
| Connection
|
| Connection
|
||||||
| Config;
|
| Config;
|
||||||
initialConfig?: InitialModuleConfigs;
|
initialConfig?: InitialModuleConfigs;
|
||||||
plugins?: AppPlugin[];
|
|
||||||
options?: {
|
options?: {
|
||||||
basePath?: string;
|
plugins?: AppPlugin[];
|
||||||
trustFetched?: boolean;
|
manager?: ManagerOptions
|
||||||
onFirstBoot?: () => Promise<void>;
|
|
||||||
seed?: (ctx: ModuleBuildContext) => Promise<void>;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user