mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
refactor: improve type handling and config structure
Updated various type definitions to improve flexibility and maintain consistency, including `MaybePromise` and `PartialRec`. Adjusted `App` class and related configurations to properly utilize these changes.
This commit is contained in:
@@ -16,7 +16,7 @@ import { DbModuleManager } from "modules/db/DbModuleManager";
|
||||
import * as SystemPermissions from "modules/permissions";
|
||||
import { AdminController, type AdminControllerOptions } from "modules/server/AdminController";
|
||||
import { SystemController } from "modules/server/SystemController";
|
||||
import type { MaybePromise } from "core/types";
|
||||
import type { MaybePromise, PartialRec } from "core/types";
|
||||
import type { ServerEnv } from "modules/Controller";
|
||||
import type { IEmailDriver, ICacheDriver } from "core/drivers";
|
||||
|
||||
@@ -99,14 +99,18 @@ export type AppOptions = {
|
||||
};
|
||||
export type CreateAppConfig = {
|
||||
connection?: Connection | { url: string };
|
||||
config?: InitialModuleConfigs;
|
||||
config?: PartialRec<ModuleConfigs>;
|
||||
options?: AppOptions;
|
||||
};
|
||||
|
||||
export type AppConfig = { version: number } & ModuleConfigs;
|
||||
export type LocalApiOptions = Request | ApiOptions;
|
||||
|
||||
export class App<C extends Connection = Connection, Options extends AppOptions = AppOptions> {
|
||||
export class App<
|
||||
C extends Connection = Connection,
|
||||
Config extends PartialRec<ModuleConfigs> = PartialRec<ModuleConfigs>,
|
||||
Options extends AppOptions = AppOptions,
|
||||
> {
|
||||
static readonly Events = AppEvents;
|
||||
|
||||
modules: ModuleManager;
|
||||
@@ -121,7 +125,7 @@ export class App<C extends Connection = Connection, Options extends AppOptions =
|
||||
|
||||
constructor(
|
||||
public connection: C,
|
||||
_config?: InitialModuleConfigs,
|
||||
_config?: Config,
|
||||
public options?: Options,
|
||||
) {
|
||||
this.drivers = options?.drivers ?? {};
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Config } from "@libsql/client/node";
|
||||
import { StorageLocalAdapter } from "adapter/node/storage";
|
||||
import type { CliBkndConfig, CliCommand } from "cli/types";
|
||||
import { Option } from "commander";
|
||||
import { config, type App, type CreateAppConfig } from "bknd";
|
||||
import { config, type App, type CreateAppConfig, type MaybePromise } from "bknd";
|
||||
import dotenv from "dotenv";
|
||||
import { registries } from "modules/registries";
|
||||
import c from "picocolors";
|
||||
@@ -60,7 +60,7 @@ type MakeAppConfig = {
|
||||
connection?: CreateAppConfig["connection"];
|
||||
server?: { platform?: Platform };
|
||||
setAdminHtml?: boolean;
|
||||
onBuilt?: (app: App) => Promise<void>;
|
||||
onBuilt?: (app: App) => MaybePromise<void>;
|
||||
};
|
||||
|
||||
async function makeApp(config: MakeAppConfig) {
|
||||
|
||||
@@ -72,12 +72,12 @@ export class Result<T = unknown> {
|
||||
return this.first().parameters;
|
||||
}
|
||||
|
||||
get data() {
|
||||
get data(): T {
|
||||
if (this.options.single) {
|
||||
return this.first().data?.[0];
|
||||
}
|
||||
|
||||
return this.first().data ?? [];
|
||||
return this.first().data ?? ([] as T);
|
||||
}
|
||||
|
||||
async execute(qb: Compilable | Compilable[]) {
|
||||
|
||||
@@ -4,5 +4,6 @@ export * from "./mutation/Mutator";
|
||||
export * from "./query/Repository";
|
||||
export * from "./query/WhereBuilder";
|
||||
export * from "./query/WithBuilder";
|
||||
export * from "./Result";
|
||||
export * from "./query/RepositoryResult";
|
||||
export * from "./mutation/MutatorResult";
|
||||
|
||||
@@ -29,6 +29,7 @@ export {
|
||||
type InitialModuleConfigs,
|
||||
ModuleManagerEvents,
|
||||
} from "./modules/ModuleManager";
|
||||
export type * from "modules/ModuleApi";
|
||||
|
||||
export type { ServerEnv } from "modules/Controller";
|
||||
export type { BkndConfig } from "bknd/adapter";
|
||||
@@ -128,6 +129,7 @@ export type { EntityRelation } from "data/relations";
|
||||
export type * from "data/entities/Entity";
|
||||
export type { EntityManager } from "data/entities/EntityManager";
|
||||
export type { SchemaManager } from "data/schema/SchemaManager";
|
||||
export type * from "data/entities";
|
||||
export {
|
||||
BaseIntrospector,
|
||||
Connection,
|
||||
|
||||
Reference in New Issue
Block a user