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