@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/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aiao/rxdb",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"uuid": "^11.1.0",
|
|
8
|
+
"type-fest": "^4.41.0",
|
|
9
|
+
"@aiao/utils": "0.0.1",
|
|
10
|
+
"rxjs": "~7.8.0"
|
|
11
|
+
},
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./index.js",
|
|
14
|
+
"types": "./index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { BehaviorSubject, Observable } from 'rxjs';
|
|
2
|
+
import { SyncOptions } from '../entity/entity-metadata-options.interface';
|
|
3
|
+
import { EntityType } from '../entity/entity.interface';
|
|
4
|
+
import { RxDB } from '../RxDB';
|
|
5
|
+
import { IRxDBAdapter, RxDBAdapterLocalBase, RxDBAdapterRemoteBase } from '../rxdb-adapter';
|
|
6
|
+
import { CountOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetOptions } from './query-options.interface';
|
|
7
|
+
import { RuleGroup } from './query.interface';
|
|
8
|
+
import { IRepository } from './repository.interface';
|
|
9
|
+
/**
|
|
10
|
+
* 实体仓库
|
|
11
|
+
* 根据配置决策实体的具体操作
|
|
12
|
+
*/
|
|
13
|
+
export declare class Repository<T extends EntityType, RT extends IRepository<T> = IRepository<T>> implements IRepository<T> {
|
|
14
|
+
protected rxdb: RxDB;
|
|
15
|
+
protected EntityType: EntityType;
|
|
16
|
+
/**
|
|
17
|
+
* 本地适配器
|
|
18
|
+
*/
|
|
19
|
+
protected localAdapterSub: BehaviorSubject<string>;
|
|
20
|
+
protected localAdapter$: Observable<IRxDBAdapter & RxDBAdapterLocalBase>;
|
|
21
|
+
/**
|
|
22
|
+
* 本地仓库
|
|
23
|
+
*/
|
|
24
|
+
protected local$: Observable<RT>;
|
|
25
|
+
/**
|
|
26
|
+
* 远程适配器
|
|
27
|
+
*/
|
|
28
|
+
protected remoteAdapterSub: BehaviorSubject<string>;
|
|
29
|
+
protected remoteAdapter$: Observable<IRxDBAdapter & RxDBAdapterRemoteBase>;
|
|
30
|
+
/**
|
|
31
|
+
* 远程仓库
|
|
32
|
+
*/
|
|
33
|
+
protected remote$: Observable<IRepository<EntityType>>;
|
|
34
|
+
/**
|
|
35
|
+
* 同步配置
|
|
36
|
+
* TODO: 待实现同步功能
|
|
37
|
+
*/
|
|
38
|
+
sync: SyncOptions;
|
|
39
|
+
constructor(rxdb: RxDB, EntityType: EntityType);
|
|
40
|
+
/**
|
|
41
|
+
* 根据 id 获取实体
|
|
42
|
+
* @param id
|
|
43
|
+
* @param options
|
|
44
|
+
*/
|
|
45
|
+
get(id: string, options?: GetOptions): Observable<InstanceType<T>>;
|
|
46
|
+
/**
|
|
47
|
+
* 查找一个实体
|
|
48
|
+
* @param where
|
|
49
|
+
* @param options
|
|
50
|
+
*/
|
|
51
|
+
findOne(where: RuleGroup<InstanceType<T>>, options?: FindOneOptions): Observable<InstanceType<T> | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* 查找一个实体,查不到就抛出错误
|
|
54
|
+
* @param where
|
|
55
|
+
* @param options
|
|
56
|
+
*/
|
|
57
|
+
findOneOrFail(where: RuleGroup<InstanceType<T>>, options?: FindOneOrFailOptions): Observable<InstanceType<T>>;
|
|
58
|
+
/**
|
|
59
|
+
* 查询多个实体
|
|
60
|
+
* @param where
|
|
61
|
+
* @param options
|
|
62
|
+
*/
|
|
63
|
+
find(where: RuleGroup<InstanceType<T>>, options?: FindOptions): Observable<InstanceType<T>[]>;
|
|
64
|
+
/**
|
|
65
|
+
* 查询所有实体
|
|
66
|
+
* @param where
|
|
67
|
+
* @param options
|
|
68
|
+
*/
|
|
69
|
+
findAll(where: RuleGroup<InstanceType<T>>, options?: FindAllOptions): Observable<InstanceType<T>[]>;
|
|
70
|
+
/**
|
|
71
|
+
* 通过指针查询实体
|
|
72
|
+
* @param where
|
|
73
|
+
* @param options
|
|
74
|
+
*/
|
|
75
|
+
findByCursor(where: RuleGroup<InstanceType<T>>, options?: FindByCursorOptions): Observable<InstanceType<T>[]>;
|
|
76
|
+
/**
|
|
77
|
+
* 查询实体数量
|
|
78
|
+
* @param where
|
|
79
|
+
* @param options
|
|
80
|
+
*/
|
|
81
|
+
count(where: RuleGroup<InstanceType<T>>, options?: CountOptions): Observable<number>;
|
|
82
|
+
/**
|
|
83
|
+
* 事务保存
|
|
84
|
+
* @param entities 需要保存的实体
|
|
85
|
+
*/
|
|
86
|
+
transactionSave(entities: InstanceType<T>[]): Promise<any>;
|
|
87
|
+
/**
|
|
88
|
+
* 创建实体
|
|
89
|
+
* @param entity
|
|
90
|
+
*/
|
|
91
|
+
create(entity: InstanceType<T>): Promise<InstanceType<T>>;
|
|
92
|
+
/**
|
|
93
|
+
* 更新实体
|
|
94
|
+
* @param entity
|
|
95
|
+
* @param patch
|
|
96
|
+
*/
|
|
97
|
+
update(entity: InstanceType<T>, patch: Partial<InstanceType<T>>): Promise<InstanceType<T>>;
|
|
98
|
+
/**
|
|
99
|
+
* 删除实体
|
|
100
|
+
* @param entity
|
|
101
|
+
*/
|
|
102
|
+
remove(entity: InstanceType<T>): Promise<InstanceType<T>>;
|
|
103
|
+
/**
|
|
104
|
+
* 设置状态 local
|
|
105
|
+
*/
|
|
106
|
+
protected _setLocalEntityStatus: (entity: InstanceType<T>) => boolean;
|
|
107
|
+
protected _setLocalEntitiesStatus: (entities: InstanceType<T>[]) => void;
|
|
108
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { EntityType, UUID } from '../entity/entity.interface';
|
|
2
|
+
import { RxDB } from '../RxDB';
|
|
3
|
+
/**
|
|
4
|
+
* 数据仓库
|
|
5
|
+
* 用来协调数据存取
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class RepositoryBase<T extends EntityType> {
|
|
8
|
+
protected readonly rxdb: RxDB;
|
|
9
|
+
protected readonly EntityClass: T;
|
|
10
|
+
constructor(rxdb: RxDB, EntityClass: T);
|
|
11
|
+
/**
|
|
12
|
+
* 获取实体实例
|
|
13
|
+
* @param data 实体数据
|
|
14
|
+
*/
|
|
15
|
+
createEntityRef(data: Partial<InstanceType<T>> & {
|
|
16
|
+
id: UUID;
|
|
17
|
+
}): any;
|
|
18
|
+
/**
|
|
19
|
+
* 获取实体实例
|
|
20
|
+
* @param id 实体的 ID
|
|
21
|
+
*/
|
|
22
|
+
getEntityRef(id: UUID): InstanceType<T> | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* 获取实体实例
|
|
25
|
+
* @param id 实体的 ID
|
|
26
|
+
*/
|
|
27
|
+
hasEntityRef(id: UUID): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* 更新实体
|
|
30
|
+
*/
|
|
31
|
+
updateEntity(entity: InstanceType<T>, newValue: Partial<InstanceType<T>>): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { EntityType } from '../entity/entity.interface';
|
|
3
|
+
import { RuleGroup } from './query.interface';
|
|
4
|
+
import { Repository } from './Repository';
|
|
5
|
+
import { FindTreeOptions } from './tree-query-options.interface';
|
|
6
|
+
import { ITreeRepository } from './tree-repository.interface';
|
|
7
|
+
/**
|
|
8
|
+
* 树结构实体仓库
|
|
9
|
+
* 根据配置决策实体的具体操作
|
|
10
|
+
*/
|
|
11
|
+
export declare class TreeRepository<T extends EntityType, RepositoryType extends ITreeRepository<T> = ITreeRepository<T>> extends Repository<T, RepositoryType> implements ITreeRepository<T> {
|
|
12
|
+
/**
|
|
13
|
+
* 查询子孙
|
|
14
|
+
*/
|
|
15
|
+
findDescendants(entity: InstanceType<T>, where: RuleGroup<InstanceType<T>>, options: FindTreeOptions): Observable<InstanceType<T>[]>;
|
|
16
|
+
/**
|
|
17
|
+
* 查询子孙数量
|
|
18
|
+
*/
|
|
19
|
+
countDescendants(entity: InstanceType<T>, where: RuleGroup<InstanceType<T>>, options: FindTreeOptions): Observable<number>;
|
|
20
|
+
/**
|
|
21
|
+
* 查询祖先
|
|
22
|
+
*/
|
|
23
|
+
findAncestors(entity: InstanceType<T>, where: RuleGroup<InstanceType<T>>, options: FindTreeOptions): Observable<InstanceType<T>[]>;
|
|
24
|
+
/**
|
|
25
|
+
* 查询祖先数量
|
|
26
|
+
*/
|
|
27
|
+
countAncestors(entity: InstanceType<T>, where: RuleGroup<InstanceType<T>>, options: FindTreeOptions): Observable<number>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 排序
|
|
3
|
+
*/
|
|
4
|
+
export interface OrderBy<FieldType extends string = string> {
|
|
5
|
+
field: FieldType;
|
|
6
|
+
order: 'asc' | 'desc';
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Get 查询选项
|
|
10
|
+
*/
|
|
11
|
+
export type GetOptions = object;
|
|
12
|
+
/**
|
|
13
|
+
* FindOne 查询选项
|
|
14
|
+
*/
|
|
15
|
+
export interface FindOneOptions<OrderByFieldType extends string = string> {
|
|
16
|
+
orderBy?: OrderBy<OrderByFieldType>[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* FindOneOrFail 查询选项
|
|
20
|
+
*/
|
|
21
|
+
export interface FindOneOrFailOptions<OrderByFieldType extends string = string> {
|
|
22
|
+
orderBy?: OrderBy<OrderByFieldType>[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Find 查询选项
|
|
26
|
+
*/
|
|
27
|
+
export interface FindOptions<OrderByFieldType extends string = string> {
|
|
28
|
+
orderBy?: OrderBy<OrderByFieldType>[];
|
|
29
|
+
limit?: number;
|
|
30
|
+
offset?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* FindAll 查询选项
|
|
34
|
+
*/
|
|
35
|
+
export interface FindAllOptions<OrderByFieldType extends string = string> {
|
|
36
|
+
orderBy?: OrderBy<OrderByFieldType>[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* FindByCursor 查询选项
|
|
40
|
+
*/
|
|
41
|
+
export interface FindByCursorOptions<OrderByFieldType extends string = string> {
|
|
42
|
+
orderBy?: OrderBy<OrderByFieldType>[];
|
|
43
|
+
before?: string;
|
|
44
|
+
after?: string;
|
|
45
|
+
first?: number;
|
|
46
|
+
last?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Count 查询选项
|
|
50
|
+
*/
|
|
51
|
+
export interface CountOptions {
|
|
52
|
+
groupBy?: string[];
|
|
53
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { SetNonNullable } from 'type-fest';
|
|
2
|
+
import { UUID } from '../entity/entity.interface';
|
|
3
|
+
/**
|
|
4
|
+
* 判断相等
|
|
5
|
+
*/
|
|
6
|
+
interface RuleEqualNullable<T, K extends keyof T = keyof T, VT = T[K]> {
|
|
7
|
+
field: K;
|
|
8
|
+
operator: '=' | '!=';
|
|
9
|
+
value: VT;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 字符串比较
|
|
13
|
+
*/
|
|
14
|
+
interface RuleStringNonNullable<T, K extends keyof T = keyof T, VT = T[K]> {
|
|
15
|
+
field: K;
|
|
16
|
+
operator: '<' | '>' | '<=' | '>=' | 'contains' | 'notContain' | 'beginWith' | 'notBeginWith' | 'endWith' | 'notEndWith';
|
|
17
|
+
value: SetNonNullable<VT>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 数值比较
|
|
21
|
+
*/
|
|
22
|
+
interface RuleNumberNonNullable<T, K extends keyof T = keyof T, VT = T[K]> {
|
|
23
|
+
field: K;
|
|
24
|
+
operator: '<' | '>' | '<=' | '>=';
|
|
25
|
+
value: SetNonNullable<VT>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* in
|
|
29
|
+
*/
|
|
30
|
+
interface RuleIn<T, K extends keyof T = keyof T, VT = T[K]> {
|
|
31
|
+
field: K;
|
|
32
|
+
operator: 'in' | 'notIn';
|
|
33
|
+
value: SetNonNullable<VT>[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* between
|
|
37
|
+
*/
|
|
38
|
+
interface RuleBetween<T, K extends keyof T = keyof T, VT = T[K]> {
|
|
39
|
+
field: K;
|
|
40
|
+
operator: 'between' | 'notBetween';
|
|
41
|
+
value: [SetNonNullable<VT>, SetNonNullable<VT>];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* UUID
|
|
45
|
+
*/
|
|
46
|
+
export type UUIDRules<T, K extends keyof T = keyof T, VT = T[K]> = RuleEqualNullable<T, K> | RuleIn<T, K, VT>;
|
|
47
|
+
/**
|
|
48
|
+
* string
|
|
49
|
+
*/
|
|
50
|
+
export type StringRules<T, K extends keyof T = keyof T, VT = T[K]> = RuleEqualNullable<T, K, VT> | RuleStringNonNullable<T, K, VT> | RuleIn<T, K, VT> | RuleBetween<T, K, VT>;
|
|
51
|
+
/**
|
|
52
|
+
* number
|
|
53
|
+
*/
|
|
54
|
+
export type NumberRules<T, K extends keyof T = keyof T, VT = T[K]> = RuleEqualNullable<T, K, VT> | RuleNumberNonNullable<T, K, VT> | RuleIn<T, K, VT> | RuleBetween<T, K, VT>;
|
|
55
|
+
/**
|
|
56
|
+
* Boolean
|
|
57
|
+
*/
|
|
58
|
+
export type BooleanRules<T, K extends keyof T = keyof T, VT = T[K]> = RuleEqualNullable<T, K, VT>;
|
|
59
|
+
/**
|
|
60
|
+
* Date
|
|
61
|
+
*/
|
|
62
|
+
export type DateRules<T, K extends keyof T = keyof T, VT = T[K]> = RuleEqualNullable<T, K, VT> | RuleNumberNonNullable<T, K, VT> | RuleIn<T, K, VT> | RuleBetween<T, K, VT>;
|
|
63
|
+
export type OneToOneRules<T, K extends keyof T = keyof T> = RuleEqualNullable<T, K, UUID> | RuleIn<T, K, UUID>;
|
|
64
|
+
export type ManyToOneRules<T, K extends keyof T = keyof T> = RuleEqualNullable<T, K, UUID> | RuleIn<T, K, UUID>;
|
|
65
|
+
export type OneToManyRules<T, K extends keyof T = keyof T> = RuleIn<T, K, UUID>;
|
|
66
|
+
export type ManyToManyRules<T, K extends keyof T = keyof T> = RuleIn<T, K, UUID>;
|
|
67
|
+
/**
|
|
68
|
+
* 查询规则
|
|
69
|
+
*/
|
|
70
|
+
export type Rule<T = any, K extends keyof T = keyof T, VT = T[K]> = RuleEqualNullable<T, K, VT> | RuleStringNonNullable<T, K, VT> | RuleIn<T, K, VT> | RuleBetween<T, K, VT>;
|
|
71
|
+
/**
|
|
72
|
+
* 查询规则组
|
|
73
|
+
*/
|
|
74
|
+
export interface RuleGroup<T = any, K extends keyof T = keyof T, RT = Rule<T, K, T[K]>> {
|
|
75
|
+
combinator: 'and' | 'or';
|
|
76
|
+
rules: Array<RuleGroup<T, K, RT> | RT>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 所有操作符
|
|
80
|
+
*/
|
|
81
|
+
export type OperatorName = '=' | '!=' | '<' | '>' | '<=' | '>=' | 'contains' | 'notContain' | 'beginWith' | 'notBeginWith' | 'endWith' | 'notEndWith' | 'null' | 'notNull' | 'in' | 'notIn' | 'between' | 'notBetween';
|
|
82
|
+
/**
|
|
83
|
+
* 操作类型
|
|
84
|
+
*/
|
|
85
|
+
export type MutationType = 'create' | 'update' | 'remove';
|
|
86
|
+
/**
|
|
87
|
+
* 查询上下文
|
|
88
|
+
*/
|
|
89
|
+
export interface IQueryContext {
|
|
90
|
+
userId?: string;
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EntityType } from '../entity/entity.interface';
|
|
2
|
+
import { OrderBy } from './query-options.interface';
|
|
3
|
+
import { RuleGroup } from './query.interface';
|
|
4
|
+
/**
|
|
5
|
+
* 判断是否是 RuleGroup
|
|
6
|
+
*/
|
|
7
|
+
export declare const isRuleGroup: (value: unknown) => value is RuleGroup<any>;
|
|
8
|
+
/**
|
|
9
|
+
* 判断实体是否匹配规则组
|
|
10
|
+
*/
|
|
11
|
+
export declare const isEntityMatchRuleGroup: <T extends EntityType>(entity: T, ruleGroup: RuleGroup<T>) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* 判断 entity 是否在排序后的结果中
|
|
14
|
+
* @param entities 排序后的结果
|
|
15
|
+
* @param entity 需要判断的实体
|
|
16
|
+
* @param orderByArray 排序数组
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare const isEntityEffectOrderBy: <T extends EntityType>(entities: T[], entity: T, orderByArray: OrderBy<string>[]) => boolean | undefined;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { EntityType } from '../entity/entity.interface';
|
|
3
|
+
import { CountOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetOptions } from './query-options.interface';
|
|
4
|
+
import { RuleGroup } from './query.interface';
|
|
5
|
+
/**
|
|
6
|
+
* 数据仓库管理接口
|
|
7
|
+
*/
|
|
8
|
+
export interface IRepository<T extends EntityType> {
|
|
9
|
+
/**
|
|
10
|
+
* 根据 id 获取实体
|
|
11
|
+
* @param id
|
|
12
|
+
* @param options
|
|
13
|
+
*/
|
|
14
|
+
get(id: string, options?: GetOptions): Observable<InstanceType<T>>;
|
|
15
|
+
/**
|
|
16
|
+
* 查找一个实体
|
|
17
|
+
* @param where
|
|
18
|
+
* @param options
|
|
19
|
+
*/
|
|
20
|
+
findOne(where: RuleGroup<InstanceType<T>>, options?: FindOneOptions): Observable<InstanceType<T> | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* 查找一个实体,查不到就抛出错误
|
|
23
|
+
* @param where
|
|
24
|
+
* @param options
|
|
25
|
+
*/
|
|
26
|
+
findOneOrFail(where: RuleGroup<InstanceType<T>>, options?: FindOneOrFailOptions): Observable<InstanceType<T>>;
|
|
27
|
+
/**
|
|
28
|
+
* 查询多个实体
|
|
29
|
+
* @param where
|
|
30
|
+
* @param options
|
|
31
|
+
*/
|
|
32
|
+
find(where: RuleGroup<InstanceType<T>>, options?: FindOptions): Observable<InstanceType<T>[]>;
|
|
33
|
+
/**
|
|
34
|
+
* 查询所有实体
|
|
35
|
+
* @param where
|
|
36
|
+
* @param options
|
|
37
|
+
*/
|
|
38
|
+
findAll(where: RuleGroup<InstanceType<T>>, options?: FindAllOptions): Observable<InstanceType<T>[]>;
|
|
39
|
+
/**
|
|
40
|
+
* 通过指针查询实体
|
|
41
|
+
* @param where
|
|
42
|
+
* @param options
|
|
43
|
+
*/
|
|
44
|
+
findByCursor(where: RuleGroup<InstanceType<T>>, options?: FindByCursorOptions): Observable<InstanceType<T>[]>;
|
|
45
|
+
/**
|
|
46
|
+
* 查询实体数量
|
|
47
|
+
* @param where
|
|
48
|
+
* @param options
|
|
49
|
+
*/
|
|
50
|
+
count(where: RuleGroup<InstanceType<T>>, options?: CountOptions): Observable<number>;
|
|
51
|
+
/**
|
|
52
|
+
* 创建实体
|
|
53
|
+
* @param entity
|
|
54
|
+
*/
|
|
55
|
+
create(entity: InstanceType<T>): Promise<InstanceType<T>>;
|
|
56
|
+
/**
|
|
57
|
+
* 更新实体
|
|
58
|
+
* @param entity
|
|
59
|
+
* @param patch
|
|
60
|
+
*/
|
|
61
|
+
update(entity: InstanceType<T>, patch: Partial<InstanceType<T>>): Promise<InstanceType<T>>;
|
|
62
|
+
/**
|
|
63
|
+
* 删除实体
|
|
64
|
+
* @param entity
|
|
65
|
+
*/
|
|
66
|
+
remove(entity: InstanceType<T>): Promise<InstanceType<T>>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 同步状态
|
|
70
|
+
*/
|
|
71
|
+
export declare enum SyncStatus {
|
|
72
|
+
/**
|
|
73
|
+
* 已同步
|
|
74
|
+
*/
|
|
75
|
+
Synced = "Synced",
|
|
76
|
+
/**
|
|
77
|
+
* 同步中
|
|
78
|
+
*/
|
|
79
|
+
Syncing = "Syncing",
|
|
80
|
+
/**
|
|
81
|
+
* 从未同步
|
|
82
|
+
*/
|
|
83
|
+
Never = "Never"
|
|
84
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { EntityType } from '../entity/entity.interface';
|
|
3
|
+
import { RuleGroup } from './query.interface';
|
|
4
|
+
import { IRepository } from './repository.interface';
|
|
5
|
+
import { FindTreeOptions } from './tree-query-options.interface';
|
|
6
|
+
/**
|
|
7
|
+
* 树结构仓库接口
|
|
8
|
+
*/
|
|
9
|
+
export interface ITreeRepository<T extends EntityType> extends IRepository<T> {
|
|
10
|
+
/**
|
|
11
|
+
* 查询子孙实体
|
|
12
|
+
*/
|
|
13
|
+
findDescendants(entity: InstanceType<T>, where: RuleGroup<InstanceType<T>>, options?: FindTreeOptions): Observable<InstanceType<T>[]>;
|
|
14
|
+
/**
|
|
15
|
+
* 查询子孙实体数量
|
|
16
|
+
*/
|
|
17
|
+
countDescendants(entity: InstanceType<T>, where: RuleGroup<InstanceType<T>>, options?: FindTreeOptions): Observable<number>;
|
|
18
|
+
/**
|
|
19
|
+
* 查询祖先节点
|
|
20
|
+
*/
|
|
21
|
+
findAncestors(entity: InstanceType<T>, where: RuleGroup<InstanceType<T>>, options?: FindTreeOptions): Observable<InstanceType<T>[]>;
|
|
22
|
+
/**
|
|
23
|
+
* 查询祖先节点数量
|
|
24
|
+
*/
|
|
25
|
+
countAncestors(entity: InstanceType<T>, where: RuleGroup<InstanceType<T>>, options?: FindTreeOptions): Observable<number>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { EntityType } from './entity/entity.interface';
|
|
3
|
+
import { IRepository } from './repository/repository.interface';
|
|
4
|
+
import { RxDB } from './RxDB';
|
|
5
|
+
/**
|
|
6
|
+
* 事务回调函数
|
|
7
|
+
*/
|
|
8
|
+
export type TransactionFun = () => Promise<any>;
|
|
9
|
+
/**
|
|
10
|
+
* RxDB 数据库适配器接口
|
|
11
|
+
*/
|
|
12
|
+
export interface IRxDBAdapter {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
/**
|
|
15
|
+
* 连接数据库
|
|
16
|
+
*/
|
|
17
|
+
connect(): Observable<IRxDBAdapter>;
|
|
18
|
+
/**
|
|
19
|
+
* 取消连接
|
|
20
|
+
*/
|
|
21
|
+
disconnect(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* 获取数据库版本
|
|
24
|
+
*/
|
|
25
|
+
version(): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* 获取仓库
|
|
28
|
+
*/
|
|
29
|
+
getRepository<T extends EntityType, RT extends IRepository<T>>(EntityType: EntityType): RT;
|
|
30
|
+
/**
|
|
31
|
+
* 创建 table
|
|
32
|
+
*/
|
|
33
|
+
createTable(EntityType: EntityType): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* 判断 table 是否存在
|
|
36
|
+
*/
|
|
37
|
+
isTableExisted(EntityType: EntityType): Promise<boolean>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 数据库适配器基类
|
|
41
|
+
*/
|
|
42
|
+
export declare abstract class RxDBAdapterBase {
|
|
43
|
+
readonly rxdb: RxDB;
|
|
44
|
+
constructor(rxdb: RxDB);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 数据库适配器基类
|
|
48
|
+
*/
|
|
49
|
+
export declare abstract class RxDBAdapterLocalBase extends RxDBAdapterBase {
|
|
50
|
+
/**
|
|
51
|
+
* 执行事务
|
|
52
|
+
*/
|
|
53
|
+
abstract transaction(fun: TransactionFun): Promise<any>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 数据库适配器基类
|
|
57
|
+
*/
|
|
58
|
+
export declare abstract class RxDBAdapterRemoteBase extends RxDBAdapterBase {
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 适配器基础配置
|
|
62
|
+
*/
|
|
63
|
+
export type IRxDBAdapterOptions = Record<string, any>;
|
|
64
|
+
/**
|
|
65
|
+
* RxDB 插件
|
|
66
|
+
*/
|
|
67
|
+
export type AdapterFactory = (rxDB: RxDB) => Promise<IRxDBAdapter> | IRxDBAdapter;
|
|
68
|
+
/**
|
|
69
|
+
* RxDB 适配器
|
|
70
|
+
*/
|
|
71
|
+
export interface RxDBAdapters {
|
|
72
|
+
[name: string]: IRxDBAdapter;
|
|
73
|
+
}
|