@aiao/rxdb 0.0.1
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/README.md +1 -0
- package/RxDB.d.ts +51 -0
- package/RxDBError.d.ts +13 -0
- package/entity/@Entity.d.ts +29 -0
- package/entity/@TreeEntity.d.ts +50 -0
- package/entity/EntityBase.d.ts +49 -0
- package/entity/EntityManager.d.ts +140 -0
- package/entity/EntityStatus.d.ts +211 -0
- package/entity/TreeEntityBase.d.ts +7 -0
- package/entity/entity-metadata-options.interface.d.ts +434 -0
- package/entity/entity-metadata.interface.d.ts +67 -0
- package/entity/entity.interface.d.ts +110 -0
- package/entity/entity.utils.d.ts +59 -0
- package/entity/entity_proxy_helper.d.ts +48 -0
- package/entity/entity_relation_helper.d.ts +15 -0
- package/entity/generate_many_to_many_entity.d.ts +35 -0
- package/entity/transition-metadata.d.ts +17 -0
- package/index.d.ts +26 -0
- package/index.js +1783 -0
- package/package.json +19 -0
- package/repository/Repository.d.ts +108 -0
- package/repository/RepositoryBase.d.ts +32 -0
- package/repository/TreeRepository.d.ts +28 -0
- package/repository/query-options.interface.d.ts +53 -0
- package/repository/query.interface.d.ts +92 -0
- package/repository/query.utils.d.ts +19 -0
- package/repository/repository.interface.d.ts +84 -0
- package/repository/tree-query-options.interface.d.ts +9 -0
- package/repository/tree-repository.interface.d.ts +26 -0
- package/rxdb-adapter.d.ts +73 -0
- package/rxdb-events.d.ts +186 -0
- package/rxdb-plugin.d.ts +20 -0
- package/rxdb-utils.d.ts +20 -0
- package/rxdb.interface.d.ts +56 -0
- package/rxdb.private.d.ts +55 -0
- package/schema/SchemaManager.d.ts +57 -0
- package/system/change.d.ts +13 -0
- package/system/migration.d.ts +9 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# rxdb
|
package/RxDB.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { SetRequired } from 'type-fest';
|
|
3
|
+
import { EntityManager } from './entity/EntityManager';
|
|
4
|
+
import { AdapterFactory, RxDBAdapters } from './rxdb-adapter';
|
|
5
|
+
import { RxDBEvent, RxDBEventMap } from './rxdb-events';
|
|
6
|
+
import { Plugin } from './rxdb-plugin';
|
|
7
|
+
import { RxDBContext, RxDBOptions } from './rxdb.interface';
|
|
8
|
+
import { SchemaManager } from './schema/SchemaManager';
|
|
9
|
+
type EventListener<T> = (event: T) => void;
|
|
10
|
+
type RxDBConfig = SetRequired<RxDBOptions, 'relationQueryDeep'>;
|
|
11
|
+
/**
|
|
12
|
+
* RxDB
|
|
13
|
+
*/
|
|
14
|
+
export declare class RxDB {
|
|
15
|
+
#private;
|
|
16
|
+
/**
|
|
17
|
+
* Schema 管理
|
|
18
|
+
*/
|
|
19
|
+
readonly schema: SchemaManager;
|
|
20
|
+
/**
|
|
21
|
+
* Entity 管理
|
|
22
|
+
*/
|
|
23
|
+
readonly em: EntityManager;
|
|
24
|
+
/**
|
|
25
|
+
* 设置环境上下文
|
|
26
|
+
*/
|
|
27
|
+
get context(): RxDBContext;
|
|
28
|
+
set context(context: RxDBContext);
|
|
29
|
+
readonly options: RxDBConfig;
|
|
30
|
+
constructor(options: RxDBOptions);
|
|
31
|
+
/**
|
|
32
|
+
* 注册适配器
|
|
33
|
+
*/
|
|
34
|
+
adapter<K extends keyof RxDBAdapters>(adapterName: K, adapter: AdapterFactory): this;
|
|
35
|
+
/**
|
|
36
|
+
* 获取适配器
|
|
37
|
+
*/
|
|
38
|
+
getAdapter<K extends keyof RxDBAdapters>(adapterName: K): Observable<RxDBAdapters[K]>;
|
|
39
|
+
/**
|
|
40
|
+
* 安装插件
|
|
41
|
+
*/
|
|
42
|
+
use<Options = any>(plugin: Plugin<Options>, options?: Options): this;
|
|
43
|
+
/**
|
|
44
|
+
* 连接适配器
|
|
45
|
+
*/
|
|
46
|
+
connect<K extends keyof RxDBAdapters>(adapterName: K): Observable<import('./rxdb-adapter').IRxDBAdapter>;
|
|
47
|
+
addEventListener<T extends keyof RxDBEventMap>(type: T, listener: EventListener<RxDBEventMap[T]>): void;
|
|
48
|
+
removeEventListener<T extends keyof RxDBEventMap>(type: T, listener: EventListener<RxDBEventMap[T]>): void;
|
|
49
|
+
dispatchEvent(event: RxDBEvent): void;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
package/RxDBError.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RxDB 基础错误类型
|
|
3
|
+
*/
|
|
4
|
+
export declare class RxDBError extends Error {
|
|
5
|
+
messageTemplate: string;
|
|
6
|
+
data: {
|
|
7
|
+
[name: string]: string | number;
|
|
8
|
+
};
|
|
9
|
+
constructor(messageTemplate: string, data?: {
|
|
10
|
+
[name: string]: string | number;
|
|
11
|
+
});
|
|
12
|
+
toString(): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EntityMetadataOptions } from './entity-metadata-options.interface';
|
|
2
|
+
import { AbstractEntityType, EntityType } from './entity.interface';
|
|
3
|
+
/**
|
|
4
|
+
* 装饰后的实体类型
|
|
5
|
+
* 根据原始类型是否为抽象类,返回相应的构造函数类型
|
|
6
|
+
*/
|
|
7
|
+
type DecoratedEntityType<T extends EntityType | AbstractEntityType> = T extends EntityType ? new (initData?: Partial<InstanceType<T>>) => InstanceType<T> : abstract new (initData?: Partial<InstanceType<T>>) => InstanceType<T>;
|
|
8
|
+
/**
|
|
9
|
+
* 实体装饰器
|
|
10
|
+
* 用于将类标记为 RxDB 实体,并处理元数据、代理和生命周期
|
|
11
|
+
*
|
|
12
|
+
* 该装饰器会:
|
|
13
|
+
* 1. 转换并存储实体元数据
|
|
14
|
+
* 2. 处理实体的默认值和初始值
|
|
15
|
+
* 3. 为实体创建代理,以支持变更跟踪和关系管理
|
|
16
|
+
* 4. 处理抽象实体和具体实体的不同行为
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // 基本用法
|
|
21
|
+
* @Entity({ name: 'User' })
|
|
22
|
+
* class User extends EntityBase {}
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param metadataOptions - 实体元数据选项,包含名称、显示名称、属性、关系、索引等配置
|
|
26
|
+
* @returns 类装饰器函数
|
|
27
|
+
*/
|
|
28
|
+
export declare const Entity: (metadataOptions: EntityMetadataOptions) => <T extends EntityType | AbstractEntityType>(target: T) => DecoratedEntityType<T>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { EntityMetadataOptions } from './entity-metadata-options.interface';
|
|
2
|
+
/**
|
|
3
|
+
* 树形结构类型
|
|
4
|
+
*
|
|
5
|
+
* 目前仅支持邻接表模型,未来可能支持其他模型:
|
|
6
|
+
* - 'closure-table': 闭包表模型
|
|
7
|
+
* - 'nested-set': 嵌套集模型
|
|
8
|
+
* - 'materialized-path': 物化路径模型
|
|
9
|
+
*
|
|
10
|
+
* 参考资料:
|
|
11
|
+
* - https://www.slideshare.net/slideshow/models-for-hierarchical-data/4179181
|
|
12
|
+
* - https://schinckel.net/2014/09/13/long-live-adjacency-lists/
|
|
13
|
+
*/
|
|
14
|
+
type TreeType = 'adjacency-list';
|
|
15
|
+
/**
|
|
16
|
+
* 树形实体元数据选项接口
|
|
17
|
+
* 扩展基本实体元数据,添加树形结构特定配置
|
|
18
|
+
*/
|
|
19
|
+
interface TreeEntityMetadataOptions extends EntityMetadataOptions {
|
|
20
|
+
/**
|
|
21
|
+
* 树形结构类型
|
|
22
|
+
* 指定使用哪种树形结构模型
|
|
23
|
+
*/
|
|
24
|
+
treeType: TreeType;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 树形实体装饰器
|
|
28
|
+
* 用于将类标记为树形结构实体,并处理树形特定的元数据
|
|
29
|
+
*
|
|
30
|
+
* 该装饰器基于基础的Entity装饰器,但添加了树形结构特定的处理:
|
|
31
|
+
* 1. 设置默认仓库为TreeRepository
|
|
32
|
+
* 2. 处理树形结构特定的元数据
|
|
33
|
+
* 3. 支持树形结构的查询和操作
|
|
34
|
+
*
|
|
35
|
+
* 树形实体通常包含以下关系:
|
|
36
|
+
* - parent: 指向父节点的关系
|
|
37
|
+
* - children: 指向子节点的关系集合
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* @TreeEntity({
|
|
42
|
+
* name: 'Category',
|
|
43
|
+
* treeType: 'adjacency-list'
|
|
44
|
+
* })
|
|
45
|
+
* class Category extends TreeAdjacencyListEntityBase {
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const TreeEntity: (metadataOptions: TreeEntityMetadataOptions) => <T extends import('./entity.interface').EntityType | import('./entity.interface').AbstractEntityType>(target: T) => T extends import('./entity.interface').EntityType ? new (initData?: Partial<InstanceType<T>> | undefined) => InstanceType<T> : abstract new (initData?: Partial<InstanceType<T>> | undefined) => InstanceType<T>;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { IEntity, UUID } from './entity.interface';
|
|
2
|
+
/**
|
|
3
|
+
* 实体基类装饰器配置
|
|
4
|
+
* 定义了所有实体共有的基础属性
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class EntityBase implements IEntity {
|
|
7
|
+
/**
|
|
8
|
+
* 实体唯一标识符
|
|
9
|
+
* 自动生成的UUID,作为主键
|
|
10
|
+
*/
|
|
11
|
+
readonly id: UUID;
|
|
12
|
+
/**
|
|
13
|
+
* 创建时间
|
|
14
|
+
* 实体创建时自动设置为当前时间
|
|
15
|
+
*/
|
|
16
|
+
readonly createdAt: Date;
|
|
17
|
+
/**
|
|
18
|
+
* 更新时间
|
|
19
|
+
* 实体创建或更新时自动设置为当前时间
|
|
20
|
+
*/
|
|
21
|
+
readonly updatedAt: Date;
|
|
22
|
+
/**
|
|
23
|
+
* 删除时间
|
|
24
|
+
* 实体被软删除时设置为当前时间,否则为null
|
|
25
|
+
*/
|
|
26
|
+
readonly removedAt?: Date | null;
|
|
27
|
+
/**
|
|
28
|
+
* 创建者ID
|
|
29
|
+
* 记录创建此实体的用户ID
|
|
30
|
+
*/
|
|
31
|
+
readonly createdBy?: UUID | null;
|
|
32
|
+
/**
|
|
33
|
+
* 更新者ID
|
|
34
|
+
* 记录最后更新此实体的用户ID
|
|
35
|
+
*/
|
|
36
|
+
readonly updatedBy?: UUID | null;
|
|
37
|
+
/**
|
|
38
|
+
* 删除者ID
|
|
39
|
+
* 记录删除此实体的用户ID
|
|
40
|
+
*/
|
|
41
|
+
readonly removedBy?: UUID | null;
|
|
42
|
+
/**
|
|
43
|
+
* 实体基类构造函数
|
|
44
|
+
* 子类会通过 Entity 装饰器增强此构造函数
|
|
45
|
+
*
|
|
46
|
+
* @param initData - 可选的初始化数据
|
|
47
|
+
*/
|
|
48
|
+
constructor(initData?: any);
|
|
49
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Repository } from '../repository/Repository';
|
|
2
|
+
import { RxDB } from '../RxDB';
|
|
3
|
+
import { EntityType, RowId, UUID } from './entity.interface';
|
|
4
|
+
import { EntityStatusOptions } from './EntityStatus';
|
|
5
|
+
/**
|
|
6
|
+
* 实体管理器
|
|
7
|
+
*
|
|
8
|
+
* 负责管理实体的整个生命周期,包括:
|
|
9
|
+
* 1. 实体的创建、更新和删除
|
|
10
|
+
* 2. 实体缓存管理
|
|
11
|
+
* 3. 实体关系处理
|
|
12
|
+
* 4. 实体仓库访问
|
|
13
|
+
* 5. 实体代理和变更跟踪
|
|
14
|
+
*
|
|
15
|
+
* 实体管理器是连接实体、仓库和数据库的桥梁,
|
|
16
|
+
* 它确保实体状态的一致性,并处理实体间的关系。
|
|
17
|
+
*/
|
|
18
|
+
export declare class EntityManager {
|
|
19
|
+
#private;
|
|
20
|
+
readonly rxdb: RxDB;
|
|
21
|
+
/**
|
|
22
|
+
* 创建实体管理器实例
|
|
23
|
+
*
|
|
24
|
+
* 构造函数会:
|
|
25
|
+
* 1. 为所有注册的实体类型添加静态和实例方法
|
|
26
|
+
* 2. 设置实体关系处理
|
|
27
|
+
* 3. 配置实体代理和删除检查
|
|
28
|
+
*
|
|
29
|
+
* @param rxdb - RxDB实例,提供数据库访问和事件分发
|
|
30
|
+
*/
|
|
31
|
+
constructor(rxdb: RxDB);
|
|
32
|
+
/**
|
|
33
|
+
* 创建实体引用
|
|
34
|
+
* 根据提供的数据创建或获取实体实例,并设置其状态
|
|
35
|
+
* 如果实体已存在于缓存中,则返回缓存的实例
|
|
36
|
+
*
|
|
37
|
+
* @template T 实体类型
|
|
38
|
+
* @param EntityType - 实体类型
|
|
39
|
+
* @param data - 实体数据,必须包含id
|
|
40
|
+
* @param [status] - 可选的实体状态配置
|
|
41
|
+
* @returns 创建或获取的实体实例
|
|
42
|
+
*/
|
|
43
|
+
createEntityRef<T extends EntityType>(EntityType: T, data: Partial<InstanceType<T>> & {
|
|
44
|
+
id: UUID;
|
|
45
|
+
}, status?: EntityStatusOptions<T>): any;
|
|
46
|
+
/**
|
|
47
|
+
* 获取实体引用
|
|
48
|
+
* 从缓存中获取指定ID的实体实例
|
|
49
|
+
*
|
|
50
|
+
* @template T 实体类型
|
|
51
|
+
* @param EntityType - 实体类型
|
|
52
|
+
* @param id - 实体ID
|
|
53
|
+
* @returns 实体实例,如果不存在则返回undefined
|
|
54
|
+
*/
|
|
55
|
+
getEntityRef<T extends EntityType>(EntityType: T, id: UUID): InstanceType<T> | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* 检查实体是否在缓存中
|
|
58
|
+
* 判断指定ID的实体是否已在缓存中初始化
|
|
59
|
+
*
|
|
60
|
+
* @template T 实体类型
|
|
61
|
+
* @param EntityType - 实体类型
|
|
62
|
+
* @param id - 实体ID
|
|
63
|
+
* @returns 如果实体在缓存中存在则返回true
|
|
64
|
+
*/
|
|
65
|
+
hasEntityRef<T extends EntityType>(EntityType: T, id: UUID): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 添加实体到缓存
|
|
68
|
+
* 将实体实例添加到对应类型的缓存映射中
|
|
69
|
+
*
|
|
70
|
+
* @template T 实体类型
|
|
71
|
+
* @param entity - 要缓存的实体实例
|
|
72
|
+
*/
|
|
73
|
+
addEntityCache<T extends EntityType>(entity: InstanceType<T>): void;
|
|
74
|
+
/**
|
|
75
|
+
* 从缓存中删除实体
|
|
76
|
+
* 将实体实例从缓存映射中移除
|
|
77
|
+
*
|
|
78
|
+
* @template T 实体类型
|
|
79
|
+
* @param entity - 要移除的实体实例
|
|
80
|
+
*/
|
|
81
|
+
removeEntityCache<T extends EntityType>(entity: InstanceType<T>): void;
|
|
82
|
+
/**
|
|
83
|
+
* 更新实体的行ID映射
|
|
84
|
+
* 建立数据库行ID到实体UUID的映射关系
|
|
85
|
+
*
|
|
86
|
+
* @template T 实体类型
|
|
87
|
+
* @param entity - 实体实例
|
|
88
|
+
* @param rowId - 数据库行ID
|
|
89
|
+
*/
|
|
90
|
+
updateEntityRowId<T extends EntityType>(entity: InstanceType<T>, rowId: RowId): void;
|
|
91
|
+
/**
|
|
92
|
+
* 保存实体
|
|
93
|
+
* 根据实体状态决定是创建新实体还是更新现有实体
|
|
94
|
+
* 如果有关联实体需要保存,会使用事务进行批量保存
|
|
95
|
+
*
|
|
96
|
+
* @template T 实体类型
|
|
97
|
+
* @param data - 要保存的实体实例
|
|
98
|
+
* @returns 保存后的实体实例
|
|
99
|
+
*/
|
|
100
|
+
save<T extends EntityType>(data: InstanceType<T>): Promise<InstanceType<T>>;
|
|
101
|
+
/**
|
|
102
|
+
* 删除实体
|
|
103
|
+
* 从数据库中删除实体,并分发相关事件
|
|
104
|
+
*
|
|
105
|
+
* @template T 实体类型
|
|
106
|
+
* @param data - 要删除的实体实例
|
|
107
|
+
* @returns 删除后的实体实例
|
|
108
|
+
* @throws 如果删除失败,抛出错误
|
|
109
|
+
*/
|
|
110
|
+
remove<T extends EntityType>(data: InstanceType<T>): Promise<InstanceType<T>>;
|
|
111
|
+
/**
|
|
112
|
+
* 创建实体
|
|
113
|
+
* 在数据库中创建新实体,并分发相关事件
|
|
114
|
+
*
|
|
115
|
+
* @template T 实体类型
|
|
116
|
+
* @param data - 要创建的实体实例
|
|
117
|
+
* @returns 创建后的实体实例
|
|
118
|
+
* @throws 如果创建失败,抛出错误
|
|
119
|
+
*/
|
|
120
|
+
create<T extends EntityType>(data: InstanceType<T>): Promise<InstanceType<T>>;
|
|
121
|
+
/**
|
|
122
|
+
* 更新实体
|
|
123
|
+
* 在数据库中更新实体,只更新已修改的属性,并分发相关事件
|
|
124
|
+
*
|
|
125
|
+
* @template T 实体类型
|
|
126
|
+
* @param data - 要更新的实体实例
|
|
127
|
+
* @returns 更新后的实体实例
|
|
128
|
+
* @throws 如果更新失败,抛出错误
|
|
129
|
+
*/
|
|
130
|
+
update<T extends EntityType>(data: InstanceType<T>): Promise<InstanceType<T>>;
|
|
131
|
+
/**
|
|
132
|
+
* 获取实体仓库
|
|
133
|
+
* 获取指定实体类型的仓库实例
|
|
134
|
+
*
|
|
135
|
+
* @template T 实体类型
|
|
136
|
+
* @param EntityType - 实体类型
|
|
137
|
+
* @returns 实体仓库实例
|
|
138
|
+
*/
|
|
139
|
+
getRepository<T extends EntityType>(EntityType: T): Repository<T>;
|
|
140
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { RxDB } from '../RxDB';
|
|
2
|
+
import { UnixMilliseconds } from '../rxdb.interface';
|
|
3
|
+
import { STATUS_CHECK, UpdatedBy } from '../rxdb.private';
|
|
4
|
+
import { EntityRelationMetadata, RelationKind } from './entity-metadata-options.interface';
|
|
5
|
+
import { EntityType, RowId } from './entity.interface';
|
|
6
|
+
/**
|
|
7
|
+
* 实体变化记录接口
|
|
8
|
+
* 记录实体的变更信息,包括变更内容、逆向变更、时间戳等
|
|
9
|
+
*
|
|
10
|
+
* @interface
|
|
11
|
+
* @template T 实体类型
|
|
12
|
+
*/
|
|
13
|
+
export interface EntityPatch<T extends EntityType> {
|
|
14
|
+
/**
|
|
15
|
+
* 变化
|
|
16
|
+
*/
|
|
17
|
+
patch: Partial<InstanceType<T>>;
|
|
18
|
+
/**
|
|
19
|
+
* 逆变化
|
|
20
|
+
*/
|
|
21
|
+
inversePatch: Partial<InstanceType<T>>;
|
|
22
|
+
/**
|
|
23
|
+
* 更新者
|
|
24
|
+
*/
|
|
25
|
+
updatedBy: UpdatedBy;
|
|
26
|
+
/**
|
|
27
|
+
* 记录的毫秒世界时间
|
|
28
|
+
*/
|
|
29
|
+
recordAt: UnixMilliseconds;
|
|
30
|
+
/**
|
|
31
|
+
* 记录的程序开始的时间
|
|
32
|
+
* 用于 recordAt 一样的时候排序用
|
|
33
|
+
*/
|
|
34
|
+
timeStamp: DOMHighResTimeStamp;
|
|
35
|
+
/**
|
|
36
|
+
* 数据快照
|
|
37
|
+
* 为了节省内存,只会在第一次变化时记录完整数据,后续只记录变化
|
|
38
|
+
* 如果历史记录有最大限制,需要删除,那么可以利用这个数据之上 patch 变化来计算数据
|
|
39
|
+
*/
|
|
40
|
+
snapshot: any;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 实体状态接口
|
|
44
|
+
* 定义实体状态的基本属性和行为
|
|
45
|
+
*/
|
|
46
|
+
export interface IEntityStatus<T extends EntityType> {
|
|
47
|
+
/**
|
|
48
|
+
* 当前实体
|
|
49
|
+
*/
|
|
50
|
+
target: InstanceType<EntityType>;
|
|
51
|
+
/**
|
|
52
|
+
* 是否已修改
|
|
53
|
+
*/
|
|
54
|
+
modified?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* 是否在本地
|
|
57
|
+
*/
|
|
58
|
+
local?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* 是否在远程
|
|
61
|
+
*/
|
|
62
|
+
remote?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* 实体变化
|
|
65
|
+
*/
|
|
66
|
+
patches?: EntityPatch<T>[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 实体状态选项类型
|
|
70
|
+
* 用于创建实体状态实例时的配置选项
|
|
71
|
+
*/
|
|
72
|
+
export type EntityStatusOptions<T extends EntityType> = Omit<IEntityStatus<T>, 'target' | 'proxyTarget'>;
|
|
73
|
+
/**
|
|
74
|
+
* 实体状态类
|
|
75
|
+
* 管理实体的状态信息,包括本地/远程状态、修改状态、变更历史等
|
|
76
|
+
* 处理实体关系和变更追踪
|
|
77
|
+
*/
|
|
78
|
+
export declare class EntityStatus<T extends EntityType> implements IEntityStatus<T> {
|
|
79
|
+
#private;
|
|
80
|
+
readonly rxdb: RxDB;
|
|
81
|
+
/**
|
|
82
|
+
* 标识实体是否存在于远程数据库
|
|
83
|
+
*/
|
|
84
|
+
protected _remote: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* 标识实体是否存在于本地数据库
|
|
87
|
+
*/
|
|
88
|
+
protected _local: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* 标识实体是否已被修改
|
|
91
|
+
*/
|
|
92
|
+
protected _modified: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* 标识实体是否已被删除
|
|
95
|
+
*/
|
|
96
|
+
protected _removed: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* 实体在数据库中的行ID
|
|
99
|
+
*/
|
|
100
|
+
protected _rowId?: RowId;
|
|
101
|
+
/**
|
|
102
|
+
* 实体变更记录数组
|
|
103
|
+
*/
|
|
104
|
+
protected _patches: EntityPatch<T>[];
|
|
105
|
+
/**
|
|
106
|
+
* 实体原始对象
|
|
107
|
+
*/
|
|
108
|
+
readonly target: InstanceType<T>;
|
|
109
|
+
/**
|
|
110
|
+
* 实体代理对象
|
|
111
|
+
* 用于拦截属性访问和修改
|
|
112
|
+
*/
|
|
113
|
+
readonly proxyTarget: InstanceType<T>;
|
|
114
|
+
/**
|
|
115
|
+
* 实体变更记录的可观察流
|
|
116
|
+
* 用于订阅实体变更
|
|
117
|
+
*/
|
|
118
|
+
readonly patches$: import('rxjs').Observable<EntityPatch<T>[]>;
|
|
119
|
+
/**
|
|
120
|
+
* 状态检查标记
|
|
121
|
+
* 用于内部状态验证
|
|
122
|
+
*/
|
|
123
|
+
[STATUS_CHECK]: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* 实体原始数据
|
|
126
|
+
* 用于比较变更和恢复
|
|
127
|
+
*/
|
|
128
|
+
_origin: any;
|
|
129
|
+
/**
|
|
130
|
+
* 是否已修改
|
|
131
|
+
*/
|
|
132
|
+
get modified(): boolean;
|
|
133
|
+
set modified(value: boolean);
|
|
134
|
+
/**
|
|
135
|
+
* 是否已删除
|
|
136
|
+
*/
|
|
137
|
+
get removed(): boolean;
|
|
138
|
+
set removed(value: boolean);
|
|
139
|
+
/**
|
|
140
|
+
* 是否是远程数据
|
|
141
|
+
*/
|
|
142
|
+
get remote(): boolean;
|
|
143
|
+
set remote(value: boolean);
|
|
144
|
+
/**
|
|
145
|
+
* 是否是本地数据
|
|
146
|
+
*/
|
|
147
|
+
get local(): boolean;
|
|
148
|
+
set local(value: boolean);
|
|
149
|
+
/**
|
|
150
|
+
* 获取变化
|
|
151
|
+
*/
|
|
152
|
+
get patches(): EntityPatch<T>[];
|
|
153
|
+
/**
|
|
154
|
+
* 设置原始值
|
|
155
|
+
*/
|
|
156
|
+
set origin(value: any);
|
|
157
|
+
get origin(): any;
|
|
158
|
+
/**
|
|
159
|
+
* 设置 rowId
|
|
160
|
+
*/
|
|
161
|
+
set rowId(value: RowId);
|
|
162
|
+
get rowId(): RowId | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* 创建实体状态实例
|
|
165
|
+
*
|
|
166
|
+
* @constructor
|
|
167
|
+
* @param rxdb - RxDB 实例
|
|
168
|
+
* @param data - 实体状态初始数据
|
|
169
|
+
*/
|
|
170
|
+
constructor(rxdb: RxDB, data: IEntityStatus<T>);
|
|
171
|
+
/**
|
|
172
|
+
* 添加实体变更记录
|
|
173
|
+
* 记录实体的变更并发布变更事件
|
|
174
|
+
*
|
|
175
|
+
* @param patch - 变更内容
|
|
176
|
+
* @param inversePatch - 逆向变更内容,用于撤销操作
|
|
177
|
+
* @param updatedBy - 更新者信息
|
|
178
|
+
* @param [recordAt=Date.now()] - 记录时间戳
|
|
179
|
+
*/
|
|
180
|
+
addEntityPatch(patch: Partial<InstanceType<T>>, inversePatch: Partial<InstanceType<T>>, updatedBy: UpdatedBy, recordAt?: number): void;
|
|
181
|
+
/**
|
|
182
|
+
* 获取需要保存的关联实体
|
|
183
|
+
* 根据关系类型的优先级排序,返回需要保存的实体数组
|
|
184
|
+
*
|
|
185
|
+
* @returns 需要保存的实体数组
|
|
186
|
+
*/
|
|
187
|
+
getNeedSaveRelationEntities(): InstanceType<T>[];
|
|
188
|
+
/**
|
|
189
|
+
* 添加关系实体
|
|
190
|
+
* 根据关系类型处理实体间的关联
|
|
191
|
+
*
|
|
192
|
+
* @param relation - 关系元数据
|
|
193
|
+
* @param entity - 要关联的实体
|
|
194
|
+
*/
|
|
195
|
+
addRelationEntity(relation: EntityRelationMetadata, entity: InstanceType<EntityType>): void;
|
|
196
|
+
/**
|
|
197
|
+
* 删除关系实体
|
|
198
|
+
* 根据关系类型移除实体间的关联
|
|
199
|
+
*
|
|
200
|
+
* @param relation - 关系元数据
|
|
201
|
+
* @param entity - 要移除关联的实体
|
|
202
|
+
*/
|
|
203
|
+
removeRelationEntity(relation: EntityRelationMetadata, entity: InstanceType<EntityType>): void;
|
|
204
|
+
/**
|
|
205
|
+
* 获取指定关系类型的实体缓存
|
|
206
|
+
* 如果缓存不存在则创建新的缓存
|
|
207
|
+
*
|
|
208
|
+
* @param kind - 关系类型
|
|
209
|
+
*/
|
|
210
|
+
getRelationCache(kind: RelationKind): Set<InstanceType<EntityType>>;
|
|
211
|
+
}
|