@h-ai/reldb 1.0.0-beta.18 → 1.0.0-beta.19

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.
package/dist/index.d.ts CHANGED
@@ -192,6 +192,38 @@ declare function parseJsonPath(path: string): string[];
192
192
  */
193
193
  declare function createJsonOps(dbType: 'sqlite' | 'postgresql' | 'mysql'): ReldbJsonOps;
194
194
 
195
+ /** 模块维护自己的迁移;这里只提供跨数据库列检查、版本账本和执行边界。 */
196
+
197
+ /**
198
+ * 一个可重入的模块升级步骤;只接收代码中固定的 SQL 与表名。
199
+ * @example
200
+ * ```ts
201
+ * import type { SchemaMigration } from '@h-ai/reldb'
202
+ * const steps: SchemaMigration[] = []
203
+ * ```
204
+ */
205
+ interface SchemaMigration {
206
+ version: number;
207
+ name: string;
208
+ needed: (sql: DmlOperations) => Promise<HaiResult<boolean>>;
209
+ apply: (sql: DmlOperations) => Promise<HaiResult<unknown>>;
210
+ }
211
+ /**
212
+ * 只读预检结果;生产升级需先停旧写入并备份数据库与共享缓存。
213
+ * @example
214
+ * ```ts
215
+ * import type { SchemaMigrationPlan } from '@h-ai/reldb'
216
+ * function changes(plan: SchemaMigrationPlan) { return plan.changes }
217
+ * ```
218
+ */
219
+ interface SchemaMigrationPlan {
220
+ module: string;
221
+ currentVersion: number;
222
+ targetVersion: number;
223
+ changes: string[];
224
+ requiresExclusiveAccess: boolean;
225
+ }
226
+
195
227
  /**
196
228
  * HaiReldbError 的数据约束与操作契约。
197
229
  * @example
@@ -957,6 +989,28 @@ interface ReldbFunctions {
957
989
  readonly crud: CrudManager;
958
990
  /** 事务管理器 */
959
991
  readonly tx: TxManager;
992
+ /**
993
+ * 预检或执行模块维护的版本迁移;绑定当前数据库,不接受其它模块实例。
994
+ * @example
995
+ * ```ts
996
+ * import { reldb } from '@h-ai/reldb'
997
+ * const plan = await reldb.migrateSchema('example', [], { dryRun: true })
998
+ * if (!plan.success) throw new Error(plan.error.message)
999
+ * ```
1000
+ */
1001
+ migrateSchema: (module: string, steps: readonly SchemaMigration[], options?: {
1002
+ dryRun?: boolean;
1003
+ }) => Promise<HaiResult<SchemaMigrationPlan>>;
1004
+ /**
1005
+ * 只读查询当前数据库真实列名;sql 可指定当前事务,不创建表。
1006
+ * @example
1007
+ * ```ts
1008
+ * import { reldb } from '@h-ai/reldb'
1009
+ * const columns = await reldb.schemaColumns('hai_iam_users')
1010
+ * if (!columns.success) throw new Error(columns.error.message)
1011
+ * ```
1012
+ */
1013
+ schemaColumns: (table: string, sql?: DmlOperations) => Promise<HaiResult<string[]>>;
960
1014
  /** 当前数据库脱敏配置快照(未初始化时为 null) */
961
1015
  readonly config: ReldbConfig | null;
962
1016
  /** 是否已初始化 */
@@ -1458,59 +1512,6 @@ declare abstract class BaseReldbCrudRepository<TItem> implements ReldbCrudReposi
1458
1512
  */
1459
1513
  declare const reldb: ReldbFunctions;
1460
1514
 
1461
- /** 模块维护自己的迁移;这里只提供跨数据库列检查、版本账本和执行边界。 */
1462
-
1463
- /**
1464
- * 一个可重入的模块升级步骤;只接收代码中固定的 SQL 与表名。
1465
- * @example
1466
- * ```ts
1467
- * import type { SchemaMigration } from '@h-ai/reldb'
1468
- * const steps: SchemaMigration[] = []
1469
- * ```
1470
- */
1471
- interface SchemaMigration {
1472
- version: number;
1473
- name: string;
1474
- needed: (sql: DmlOperations) => Promise<HaiResult<boolean>>;
1475
- apply: (sql: DmlOperations) => Promise<HaiResult<unknown>>;
1476
- }
1477
- /**
1478
- * 只读预检结果;生产升级需先停旧写入并备份数据库与共享缓存。
1479
- * @example
1480
- * ```ts
1481
- * import type { SchemaMigrationPlan } from '@h-ai/reldb'
1482
- * function changes(plan: SchemaMigrationPlan) { return plan.changes }
1483
- * ```
1484
- */
1485
- interface SchemaMigrationPlan {
1486
- module: string;
1487
- currentVersion: number;
1488
- targetVersion: number;
1489
- changes: string[];
1490
- requiresExclusiveAccess: boolean;
1491
- }
1492
- /**
1493
- * 查询真实列名;不创建表,不把查询错误当成新安装。
1494
- * @example
1495
- * ```ts
1496
- * import { reldb, schemaColumns } from '@h-ai/reldb'
1497
- * const columns = await schemaColumns(reldb, 'hai_iam_users')
1498
- * ```
1499
- */
1500
- declare function schemaColumns(db: ReldbFunctions, table: string, sql?: DmlOperations): Promise<HaiResult<string[]>>;
1501
- /**
1502
- * 预检或执行模块维护的版本迁移。SQLite/PostgreSQL 原子提交;MySQL DDL 隐式提交,步骤须可重入。
1503
- * 失败不记录目标版本;重启重新检查真实结构。新版本账本拒绝旧代码向下迁移。
1504
- * @example
1505
- * ```ts
1506
- * import { reldb, migrateSchema } from '@h-ai/reldb'
1507
- * const plan = await migrateSchema(reldb, 'example', [], { dryRun: true })
1508
- * ```
1509
- */
1510
- declare function migrateSchema(db: ReldbFunctions, module: string, steps: readonly SchemaMigration[], options?: {
1511
- dryRun?: boolean;
1512
- }): Promise<HaiResult<SchemaMigrationPlan>>;
1513
-
1514
1515
  /**
1515
1516
  * @h-ai/reldb — 安全工具
1516
1517
  *
@@ -1588,4 +1589,5 @@ declare function quoteIdentifier(name: string): string;
1588
1589
  */
1589
1590
  declare function escapeSqlString(value: string): string;
1590
1591
 
1591
- export { BaseReldbCrudRepository, type BaseReldbCrudRepositoryConfig, type ColumnType, type CrudConfig, type CrudManager, type CrudPageOptions, type CrudQueryOptions, DbType, type DdlOperations, type DmlOperations, type DmlWithTxOperations, type ExecuteResult, HaiReldbError, type JsonSqlExpr, type NormalizedPagination, type PaginationOverrides, type PaginationQueryOptions, type QueryRow, type ReldbColumnDef, ReldbConfig, ReldbConfigInput, type ReldbCrudCountOptions, type ReldbCrudFieldDefinition, type ReldbCrudRepository, type ReldbFunctions, type ReldbIndexDef, type ReldbJsonOps, type ReldbTableDef, type SchemaMigration, type SchemaMigrationPlan, type TxManager, type TxWrapCallback, createJsonOps, escapeSqlString, migrateSchema, parseJsonPath, quoteIdentifier, reldb, schemaColumns, validateIdentifier, validateIdentifiers };
1592
+ export { BaseReldbCrudRepository, DbType, HaiReldbError, ReldbConfig, ReldbConfigInput, createJsonOps, escapeSqlString, parseJsonPath, quoteIdentifier, reldb, validateIdentifier, validateIdentifiers };
1593
+ export type { BaseReldbCrudRepositoryConfig, ColumnType, CrudConfig, CrudManager, CrudPageOptions, CrudQueryOptions, DdlOperations, DmlOperations, DmlWithTxOperations, ExecuteResult, JsonSqlExpr, NormalizedPagination, PaginationOverrides, PaginationQueryOptions, QueryRow, ReldbColumnDef, ReldbCrudCountOptions, ReldbCrudFieldDefinition, ReldbCrudRepository, ReldbFunctions, ReldbIndexDef, ReldbJsonOps, ReldbTableDef, SchemaMigration, SchemaMigrationPlan, TxManager, TxWrapCallback };