befly 3.14.2 → 3.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@
4
4
  import type { CacheHelper } from "./cache";
5
5
  import type { CipherStatic } from "./cipher";
6
6
  import type { KeyValue } from "./common";
7
+ import type { RequestContext } from "./context";
7
8
  import type { DbHelper } from "./database";
8
9
  import type { Jwt } from "./jwt";
9
10
  import type { Logger, LoggerConfig } from "./logger";
@@ -190,6 +191,11 @@ export interface BeflyContext extends KeyValue {
190
191
  msg: string;
191
192
  data: any;
192
193
  };
194
+ Raw: (ctx: RequestContext, data: Record<string, any> | string, options?: {
195
+ status?: number;
196
+ contentType?: string;
197
+ headers?: Record<string, string>;
198
+ }) => Response;
193
199
  };
194
200
  /** 加密解密 */
195
201
  cipher: CipherStatic;
@@ -2,6 +2,19 @@
2
2
  * 数据库操作相关类型定义
3
3
  */
4
4
  import type { JoinOption, SqlValue, WhereConditions } from "./common";
5
+ /**
6
+ * 表名到行类型的映射(项目侧可通过 declaration merging 扩展)。
7
+ *
8
+ * 用法(项目侧):
9
+ * declare module "befly/types/database" {
10
+ * interface DbRowMap {
11
+ * user: { id: number; nickname?: string };
12
+ * }
13
+ * }
14
+ */
15
+ export interface DbRowMap {
16
+ }
17
+ export type DbTableName = keyof DbRowMap & string;
5
18
  /**
6
19
  * 数据库类型
7
20
  */
@@ -109,12 +122,34 @@ export type TransactionCallback<TResult = unknown, TDb = unknown> = (db: TDb) =>
109
122
  */
110
123
  export interface DbHelper {
111
124
  tableExists(tableName: string): Promise<DbResult<boolean>>;
125
+ getCount<TTable extends DbTableName>(options: Omit<QueryOptions, "fields" | "page" | "limit" | "orderBy" | "table"> & {
126
+ table: TTable;
127
+ }): Promise<DbResult<number>>;
112
128
  getCount(options: Omit<QueryOptions, "fields" | "page" | "limit" | "orderBy">): Promise<DbResult<number>>;
129
+ getOne<TTable extends DbTableName>(options: Omit<QueryOptions, "table"> & {
130
+ table: TTable;
131
+ }): Promise<DbResult<DbRowMap[TTable]>>;
113
132
  getOne<TItem = unknown>(options: QueryOptions): Promise<DbResult<TItem>>;
133
+ getDetail<TTable extends DbTableName>(options: Omit<QueryOptions, "table"> & {
134
+ table: TTable;
135
+ }): Promise<DbResult<DbRowMap[TTable]>>;
114
136
  getDetail<TItem = unknown>(options: QueryOptions): Promise<DbResult<TItem>>;
137
+ getList<TTable extends DbTableName>(options: Omit<QueryOptions, "table"> & {
138
+ table: TTable;
139
+ }): Promise<DbResult<DbPageResult<DbRowMap[TTable]>, ListSql>>;
115
140
  getList<TItem = unknown>(options: QueryOptions): Promise<DbResult<DbPageResult<TItem>, ListSql>>;
141
+ getAll<TTable extends DbTableName>(options: Omit<QueryOptions, "table" | "page" | "limit"> & {
142
+ table: TTable;
143
+ }): Promise<DbResult<DbListResult<DbRowMap[TTable]>, ListSql>>;
116
144
  getAll<TItem = unknown>(options: Omit<QueryOptions, "page" | "limit">): Promise<DbResult<DbListResult<TItem>, ListSql>>;
145
+ exists<TTable extends DbTableName>(options: Omit<QueryOptions, "fields" | "orderBy" | "page" | "limit" | "table"> & {
146
+ table: TTable;
147
+ }): Promise<DbResult<boolean>>;
117
148
  exists(options: Omit<QueryOptions, "fields" | "orderBy" | "page" | "limit">): Promise<DbResult<boolean>>;
149
+ getFieldValue<TTable extends DbTableName, TField extends keyof DbRowMap[TTable] & string>(options: Omit<QueryOptions, "fields" | "table"> & {
150
+ table: TTable;
151
+ field: TField;
152
+ }): Promise<DbResult<DbRowMap[TTable][TField] | null>>;
118
153
  getFieldValue<TValue = unknown>(options: Omit<QueryOptions, "fields"> & {
119
154
  field: string;
120
155
  }): Promise<DbResult<TValue | null>>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.14.2",
4
- "gitHead": "e30f1dd7cb51e6560832110c37708ef0a6853749",
3
+ "version": "3.14.3",
4
+ "gitHead": "5a041666725189792d66b994d4d35a28822637ad",
5
5
  "private": false,
6
6
  "description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
7
7
  "keywords": [