@aiao/rxdb 0.0.5 → 0.0.7
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/RxDB.d.ts +118 -21
- package/dist/RxDB.d.ts.map +1 -1
- package/dist/RxDBError.d.ts.map +1 -1
- package/dist/entity/@Entity.d.ts +1 -1
- package/dist/entity/@Entity.d.ts.map +1 -1
- package/dist/entity/@TreeEntity.d.ts +2 -21
- package/dist/entity/@TreeEntity.d.ts.map +1 -1
- package/dist/entity/EntityBase.d.ts +59 -11
- package/dist/entity/EntityBase.d.ts.map +1 -1
- package/dist/entity/EntityManager.d.ts +18 -25
- package/dist/entity/EntityManager.d.ts.map +1 -1
- package/dist/entity/EntityStatus.d.ts +149 -107
- package/dist/entity/EntityStatus.d.ts.map +1 -1
- package/dist/entity/EntityStatus.interface.d.ts +59 -0
- package/dist/entity/EntityStatus.interface.d.ts.map +1 -0
- package/dist/entity/TreeEntityBase.d.ts +32 -5
- package/dist/entity/TreeEntityBase.d.ts.map +1 -1
- package/dist/entity/entity.interface.d.ts +23 -34
- package/dist/entity/entity.interface.d.ts.map +1 -1
- package/dist/entity/entity.utils.d.ts +23 -2
- package/dist/entity/entity.utils.d.ts.map +1 -1
- package/dist/entity/{generate_many_to_many_entity.d.ts → many_to_many_entity.d.ts} +3 -3
- package/dist/entity/many_to_many_entity.d.ts.map +1 -0
- package/dist/entity/{entity-metadata-options.interface.d.ts → metadata-options.interface.d.ts} +312 -35
- package/dist/entity/metadata-options.interface.d.ts.map +1 -0
- package/dist/entity/{transition-metadata.d.ts → metadata-transition.d.ts} +3 -3
- package/dist/entity/metadata-transition.d.ts.map +1 -0
- package/dist/entity/{entity-metadata.interface.d.ts → metadata.interface.d.ts} +8 -2
- package/dist/entity/metadata.interface.d.ts.map +1 -0
- package/dist/entity/metadata_cascade_default.d.ts +54 -0
- package/dist/entity/metadata_cascade_default.d.ts.map +1 -0
- package/dist/entity/proxy.d.ts +7 -0
- package/dist/entity/proxy.d.ts.map +1 -0
- package/dist/entity/{entity_relation_helper.d.ts → relation_helper.d.ts} +2 -2
- package/dist/entity/relation_helper.d.ts.map +1 -0
- package/dist/entity/tree-entity.interface.d.ts +5 -0
- package/dist/entity/tree-entity.interface.d.ts.map +1 -0
- package/dist/gateway/RxDBTabsGateway.d.ts +52 -0
- package/dist/gateway/RxDBTabsGateway.d.ts.map +1 -0
- package/dist/gateway/gateway.interface.d.ts +43 -0
- package/dist/gateway/gateway.interface.d.ts.map +1 -0
- package/dist/index.d.ts +19 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6579 -2876
- package/dist/query/entity_type_dependencies.d.ts +22 -0
- package/dist/query/entity_type_dependencies.d.ts.map +1 -0
- package/dist/query/merge-update-basic.d.ts +30 -0
- package/dist/query/merge-update-basic.d.ts.map +1 -0
- package/dist/query/merge-update-tree.d.ts +86 -0
- package/dist/query/merge-update-tree.d.ts.map +1 -0
- package/dist/query/merge-update.utils.d.ts +52 -0
- package/dist/query/merge-update.utils.d.ts.map +1 -0
- package/dist/query/merge_create.d.ts +19 -0
- package/dist/query/merge_create.d.ts.map +1 -0
- package/dist/query/merge_remove.d.ts +6 -0
- package/dist/query/merge_remove.d.ts.map +1 -0
- package/dist/query/merge_update.d.ts +24 -0
- package/dist/query/merge_update.d.ts.map +1 -0
- package/dist/query/need_refresh_create.d.ts +11 -0
- package/dist/query/need_refresh_create.d.ts.map +1 -0
- package/dist/query/need_refresh_remove.d.ts +6 -0
- package/dist/query/need_refresh_remove.d.ts.map +1 -0
- package/dist/query/need_refresh_update.d.ts +11 -0
- package/dist/query/need_refresh_update.d.ts.map +1 -0
- package/dist/query/query-matching.utils.d.ts +60 -0
- package/dist/query/query-matching.utils.d.ts.map +1 -0
- package/dist/query/query-relation.utils.d.ts +44 -0
- package/dist/query/query-relation.utils.d.ts.map +1 -0
- package/dist/query/query-rules-builder.d.ts +68 -0
- package/dist/query/query-rules-builder.d.ts.map +1 -0
- package/dist/query/query-tree.utils.d.ts +54 -0
- package/dist/query/query-tree.utils.d.ts.map +1 -0
- package/dist/repository/QueryManager.d.ts +69 -0
- package/dist/repository/QueryManager.d.ts.map +1 -0
- package/dist/repository/QueryManager.interface.d.ts +106 -0
- package/dist/repository/QueryManager.interface.d.ts.map +1 -0
- package/dist/repository/QueryTask.d.ts +150 -0
- package/dist/repository/QueryTask.d.ts.map +1 -0
- package/dist/repository/Repository.d.ts +38 -44
- package/dist/repository/Repository.d.ts.map +1 -1
- package/dist/repository/RepositoryBase.d.ts +8 -8
- package/dist/repository/RepositoryBase.d.ts.map +1 -1
- package/dist/repository/TreeRepository.d.ts +29 -4
- package/dist/repository/TreeRepository.d.ts.map +1 -1
- package/dist/repository/fingerprint.utils.d.ts +28 -0
- package/dist/repository/fingerprint.utils.d.ts.map +1 -0
- package/dist/repository/query-options.interface.d.ts +88 -16
- package/dist/repository/query-options.interface.d.ts.map +1 -1
- package/dist/repository/query.interface.d.ts +107 -37
- package/dist/repository/query.interface.d.ts.map +1 -1
- package/dist/repository/relation-query.interface.d.ts +20 -1
- package/dist/repository/relation-query.interface.d.ts.map +1 -1
- package/dist/repository/repository.interface.d.ts +4 -29
- package/dist/repository/repository.interface.d.ts.map +1 -1
- package/dist/repository/tree-repository.interface.d.ts +34 -30
- package/dist/repository/tree-repository.interface.d.ts.map +1 -1
- package/dist/rxdb-adapter.d.ts +100 -16
- package/dist/rxdb-adapter.d.ts.map +1 -1
- package/dist/rxdb-events.d.ts +335 -66
- package/dist/rxdb-events.d.ts.map +1 -1
- package/dist/rxdb-plugin.d.ts +2 -2
- package/dist/rxdb-plugin.d.ts.map +1 -1
- package/dist/rxdb-utils.d.ts +20 -9
- package/dist/rxdb-utils.d.ts.map +1 -1
- package/dist/rxdb.interface.d.ts +5 -9
- package/dist/rxdb.interface.d.ts.map +1 -1
- package/dist/rxdb.private.d.ts +7 -36
- package/dist/rxdb.private.d.ts.map +1 -1
- package/dist/schema/SchemaManager.d.ts +5 -4
- package/dist/schema/SchemaManager.d.ts.map +1 -1
- package/dist/system/branch.d.ts +124 -7
- package/dist/system/branch.d.ts.map +1 -1
- package/dist/system/change.d.ts +605 -33
- package/dist/system/change.d.ts.map +1 -1
- package/dist/system/migration.d.ts +61 -11
- package/dist/system/migration.d.ts.map +1 -1
- package/dist/system/repository-sync.d.ts +95 -0
- package/dist/system/repository-sync.d.ts.map +1 -0
- package/dist/system/system.interface.d.ts +25 -0
- package/dist/system/system.interface.d.ts.map +1 -0
- package/dist/system/types.d.ts +234 -139
- package/dist/system/types.d.ts.map +1 -1
- package/dist/system/types.local.d.ts +156 -0
- package/dist/system/types.local.d.ts.map +1 -0
- package/dist/system/types.remote.d.ts +103 -0
- package/dist/system/types.remote.d.ts.map +1 -0
- package/dist/version/HistoryManager.d.ts +238 -0
- package/dist/version/HistoryManager.d.ts.map +1 -0
- package/dist/version/LWWConflictResolver.d.ts +41 -0
- package/dist/version/LWWConflictResolver.d.ts.map +1 -0
- package/dist/version/VersionManager.d.ts +407 -0
- package/dist/version/VersionManager.d.ts.map +1 -0
- package/dist/version/VersionManager.interface.d.ts +428 -0
- package/dist/version/VersionManager.interface.d.ts.map +1 -0
- package/dist/version/VersionManager.utils.d.ts +14 -0
- package/dist/version/VersionManager.utils.d.ts.map +1 -0
- package/dist/version/bulk-sync.d.ts +97 -0
- package/dist/version/bulk-sync.d.ts.map +1 -0
- package/dist/version/check-repository-updates.d.ts +53 -0
- package/dist/version/check-repository-updates.d.ts.map +1 -0
- package/dist/version/compact-changes.d.ts +45 -0
- package/dist/version/compact-changes.d.ts.map +1 -0
- package/dist/version/conflict.d.ts +75 -0
- package/dist/version/conflict.d.ts.map +1 -0
- package/dist/version/create_branch.d.ts +13 -0
- package/dist/version/create_branch.d.ts.map +1 -0
- package/dist/version/dependency-graph.d.ts +132 -0
- package/dist/version/dependency-graph.d.ts.map +1 -0
- package/dist/version/find_switch_branch_step.d.ts +53 -0
- package/dist/version/find_switch_branch_step.d.ts.map +1 -0
- package/dist/version/get-all-repository-sync-status.d.ts +58 -0
- package/dist/version/get-all-repository-sync-status.d.ts.map +1 -0
- package/dist/version/get-repository-sync-status.d.ts +74 -0
- package/dist/version/get-repository-sync-status.d.ts.map +1 -0
- package/dist/version/pull-repository.d.ts +99 -0
- package/dist/version/pull-repository.d.ts.map +1 -0
- package/dist/version/pull.d.ts +11 -0
- package/dist/version/pull.d.ts.map +1 -0
- package/dist/version/push-repository.d.ts +93 -0
- package/dist/version/push-repository.d.ts.map +1 -0
- package/dist/version/push.d.ts +11 -0
- package/dist/version/push.d.ts.map +1 -0
- package/dist/version/remove_branch.d.ts +8 -0
- package/dist/version/remove_branch.d.ts.map +1 -0
- package/dist/version/switch_branch_actions.d.ts +17 -0
- package/dist/version/switch_branch_actions.d.ts.map +1 -0
- package/dist/version/sync-repository.d.ts +57 -0
- package/dist/version/sync-repository.d.ts.map +1 -0
- package/dist/version/sync-type-utils.d.ts +145 -0
- package/dist/version/sync-type-utils.d.ts.map +1 -0
- package/dist/version/topological-sort.d.ts +70 -0
- package/dist/version/topological-sort.d.ts.map +1 -0
- package/dist/version/version.utils.d.ts +4 -0
- package/dist/version/version.utils.d.ts.map +1 -0
- package/package.json +4 -3
- package/README.md +0 -1
- package/dist/entity/entity-metadata-options.interface.d.ts.map +0 -1
- package/dist/entity/entity-metadata.interface.d.ts.map +0 -1
- package/dist/entity/entity_proxy_helper.d.ts +0 -49
- package/dist/entity/entity_proxy_helper.d.ts.map +0 -1
- package/dist/entity/entity_relation_helper.d.ts.map +0 -1
- package/dist/entity/generate_many_to_many_entity.d.ts.map +0 -1
- package/dist/entity/transition-metadata.d.ts.map +0 -1
- package/dist/repository/query.utils.d.ts +0 -27
- package/dist/repository/query.utils.d.ts.map +0 -1
- package/dist/system/VersionManager.d.ts +0 -35
- package/dist/system/VersionManager.d.ts.map +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { EntityType } from '../entity/entity.interface.js';
|
|
3
|
+
import { RxDBEntityLocalCreatedEventData, RxDBEntityLocalRemovedEventData, RxDBEntityLocalUpdatedEventData } from '../rxdb-events.js';
|
|
4
|
+
import { RxDB } from '../RxDB.js';
|
|
5
|
+
import { QueryOptions } from './QueryManager.interface.js';
|
|
6
|
+
import { QueryTask } from './QueryTask.js';
|
|
7
|
+
import { Repository } from './Repository.js';
|
|
8
|
+
export type MergeQueryTaskCreateFn<T extends EntityType = any> = (task: QueryTask<T>, entities: RxDBEntityLocalCreatedEventData<T>[]) => void;
|
|
9
|
+
export type MergeQueryTaskUpdateFn<T extends EntityType = any> = (task: QueryTask<T>, entities: RxDBEntityLocalUpdatedEventData<T>[]) => void;
|
|
10
|
+
export type MergeQueryTaskRemoveFn<T extends EntityType = any> = (task: QueryTask<T>, entities: RxDBEntityLocalRemovedEventData<T>[]) => void;
|
|
11
|
+
interface CreateTaskOptions<T extends EntityType, RT> {
|
|
12
|
+
/**
|
|
13
|
+
* 查询选项
|
|
14
|
+
*/
|
|
15
|
+
options: QueryOptions<T>;
|
|
16
|
+
/**
|
|
17
|
+
* 查询执行函数
|
|
18
|
+
*/
|
|
19
|
+
runner: (options?: QueryOptions<T>) => Observable<RT>;
|
|
20
|
+
/**
|
|
21
|
+
* 结果指纹计算方法
|
|
22
|
+
*/
|
|
23
|
+
getFingerprint: (result: any) => any[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 查询缓存管理器
|
|
27
|
+
*
|
|
28
|
+
* 用于管理查询任务的缓存和执行
|
|
29
|
+
* - 需要根据查询条件记录观察表的依赖关系
|
|
30
|
+
* - 统一计算何时 js 计算,何时重新执行 sql,减少适配器的开发难度
|
|
31
|
+
* - 未来配置 Repository 里的规则,与远程进行 pull/push
|
|
32
|
+
*
|
|
33
|
+
* 核心功能:
|
|
34
|
+
* 1. 查询结果缓存:相同查询条件复用缓存结果
|
|
35
|
+
* 2. 订阅管理:管理多个观察者的订阅和取消订阅
|
|
36
|
+
* 3. 自动清理:当没有观察者时自动清理缓存
|
|
37
|
+
* 4. 响应式刷新:支持手动刷新和自动刷新查询结果
|
|
38
|
+
*/
|
|
39
|
+
export declare class QueryManager<T extends EntityType> {
|
|
40
|
+
#private;
|
|
41
|
+
protected readonly rxdb: RxDB;
|
|
42
|
+
protected readonly EntityType: T;
|
|
43
|
+
protected readonly repository: Repository<T>;
|
|
44
|
+
/**
|
|
45
|
+
* 构造函数
|
|
46
|
+
*
|
|
47
|
+
* @param rxdb RxDB 实例,用于访问数据库和事件系统
|
|
48
|
+
* @param EntityType 实体类型,用于标识当前管理的实体
|
|
49
|
+
* @param repository 仓库实例,用于执行实际的查询操作
|
|
50
|
+
*/
|
|
51
|
+
constructor(rxdb: RxDB, EntityType: T, repository: Repository<T>);
|
|
52
|
+
/**
|
|
53
|
+
* 创建查询任务
|
|
54
|
+
*
|
|
55
|
+
* 此方法根据查询选项创建或复用缓存的查询任务
|
|
56
|
+
* - 使用查询类型和选项的 hash 值作为缓存 key
|
|
57
|
+
* - 如果缓存中已存在相同的查询,直接返回缓存的任务
|
|
58
|
+
* - 每个查询任务管理多个观察者,当最后一个观察者取消订阅时自动清理任务
|
|
59
|
+
*
|
|
60
|
+
* @param taskOptions 查询任务选项
|
|
61
|
+
* @returns 查询任务对象,包含 result$ 用于订阅查询结果
|
|
62
|
+
*/
|
|
63
|
+
createTask<RT = any>(taskOptions: CreateTaskOptions<T, RT>): QueryTask<T>;
|
|
64
|
+
registerMergeCreateFn(taskType: string, fn: MergeQueryTaskCreateFn<T>): void;
|
|
65
|
+
registerMergeUpdateFn(taskType: string, fn: MergeQueryTaskUpdateFn<T>): void;
|
|
66
|
+
registerMergeRemoveFn(taskType: string, fn: MergeQueryTaskRemoveFn<T>): void;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=QueryManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryManager.d.ts","sourceRoot":"","sources":["../../src/repository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Ac,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,EAAE,CAAC;CACxC;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAY,CAAC,CAAC,SAAS,UAAU;;IAkB1C,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI;IAC7B,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IAChC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IAV9C;;;;;;OAMG;gBAEkB,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,CAAC,EACb,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IAQ9C;;;;;;;;;;OAUG;IACI,UAAU,CAAC,EAAE,GAAG,GAAG,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IAehF,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,sBAAsB,CAAC,CAAC,CAAC;IAIrE,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,sBAAsB,CAAC,CAAC,CAAC;IAIrE,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,sBAAsB,CAAC,CAAC,CAAC;CAmKtE"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { EntityStaticType, EntityType } from '../entity/entity.interface.js';
|
|
2
|
+
import { CountOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions } from './query-options.interface.js';
|
|
3
|
+
import { FindTreeOptions } from './tree-repository.interface.js';
|
|
4
|
+
/**
|
|
5
|
+
* Get 查询任务
|
|
6
|
+
* 根据 ID 获取单个实体的查询任务
|
|
7
|
+
*/
|
|
8
|
+
export interface GetQuery<T extends EntityType> {
|
|
9
|
+
type: 'get';
|
|
10
|
+
options: EntityStaticType<T, 'idType'>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* FindOne 查询任务
|
|
14
|
+
* 查找符合条件的第一个实体,可能返回 null
|
|
15
|
+
*/
|
|
16
|
+
export interface FindOneQuery<T extends EntityType> {
|
|
17
|
+
type: 'findOne';
|
|
18
|
+
options: FindOneOptions<T>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* FindOneOrFail 查询任务
|
|
22
|
+
* 查找符合条件的第一个实体,找不到时抛出错误
|
|
23
|
+
*/
|
|
24
|
+
export interface FindOneOrFailQuery<T extends EntityType> {
|
|
25
|
+
type: 'findOneOrFail';
|
|
26
|
+
options: FindOneOrFailOptions<T>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Find 查询任务
|
|
30
|
+
* 查找符合条件的所有实体
|
|
31
|
+
*/
|
|
32
|
+
export interface FindQuery<T extends EntityType> {
|
|
33
|
+
type: 'find';
|
|
34
|
+
options: FindOptions<T>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* FindAll 查询任务
|
|
38
|
+
* 查找所有实体
|
|
39
|
+
*/
|
|
40
|
+
export interface FindAllQuery<T extends EntityType> {
|
|
41
|
+
type: 'findAll';
|
|
42
|
+
options: FindAllOptions<T>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* FindByCursor 查询任务
|
|
46
|
+
* 使用游标分页查找实体
|
|
47
|
+
*/
|
|
48
|
+
export interface FindByCursorQuery<T extends EntityType> {
|
|
49
|
+
type: 'findByCursor';
|
|
50
|
+
options: FindByCursorOptions<T>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Count 查询任务
|
|
54
|
+
* 统计符合条件的实体数量
|
|
55
|
+
*/
|
|
56
|
+
export interface CountQuery<T extends EntityType> {
|
|
57
|
+
type: 'count';
|
|
58
|
+
options: CountOptions<T>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* FindDescendants 查询任务
|
|
62
|
+
* 查找指定实体的所有后代节点
|
|
63
|
+
*/
|
|
64
|
+
export interface FindDescendantsQuery<T extends EntityType> {
|
|
65
|
+
type: 'findDescendants';
|
|
66
|
+
options: FindTreeOptions<T>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* FindAncestors 查询任务
|
|
70
|
+
* 查找指定实体的所有祖先节点
|
|
71
|
+
*/
|
|
72
|
+
export interface FindAncestorsQuery<T extends EntityType> {
|
|
73
|
+
type: 'findAncestors';
|
|
74
|
+
options: FindTreeOptions<T>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* CountDescendants 查询任务
|
|
78
|
+
* 统计指定实体的后代节点数量
|
|
79
|
+
*/
|
|
80
|
+
export interface CountDescendantsQuery<T extends EntityType> {
|
|
81
|
+
type: 'countDescendants';
|
|
82
|
+
options: FindTreeOptions<T>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* CountAncestors 查询任务
|
|
86
|
+
* 统计指定实体的祖先节点数量
|
|
87
|
+
*/
|
|
88
|
+
export interface CountAncestorsQuery<T extends EntityType> {
|
|
89
|
+
type: 'countAncestors';
|
|
90
|
+
options: FindTreeOptions<T>;
|
|
91
|
+
}
|
|
92
|
+
export type QueryOptions<T extends EntityType> = GetQuery<T> | FindOneQuery<T> | FindOneOrFailQuery<T> | FindQuery<T> | FindAllQuery<T> | FindByCursorQuery<T> | CountQuery<T> | CountAncestorsQuery<T> | CountDescendantsQuery<T> | FindAncestorsQuery<T> | FindDescendantsQuery<T>;
|
|
93
|
+
/**
|
|
94
|
+
* 刷新匹配规则名称
|
|
95
|
+
* 定义查询缓存刷新时的匹配规则类型
|
|
96
|
+
*/
|
|
97
|
+
type RefreshMatchRuleName = 'match_where' | 'match_order_by' | 'match_relation_where' | 'not_match_relation_where' | 'result_contains' | 'not_match_where' | 'result_not_contains' | 'match_where_before' | 'not_match_where_before';
|
|
98
|
+
/**
|
|
99
|
+
* 刷新匹配规则
|
|
100
|
+
* 二维数组表示多组规则的组合,每组规则内的条件是 AND 关系,组与组之间是 OR 关系
|
|
101
|
+
* 例如:[['match_where', 'result_contains'], ['not_match_where']]
|
|
102
|
+
* 表示:(匹配查询条件 AND 结果包含) OR (不匹配查询条件)
|
|
103
|
+
*/
|
|
104
|
+
export type RefreshMatchRules = RefreshMatchRuleName[][];
|
|
105
|
+
export {};
|
|
106
|
+
//# sourceMappingURL=QueryManager.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryManager.interface.d.ts","sourceRoot":"","sources":["../../src/repository/QueryManager.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EACL,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,WAAW,EACZ,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAMjE;;;GAGG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,UAAU;IAC5C,IAAI,EAAE,KAAK,CAAC;IACZ,OAAO,EAAE,gBAAgB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;CACxC;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,UAAU;IAChD,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,UAAU;IACtD,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAC;CAClC;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,UAAU;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY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CAAC,GACpB,UAAU,CAAC,CAAC,CAAC,GAEb,mBAAmB,CAAC,CAAC,CAAC,GACtB,qBAAqB,CAAC,CAAC,CAAC,GACxB,kBAAkB,CAAC,CAAC,CAAC,GACrB,oBAAoB,CAAC,CAAC,CAAC,CAAC;AAM5B;;;GAGG;AACH,KAAK,oBAAoB,GACrB,aAAa,GACb,gBAAgB,GAChB,sBAAsB,GACtB,0BAA0B,GAC1B,iBAAiB,GACjB,iBAAiB,GACjB,qBAAqB,GACrB,oBAAoB,GACpB,wBAAwB,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,EAAE,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Observable, Observer } from 'rxjs';
|
|
2
|
+
import { EntityStaticType, EntityType } from '../entity/entity.interface.js';
|
|
3
|
+
import { RxDBEntityLocalEventData } from '../rxdb-events.js';
|
|
4
|
+
import { RxDB } from '../RxDB.js';
|
|
5
|
+
import { QueryOptions } from './QueryManager.interface.js';
|
|
6
|
+
/**
|
|
7
|
+
* 查询任务选项接口
|
|
8
|
+
*/
|
|
9
|
+
export interface QueryTaskOptions<T extends EntityType> {
|
|
10
|
+
/**
|
|
11
|
+
* 缓存键
|
|
12
|
+
*/
|
|
13
|
+
cacheKey: string;
|
|
14
|
+
/**
|
|
15
|
+
* 查询选项
|
|
16
|
+
*/
|
|
17
|
+
options: QueryOptions<T>;
|
|
18
|
+
/**
|
|
19
|
+
* 查询执行函数
|
|
20
|
+
*/
|
|
21
|
+
runner: () => Observable<any>;
|
|
22
|
+
/**
|
|
23
|
+
* 实体类型
|
|
24
|
+
*/
|
|
25
|
+
entityType: T;
|
|
26
|
+
/**
|
|
27
|
+
* RxDB 实例
|
|
28
|
+
*/
|
|
29
|
+
rxdb: RxDB;
|
|
30
|
+
/**
|
|
31
|
+
* 依赖的实体类型映射
|
|
32
|
+
*/
|
|
33
|
+
depEntityTypeMap: Map<T, number>;
|
|
34
|
+
/**
|
|
35
|
+
* 序列化函数
|
|
36
|
+
*/
|
|
37
|
+
serialize: (data: RxDBEntityLocalEventData<T>) => InstanceType<T>;
|
|
38
|
+
/**
|
|
39
|
+
* 清理函数
|
|
40
|
+
*/
|
|
41
|
+
onClean: (cacheKey: string) => void;
|
|
42
|
+
/**
|
|
43
|
+
* 结果指纹计算方法
|
|
44
|
+
*/
|
|
45
|
+
getFingerprint: (result: any) => any[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 查询任务实现
|
|
49
|
+
*
|
|
50
|
+
* 封装查询任务的创建和生命周期管理
|
|
51
|
+
* - 管理任务的刷新和销毁信号
|
|
52
|
+
* - 处理观察者的订阅和取消订阅
|
|
53
|
+
* - 维护实体类型依赖关系
|
|
54
|
+
* - 提供任务的首次运行和清理机制
|
|
55
|
+
*/
|
|
56
|
+
export declare class QueryTask<T extends EntityType, RT = any> {
|
|
57
|
+
#private;
|
|
58
|
+
private readonly runner;
|
|
59
|
+
private readonly onClean;
|
|
60
|
+
/**
|
|
61
|
+
* 观察者集合
|
|
62
|
+
* 存储所有订阅此查询结果的观察者
|
|
63
|
+
*/
|
|
64
|
+
readonly observers: Set<Observer<any>>;
|
|
65
|
+
readonly serialize: (data: RxDBEntityLocalEventData<T>) => InstanceType<T>;
|
|
66
|
+
readonly cacheKey: string;
|
|
67
|
+
readonly entityType: T;
|
|
68
|
+
readonly rxdb: RxDB;
|
|
69
|
+
readonly depEntityTypeMap: Map<T, number>;
|
|
70
|
+
/**
|
|
71
|
+
* 刷新触发流
|
|
72
|
+
* 每次刷新时发送刷新次数,用于触发查询重新执行
|
|
73
|
+
*/
|
|
74
|
+
readonly refresh$: Observable<number>;
|
|
75
|
+
/**
|
|
76
|
+
* 查询销毁流
|
|
77
|
+
* 当查询任务被销毁时触发
|
|
78
|
+
*/
|
|
79
|
+
readonly destroy$: Observable<void>;
|
|
80
|
+
/**
|
|
81
|
+
* 关联实体类型集合
|
|
82
|
+
* 存储查询中涉及到的所有关联实体类型
|
|
83
|
+
*/
|
|
84
|
+
readonly relationEntityTypes: Set<T>;
|
|
85
|
+
/**
|
|
86
|
+
* 查询的实体 ID 集合
|
|
87
|
+
*/
|
|
88
|
+
readonly resultEntityIds: Set<EntityStaticType<T, "idType">>;
|
|
89
|
+
/**
|
|
90
|
+
* 查询的实体集合
|
|
91
|
+
* 存储查询结果中包含的所有实体实例
|
|
92
|
+
*/
|
|
93
|
+
readonly resultEntitySet: Set<InstanceType<T>>;
|
|
94
|
+
/**
|
|
95
|
+
* 查询类型
|
|
96
|
+
*/
|
|
97
|
+
readonly type: 'get' | 'findOne' | 'findOneOrFail' | 'find' | 'findAll' | 'findByCursor' | 'count' | 'findDescendants' | 'findAncestors' | 'countDescendants' | 'countAncestors' | 'findNeighbors' | 'countNeighbors' | 'findPaths';
|
|
98
|
+
/**
|
|
99
|
+
* 查询选项
|
|
100
|
+
*/
|
|
101
|
+
readonly options: QueryOptions<T>['options'];
|
|
102
|
+
/**
|
|
103
|
+
* 观察者数量
|
|
104
|
+
* 记录当前有多少个订阅者正在监听此查询结果
|
|
105
|
+
*/
|
|
106
|
+
observerCount: number;
|
|
107
|
+
/**
|
|
108
|
+
* 刷新次数
|
|
109
|
+
* 记录查询被刷新执行的总次数
|
|
110
|
+
*/
|
|
111
|
+
refreshCount: number;
|
|
112
|
+
/**
|
|
113
|
+
* 查询结果
|
|
114
|
+
* 缓存的最新查询结果数据
|
|
115
|
+
*/
|
|
116
|
+
result?: RT;
|
|
117
|
+
/**
|
|
118
|
+
* 结果指纹计算方法
|
|
119
|
+
*/
|
|
120
|
+
getFingerprint: (result: any) => (string | number)[];
|
|
121
|
+
/**
|
|
122
|
+
* 查询结果流
|
|
123
|
+
* 通过 Observable 发送查询结果的响应式流
|
|
124
|
+
*/
|
|
125
|
+
result$: Observable<RT>;
|
|
126
|
+
constructor(opt: QueryTaskOptions<T>);
|
|
127
|
+
/**
|
|
128
|
+
* 清理任务资源
|
|
129
|
+
*/
|
|
130
|
+
clean: () => void;
|
|
131
|
+
/**
|
|
132
|
+
* 首次运行查询任务
|
|
133
|
+
*/
|
|
134
|
+
run: () => void;
|
|
135
|
+
/**
|
|
136
|
+
* 发送结果给所有观察者
|
|
137
|
+
* @param result 查询结果
|
|
138
|
+
* @param autoCache 是否自动缓存结果实体
|
|
139
|
+
*/
|
|
140
|
+
next: (result: any, autoCache?: boolean) => void;
|
|
141
|
+
/**
|
|
142
|
+
* 发送错误给所有观察者
|
|
143
|
+
*/
|
|
144
|
+
error: (err: any) => void;
|
|
145
|
+
/**
|
|
146
|
+
* 手动刷新查询
|
|
147
|
+
*/
|
|
148
|
+
refresh: () => void;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=QueryTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryTask.d.ts","sourceRoot":"","sources":["../../src/repository/QueryTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,QAAQ,EAKT,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAElF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,UAAU;IACpD;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAEzB;;OAEG;IACH,MAAM,EAAE,MAAM,UAAU,CAAC,GAAG,CAAC,CAAC;IAE9B;;OAEG;IACH,UAAU,EAAE,CAAC,CAAC;IAEd;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;IAEX;;OAEG;IACH,gBAAgB,EAAE,GAAG,CA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,GACf,kBAAkB,GAClB,gBAAgB,GAChB,eAAe,GACf,gBAAgB,GAChB,WAAW,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAE7C;;;OAGG;IACH,aAAa,SAAK;IAClB;;;OAGG;IACH,YAAY,SAAK;IACjB;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,CAAC;IAEZ;;OAEG;IACH,cAAc,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAErD;;;OAGG;IACH,OAAO,EAAG,UAAU,CAAC,EAAE,CAAC,CAAC;gBAEb,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAcpC;;OAEG;IACH,KAAK,QAAO,IAAI,CAYd;IAEF;;OAEG;IACH,GAAG,QAAO,IAAI,CAiCZ;IAEF;;;;OAIG;IACH,IAAI,GAAI,QAAQ,GAAG,EAAE,mBAAgB,KAAG,IAAI,CAgC1C;IAEF;;OAEG;IACH,KAAK,GAAI,KAAK,GAAG,KAAG,IAAI,CAEtB;IAEF;;OAEG;IACH,OAAO,QAAO,IAAI,CAEhB;CACH"}
|
|
@@ -1,102 +1,96 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SyncOptions } from '../entity/entity-metadata-options.interface.js';
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
3
2
|
import { EntityStaticType, EntityType } from '../entity/entity.interface.js';
|
|
4
|
-
import {
|
|
3
|
+
import { SyncOptions } from '../entity/metadata-options.interface.js';
|
|
5
4
|
import { RxDB } from '../RxDB.js';
|
|
6
|
-
import { CountOptions, FindAllOptions, FindOneOptions, FindOneOrFailOptions, FindOptions } from './query-options.interface.js';
|
|
5
|
+
import { CountOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions } from './query-options.interface.js';
|
|
6
|
+
import { QueryManager } from './QueryManager.js';
|
|
7
7
|
import { IRepository } from './repository.interface.js';
|
|
8
|
+
import { RepositoryBase } from './RepositoryBase.js';
|
|
8
9
|
/**
|
|
9
10
|
* 实体仓库
|
|
10
11
|
* 根据配置决策实体的具体操作
|
|
11
12
|
*/
|
|
12
|
-
export declare class Repository<T extends EntityType, RT extends IRepository<T> = IRepository<T>>
|
|
13
|
-
protected
|
|
14
|
-
protected EntityType: EntityType;
|
|
13
|
+
export declare class Repository<T extends EntityType, RT extends IRepository<T> = IRepository<T>> extends RepositoryBase<T> {
|
|
14
|
+
protected static _STATIC_METHODS: string[];
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* 本地仓库
|
|
17
17
|
*/
|
|
18
|
-
protected
|
|
19
|
-
protected localAdapter$: Observable<IRxDBAdapter & RxDBAdapterLocalBase>;
|
|
18
|
+
protected readonly local$: Observable<RT>;
|
|
20
19
|
/**
|
|
21
|
-
*
|
|
20
|
+
* 远程仓库
|
|
22
21
|
*/
|
|
23
|
-
protected
|
|
22
|
+
protected readonly remote$: Observable<IRepository<T>>;
|
|
24
23
|
/**
|
|
25
|
-
*
|
|
24
|
+
* 主仓库(根据 SyncOptions 选择 local 或 remote)
|
|
25
|
+
* - SyncType.None + 只有 remote:使用 remote$
|
|
26
|
+
* - 其他情况:使用 local$
|
|
26
27
|
*/
|
|
27
|
-
protected
|
|
28
|
-
protected remoteAdapter$: Observable<IRxDBAdapter & RxDBAdapterRemoteBase>;
|
|
28
|
+
protected readonly primary$: Observable<RT>;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* 查询缓存管理器
|
|
31
31
|
*/
|
|
32
|
-
protected
|
|
32
|
+
protected readonly queryManager: QueryManager<T>;
|
|
33
33
|
/**
|
|
34
34
|
* 同步配置
|
|
35
|
-
* TODO: 待实现同步功能
|
|
36
35
|
*/
|
|
37
|
-
sync: SyncOptions;
|
|
38
|
-
constructor(rxdb: RxDB, EntityType:
|
|
36
|
+
readonly sync: SyncOptions;
|
|
37
|
+
constructor(rxdb: RxDB, EntityType: T);
|
|
39
38
|
/**
|
|
40
39
|
* 根据 id 获取实体
|
|
41
|
-
* @param id
|
|
42
|
-
* @param options
|
|
40
|
+
* @param id 实体的唯一标识符
|
|
43
41
|
*/
|
|
44
42
|
get(id: EntityStaticType<T, 'idType'>): Observable<InstanceType<T>>;
|
|
45
43
|
/**
|
|
46
44
|
* 查找一个实体
|
|
47
|
-
* @param where
|
|
48
|
-
* @param options
|
|
45
|
+
* @param options 查询选项,包含 where 条件
|
|
49
46
|
*/
|
|
50
|
-
findOne(options: FindOneOptions<T>): Observable<InstanceType<T> |
|
|
47
|
+
findOne(options: FindOneOptions<T>): Observable<InstanceType<T> | null>;
|
|
51
48
|
/**
|
|
52
49
|
* 查找一个实体,查不到就抛出错误
|
|
53
|
-
* @param where
|
|
54
|
-
* @param options
|
|
50
|
+
* @param options 查询选项,包含 where 条件
|
|
55
51
|
*/
|
|
56
52
|
findOneOrFail(options: FindOneOrFailOptions<T>): Observable<InstanceType<T>>;
|
|
57
53
|
/**
|
|
58
54
|
* 查询多个实体
|
|
59
|
-
* @param where
|
|
60
|
-
* @param options
|
|
55
|
+
* @param options 查询选项,包含 where 条件、limit、offset 等
|
|
61
56
|
*/
|
|
62
57
|
find(options: FindOptions<T>): Observable<InstanceType<T>[]>;
|
|
63
58
|
/**
|
|
64
59
|
* 查询所有实体
|
|
65
|
-
* @param where
|
|
66
|
-
|
|
60
|
+
* @param options 查询选项,包含 where 条件和排序(不限制数量)
|
|
61
|
+
|
|
67
62
|
*/
|
|
68
63
|
findAll(options: FindAllOptions<T>): Observable<InstanceType<T>[]>;
|
|
69
64
|
/**
|
|
70
|
-
*
|
|
71
|
-
* @param
|
|
72
|
-
* @param options
|
|
65
|
+
* 通过游标进行分页查询
|
|
66
|
+
* @param options 游标分页选项,包含 orderBy、before/after 游标
|
|
73
67
|
*/
|
|
74
|
-
|
|
68
|
+
findByCursor(options: FindByCursorOptions<T>): Observable<InstanceType<T>[]>;
|
|
75
69
|
/**
|
|
76
|
-
*
|
|
77
|
-
* @param
|
|
70
|
+
* 查询实体数量
|
|
71
|
+
* @param options 查询选项,包含 where 条件
|
|
78
72
|
*/
|
|
79
|
-
|
|
73
|
+
count(options: CountOptions<T>): Observable<number>;
|
|
80
74
|
/**
|
|
81
75
|
* 创建实体
|
|
82
|
-
* @param entity
|
|
76
|
+
* @param entity 要创建的实体实例
|
|
83
77
|
*/
|
|
84
78
|
create(entity: InstanceType<T>): Promise<InstanceType<T>>;
|
|
85
79
|
/**
|
|
86
80
|
* 更新实体
|
|
87
|
-
* @param entity
|
|
88
|
-
* @param patch
|
|
81
|
+
* @param entity 要更新的实体实例
|
|
82
|
+
* @param patch 部分更新数据
|
|
89
83
|
*/
|
|
90
84
|
update(entity: InstanceType<T>, patch: Partial<InstanceType<T>>): Promise<InstanceType<T>>;
|
|
91
85
|
/**
|
|
92
86
|
* 删除实体
|
|
93
|
-
* @param entity
|
|
87
|
+
* @param entity 要删除的实体实例
|
|
94
88
|
*/
|
|
95
89
|
remove(entity: InstanceType<T>): Promise<InstanceType<T>>;
|
|
96
90
|
/**
|
|
97
91
|
* 设置状态 local
|
|
98
92
|
*/
|
|
99
|
-
protected
|
|
100
|
-
protected
|
|
93
|
+
protected _setLocal: (entity: InstanceType<T>) => void;
|
|
94
|
+
protected _setLocals: (entities: InstanceType<T>[]) => void;
|
|
101
95
|
}
|
|
102
96
|
//# sourceMappingURL=Repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Repository.d.ts","sourceRoot":"","sources":["../../src/repository/Repository.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Repository.d.ts","sourceRoot":"","sources":["../../src/repository/Repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,UAAU,EAA+B,MAAM,MAAM,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAA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+1,20 @@
|
|
|
1
|
-
import { EntityStaticType, EntityType } from '../entity/entity.interface.js';
|
|
1
|
+
import { EntityStaticType, EntityType, EntityUpdateData, IEntity } from '../entity/entity.interface.js';
|
|
2
2
|
import { RxDB } from '../RxDB.js';
|
|
3
3
|
/**
|
|
4
4
|
* 数据仓库
|
|
5
5
|
* 用来协调数据存取
|
|
6
6
|
*/
|
|
7
|
-
export declare abstract class RepositoryBase<T extends EntityType> {
|
|
7
|
+
export declare abstract class RepositoryBase<T extends EntityType & (new (...args: any[]) => IEntity)> {
|
|
8
8
|
protected readonly rxdb: RxDB;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
readonly EntityType: T;
|
|
10
|
+
protected static _STATIC_METHODS: string[];
|
|
11
|
+
static get staticMethods(): string[];
|
|
12
|
+
constructor(rxdb: RxDB, EntityType: T);
|
|
11
13
|
/**
|
|
12
14
|
* 获取实体实例
|
|
13
15
|
* @param data 实体数据
|
|
14
16
|
*/
|
|
15
|
-
createEntityRef(data:
|
|
16
|
-
id: EntityStaticType<T, 'idType'>;
|
|
17
|
-
}): any;
|
|
17
|
+
createEntityRef(data: EntityUpdateData<T>): any;
|
|
18
18
|
/**
|
|
19
19
|
* 获取实体实例
|
|
20
20
|
* @param id 实体的 ID
|
|
@@ -28,6 +28,6 @@ export declare abstract class RepositoryBase<T extends EntityType> {
|
|
|
28
28
|
/**
|
|
29
29
|
* 更新实体
|
|
30
30
|
*/
|
|
31
|
-
updateEntity(entity: InstanceType<T>,
|
|
31
|
+
updateEntity(entity: InstanceType<T>, update: InstanceType<T>): void;
|
|
32
32
|
}
|
|
33
33
|
//# sourceMappingURL=RepositoryBase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RepositoryBase.d.ts","sourceRoot":"","sources":["../../src/repository/RepositoryBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"RepositoryBase.d.ts","sourceRoot":"","sources":["../../src/repository/RepositoryBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAExG,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC;;;GAGG;AACH,8BAAsB,cAAc,CAAC,CAAC,SAAS,UAAU,GAAG,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC;IAQzF,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI;aACb,UAAU,EAAE,CAAC;IAR/B,SAAS,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,EAAE,CAAM;IAEhD,MAAM,KAAK,aAAa,aAEvB;gBAGoB,IAAI,EAAE,IAAI,EACb,UAAU,EAAE,CAAC;IAG/B;;;OAGG;IACH,eAAe,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAIzC;;;OAGG;IACH,YAAY,CAAC,EAAE,EAAE,gBAAgB,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS;IAI5E;;;OAGG;IACH,YAAY,CAAC,EAAE,EAAE,gBAAgB,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,OAAO;IAIxD;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;CAK9D"}
|
|
@@ -1,14 +1,39 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { EntityType } from '../entity/entity.interface.js';
|
|
3
|
+
import { ITreeEntity } from '../entity/tree-entity.interface.js';
|
|
3
4
|
import { Repository } from './Repository.js';
|
|
4
|
-
import { FindTreeOptions,
|
|
5
|
+
import { FindTreeOptions, ITreeRepository } from './tree-repository.interface.js';
|
|
5
6
|
/**
|
|
6
7
|
* 树结构实体仓库
|
|
7
8
|
* 根据配置决策实体的具体操作
|
|
9
|
+
*
|
|
10
|
+
* @template T - 必须是实现 ITreeEntity 接口的实体类型(通常继承 TreeAdjacencyListEntityBase)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // ✅ 正确:继承 TreeAdjacencyListEntityBase
|
|
15
|
+
* @Entity({ name: 'Category' })
|
|
16
|
+
* class Category extends TreeAdjacencyListEntityBase {
|
|
17
|
+
* name!: string;
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // 可以使用树查询方法
|
|
21
|
+
* Category.findDescendants({ entityId: 'root-id' });
|
|
22
|
+
* Category.findAncestors({ entityId: 'leaf-id' });
|
|
23
|
+
*
|
|
24
|
+
* // ❌ 错误:只继承 EntityBase,没有实现 ITreeEntity
|
|
25
|
+
* @Entity({ name: 'User' })
|
|
26
|
+
* class User extends EntityBase {
|
|
27
|
+
* name!: string;
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* // 编译错误:User 不满足 TreeRepository 的类型约束
|
|
31
|
+
* // User.findDescendants({ entityId: 'id' }); // TypeScript 错误
|
|
32
|
+
* ```
|
|
8
33
|
*/
|
|
9
|
-
export declare class TreeRepository<T extends EntityType, RepositoryType extends ITreeRepository<T> = ITreeRepository<T>> extends Repository<T, RepositoryType>
|
|
10
|
-
|
|
11
|
-
|
|
34
|
+
export declare class TreeRepository<T extends EntityType & (new (...args: any[]) => ITreeEntity), RepositoryType extends ITreeRepository<T> = ITreeRepository<T>> extends Repository<T, RepositoryType> {
|
|
35
|
+
#private;
|
|
36
|
+
protected static _STATIC_METHODS: string[];
|
|
12
37
|
/**
|
|
13
38
|
* 查询子孙
|
|
14
39
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRepository.d.ts","sourceRoot":"","sources":["../../src/repository/TreeRepository.ts"],"names":[],"mappings":"AAAA,OAA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C,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC;CAwBhE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EntityType } from '../entity/entity.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* 指纹类型
|
|
4
|
+
*/
|
|
5
|
+
export type Fingerprint = string | number | boolean | null | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* 值类型指纹计算
|
|
8
|
+
* 用于 count 等返回原始值的查询
|
|
9
|
+
*
|
|
10
|
+
* @param value - 要计算指纹的值
|
|
11
|
+
* @returns 指纹数组
|
|
12
|
+
*/
|
|
13
|
+
export declare const getFingerprintPrimitive: <T extends Fingerprint>(value: T | T[]) => Fingerprint[];
|
|
14
|
+
/**
|
|
15
|
+
* 单个实体指纹计算
|
|
16
|
+
*
|
|
17
|
+
* @param entity - 要计算指纹的实体
|
|
18
|
+
* @returns 指纹数组
|
|
19
|
+
*/
|
|
20
|
+
export declare const getFingerprintByEntity: <T extends EntityType>(entity: InstanceType<T> | null | undefined) => Fingerprint[];
|
|
21
|
+
/**
|
|
22
|
+
* 多个实体指纹计算
|
|
23
|
+
*
|
|
24
|
+
* @param entities - 要计算指纹的实体数组
|
|
25
|
+
* @returns 指纹数组
|
|
26
|
+
*/
|
|
27
|
+
export declare const getFingerprintByEntities: <T extends EntityType>(entities: InstanceType<T>[]) => Fingerprint[];
|
|
28
|
+
//# sourceMappingURL=fingerprint.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint.utils.d.ts","sourceRoot":"","sources":["../../src/repository/fingerprint.utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAG3D;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAEvE;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAS,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,KAAG,WAAW,EACnD,CAAC;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,UAAU,EACzD,QAAQ,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,KACzC,WAAW,EAIb,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,UAAU,EAAE,UAAU,YAAY,CAAC,CAAC,CAAC,EAAE,KAAG,WAAW,EAIpG,CAAC"}
|