@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.
Files changed (38) hide show
  1. package/README.md +1 -0
  2. package/RxDB.d.ts +51 -0
  3. package/RxDBError.d.ts +13 -0
  4. package/entity/@Entity.d.ts +29 -0
  5. package/entity/@TreeEntity.d.ts +50 -0
  6. package/entity/EntityBase.d.ts +49 -0
  7. package/entity/EntityManager.d.ts +140 -0
  8. package/entity/EntityStatus.d.ts +211 -0
  9. package/entity/TreeEntityBase.d.ts +7 -0
  10. package/entity/entity-metadata-options.interface.d.ts +434 -0
  11. package/entity/entity-metadata.interface.d.ts +67 -0
  12. package/entity/entity.interface.d.ts +110 -0
  13. package/entity/entity.utils.d.ts +59 -0
  14. package/entity/entity_proxy_helper.d.ts +48 -0
  15. package/entity/entity_relation_helper.d.ts +15 -0
  16. package/entity/generate_many_to_many_entity.d.ts +35 -0
  17. package/entity/transition-metadata.d.ts +17 -0
  18. package/index.d.ts +26 -0
  19. package/index.js +1783 -0
  20. package/package.json +19 -0
  21. package/repository/Repository.d.ts +108 -0
  22. package/repository/RepositoryBase.d.ts +32 -0
  23. package/repository/TreeRepository.d.ts +28 -0
  24. package/repository/query-options.interface.d.ts +53 -0
  25. package/repository/query.interface.d.ts +92 -0
  26. package/repository/query.utils.d.ts +19 -0
  27. package/repository/repository.interface.d.ts +84 -0
  28. package/repository/tree-query-options.interface.d.ts +9 -0
  29. package/repository/tree-repository.interface.d.ts +26 -0
  30. package/rxdb-adapter.d.ts +73 -0
  31. package/rxdb-events.d.ts +186 -0
  32. package/rxdb-plugin.d.ts +20 -0
  33. package/rxdb-utils.d.ts +20 -0
  34. package/rxdb.interface.d.ts +56 -0
  35. package/rxdb.private.d.ts +55 -0
  36. package/schema/SchemaManager.d.ts +57 -0
  37. package/system/change.d.ts +13 -0
  38. package/system/migration.d.ts +9 -0
@@ -0,0 +1,186 @@
1
+ import { EntityType, UUID } from './entity/entity.interface';
2
+ import { UnixMilliseconds } from './rxdb.interface';
3
+ import { UpdatedBy } from './rxdb.private';
4
+ /**
5
+ * RxDB 实体事件抽象类
6
+ */
7
+ declare abstract class AbstractRxDBEntityEvent {
8
+ readonly entity: InstanceType<EntityType>;
9
+ abstract type: string;
10
+ constructor(entity: InstanceType<EntityType>);
11
+ }
12
+ /**
13
+ * RxDB 实体错误事件抽象类
14
+ */
15
+ declare abstract class AbstractRxDBEntityErrorEvent extends AbstractRxDBEntityEvent {
16
+ readonly error: any;
17
+ constructor(entity: InstanceType<EntityType>, error: any);
18
+ }
19
+ export declare const ENTITY_NEW_EVENT = "ENTITY_NEW";
20
+ /**
21
+ * 实体 被 new 出来
22
+ */
23
+ export declare class EntityNewEvent extends AbstractRxDBEntityEvent {
24
+ type: string;
25
+ }
26
+ export declare const ENTITY_CREATE_EVENT = "ENTITY_CREATE";
27
+ export declare const ENTITY_CREATE_SUCCESS_EVENT = "ENTITY_CREATE_SUCCESS";
28
+ export declare const ENTITY_CREATE_ERROR_EVENT = "ENTITY_CREATE_ERROR";
29
+ /**
30
+ * 实体 正在被创建
31
+ */
32
+ export declare class EntityCreateEvent extends AbstractRxDBEntityEvent {
33
+ type: string;
34
+ }
35
+ /**
36
+ * 实体 创建成功
37
+ */
38
+ export declare class EntityCreateSuccessEvent extends AbstractRxDBEntityEvent {
39
+ type: string;
40
+ }
41
+ /**
42
+ * 实体 创建错误
43
+ */
44
+ export declare class EntityCreateErrorEvent extends AbstractRxDBEntityErrorEvent {
45
+ type: string;
46
+ }
47
+ export declare const ENTITY_UPDATE_EVENT = "ENTITY_UPDATE";
48
+ export declare const ENTITY_UPDATE_SUCCESS_EVENT = "ENTITY_UPDATE_SUCCESS";
49
+ export declare const ENTITY_UPDATE_ERROR_EVENT = "ENTITY_UPDATE_ERROR";
50
+ /**
51
+ * 实体 准备更新
52
+ */
53
+ export declare class EntityUpdateEvent extends AbstractRxDBEntityEvent {
54
+ type: string;
55
+ }
56
+ /**
57
+ * 实体 更新成功
58
+ */
59
+ export declare class EntityUpdateSuccessEvent extends AbstractRxDBEntityEvent {
60
+ type: string;
61
+ }
62
+ /**
63
+ * 实体 更新失败
64
+ */
65
+ export declare class EntityUpdateErrorEvent extends AbstractRxDBEntityErrorEvent {
66
+ type: string;
67
+ }
68
+ export declare const ENTITY_REMOVE_EVENT = "ENTITY_REMOVE";
69
+ export declare const ENTITY_REMOVE_SUCCESS_EVENT = "ENTITY_REMOVE_SUCCESS";
70
+ export declare const ENTITY_REMOVE_ERROR_EVENT = "ENTITY_REMOVE_ERROR";
71
+ /**
72
+ * 实体 准备删除
73
+ */
74
+ export declare class EntityRemoveEvent extends AbstractRxDBEntityEvent {
75
+ type: string;
76
+ }
77
+ /**
78
+ * 实体 删除成功
79
+ */
80
+ export declare class EntityRemoveSuccessEvent extends AbstractRxDBEntityEvent {
81
+ type: string;
82
+ }
83
+ /**
84
+ * 实体 删除失败
85
+ */
86
+ export declare class EntityRemoveErrorEvent extends AbstractRxDBEntityErrorEvent {
87
+ type: string;
88
+ }
89
+ export declare const ENTITY_PATCH_EVENT = "ENTITY_PATCH";
90
+ /**
91
+ * 实体 部分更新
92
+ */
93
+ export declare class EntityPatchEvent extends AbstractRxDBEntityEvent {
94
+ readonly patch: Record<string, any>;
95
+ readonly inversePatch: Record<string, any>;
96
+ readonly recordAt: UnixMilliseconds;
97
+ readonly timeStamp: DOMHighResTimeStamp;
98
+ readonly updatedBy: UpdatedBy;
99
+ type: string;
100
+ constructor(entity: InstanceType<EntityType>, patch: Record<string, any>, inversePatch: Record<string, any>, recordAt: UnixMilliseconds, timeStamp: DOMHighResTimeStamp, updatedBy: UpdatedBy);
101
+ }
102
+ /**
103
+ * 实体 所有事件
104
+ */
105
+ export interface RxDBEntityEventMap {
106
+ [ENTITY_NEW_EVENT]: EntityNewEvent;
107
+ [ENTITY_CREATE_EVENT]: EntityCreateEvent;
108
+ [ENTITY_CREATE_SUCCESS_EVENT]: EntityCreateSuccessEvent;
109
+ [ENTITY_CREATE_ERROR_EVENT]: EntityCreateErrorEvent;
110
+ [ENTITY_PATCH_EVENT]: EntityPatchEvent;
111
+ [ENTITY_UPDATE_EVENT]: EntityUpdateEvent;
112
+ [ENTITY_UPDATE_SUCCESS_EVENT]: EntityUpdateSuccessEvent;
113
+ [ENTITY_UPDATE_ERROR_EVENT]: EntityUpdateErrorEvent;
114
+ [ENTITY_REMOVE_EVENT]: EntityRemoveEvent;
115
+ [ENTITY_REMOVE_SUCCESS_EVENT]: EntityRemoveSuccessEvent;
116
+ [ENTITY_REMOVE_ERROR_EVENT]: EntityRemoveErrorEvent;
117
+ }
118
+ export declare const TRANSACTION_BEGIN = "TRANSACTION_BEGIN";
119
+ export declare const TRANSACTION_COMMIT = "TRANSACTION_COMMIT";
120
+ export declare const TRANSACTION_ROLLBACK = "TRANSACTION_ROLLBACK";
121
+ /**
122
+ * 事务 开始
123
+ */
124
+ export declare class TransactionBeginEvent {
125
+ type: string;
126
+ }
127
+ /**
128
+ * 事务 提交
129
+ */
130
+ export declare class TransactionCommitEvent {
131
+ type: string;
132
+ }
133
+ /**
134
+ * 事务 回滚
135
+ */
136
+ export declare class TransactionRollbackEvent {
137
+ type: string;
138
+ }
139
+ export declare const DATABASE_DELETE = "DATABASE_DELETE";
140
+ export declare const DATABASE_INSERT = "DATABASE_INSERT";
141
+ export declare const DATABASE_UPDATE = "DATABASE_UPDATE";
142
+ /**
143
+ * 数据变化
144
+ */
145
+ export interface IRxDBAdapterDataChange {
146
+ id?: UUID;
147
+ rowId?: any;
148
+ data?: any;
149
+ recordAt: UnixMilliseconds;
150
+ timeStamp: DOMHighResTimeStamp;
151
+ }
152
+ declare abstract class AbstractRxDBAdapterDataChangeEvent {
153
+ readonly EntityType: EntityType;
154
+ readonly data: IRxDBAdapterDataChange;
155
+ abstract type: string;
156
+ constructor(EntityType: EntityType, data: IRxDBAdapterDataChange);
157
+ }
158
+ export declare class RxDBAdapterDeleteChangeEvent extends AbstractRxDBAdapterDataChangeEvent {
159
+ type: string;
160
+ }
161
+ export declare class RxDBAdapterInsertChangeEvent extends AbstractRxDBAdapterDataChangeEvent {
162
+ type: string;
163
+ }
164
+ export declare class RxDBAdapterUpdateChangeEvent extends AbstractRxDBAdapterDataChangeEvent {
165
+ type: string;
166
+ }
167
+ /**
168
+ * Rxdb 事件
169
+ */
170
+ export interface RxDBEventMap extends RxDBEntityEventMap {
171
+ [TRANSACTION_BEGIN]: TransactionBeginEvent;
172
+ [TRANSACTION_COMMIT]: TransactionCommitEvent;
173
+ [TRANSACTION_ROLLBACK]: TransactionRollbackEvent;
174
+ [DATABASE_DELETE]: RxDBAdapterDeleteChangeEvent;
175
+ [DATABASE_INSERT]: RxDBAdapterInsertChangeEvent;
176
+ [DATABASE_UPDATE]: RxDBAdapterUpdateChangeEvent;
177
+ }
178
+ /**
179
+ * RxDB 实体事件
180
+ */
181
+ export type RxDBEntityEvent = RxDBEntityEventMap[keyof RxDBEntityEventMap];
182
+ /**
183
+ * RxDB 事件
184
+ */
185
+ export type RxDBEvent = RxDBEventMap[keyof RxDBEventMap];
186
+ export {};
@@ -0,0 +1,20 @@
1
+ import { RxDB } from './RxDB';
2
+ /**
3
+ * RxDB 插件接口
4
+ */
5
+ export interface IRxDBPlugin {
6
+ name: Uncapitalize<string>;
7
+ install(): Promise<void>;
8
+ destroy(): Promise<void>;
9
+ }
10
+ /**
11
+ * RxDB 插件基类
12
+ */
13
+ export declare abstract class RxDBPluginBase {
14
+ protected readonly rxdb: RxDB;
15
+ constructor(rxdb: RxDB);
16
+ }
17
+ /**
18
+ * RxDB 插件
19
+ */
20
+ export type Plugin<Options = any> = (rxDB: RxDB, options?: Options) => IRxDBPlugin;
@@ -0,0 +1,20 @@
1
+ import { EntityMetadata } from './entity/entity-metadata.interface';
2
+ import { EntityType, UUID } from './entity/entity.interface';
3
+ import { EntityStatus } from './entity/EntityStatus';
4
+ /**
5
+ * 获取实体元数据
6
+ */
7
+ export declare const getEntityMetadata: <T extends EntityType>(target: T | InstanceType<T>) => EntityMetadata;
8
+ /**
9
+ * 获取实体状态
10
+ */
11
+ export declare const getEntityStatus: <T extends EntityType>(target: InstanceType<T>) => EntityStatus<T>;
12
+ /**
13
+ * class 的装饰器
14
+ * 代码生成时会重复创建这个方法,所以统一引用 rxdb 里的减少代码量
15
+ */
16
+ export declare const __decorateClass: (decorators: any, target: any, key: any, kind: number) => any;
17
+ /**
18
+ * 生成 uuid
19
+ */
20
+ export declare const uuid: () => UUID;
@@ -0,0 +1,56 @@
1
+ import { SyncOptions } from './entity/entity-metadata-options.interface';
2
+ import { EntityType } from './entity/entity.interface';
3
+ /**
4
+ * 升级脚步
5
+ */
6
+ export interface MigrationType {
7
+ up(): Promise<void>;
8
+ down(): Promise<void>;
9
+ }
10
+ /**
11
+ * RxDB 环境上下文
12
+ */
13
+ export interface RxDBContext {
14
+ userId?: string;
15
+ }
16
+ /**
17
+ * RxDB 配置
18
+ */
19
+ export interface RxDBOptions {
20
+ /**
21
+ * 数据库名称
22
+ */
23
+ dbName: string;
24
+ /**
25
+ * 所有实体
26
+ */
27
+ entities: EntityType[];
28
+ /**
29
+ * 升级脚本
30
+ */
31
+ migrations?: MigrationType[];
32
+ /**
33
+ * 默认的同步配置
34
+ */
35
+ sync: SyncOptions;
36
+ /**
37
+ * 环境上下文
38
+ */
39
+ context?: RxDBContext;
40
+ /**
41
+ * 关系查询深度
42
+ * 最小为 1
43
+ * @default 2
44
+ * @example 1 允许查询自己的基本属性 + 自己的关系的基本属性
45
+ * @example 2 允许查询自己的基本属性 + 自己的关系的基本属性 + 自己关系的关系的基本属性
46
+ */
47
+ relationQueryDeep?: number;
48
+ }
49
+ /**
50
+ * unix(毫秒)时间
51
+ */
52
+ export type UnixMilliseconds = number;
53
+ /**
54
+ * unix(秒)时间
55
+ */
56
+ export type UnixSeconds = number;
@@ -0,0 +1,55 @@
1
+ import { EntityManager } from './entity/EntityManager';
2
+ import { UUID } from './entity/entity.interface';
3
+ import { RxDBAdapters } from './rxdb-adapter';
4
+ import { RxDBEvent } from './rxdb-events';
5
+ import { RxDBOptions } from './rxdb.interface';
6
+ /**
7
+ * 实体代理
8
+ */
9
+ export declare const ɵProxy: unique symbol;
10
+ /**
11
+ * 实体元数据
12
+ */
13
+ export declare const METADATA: unique symbol;
14
+ /**
15
+ * 实体状态
16
+ */
17
+ export declare const STATUS: unique symbol;
18
+ /**
19
+ * 实体状态正在变化
20
+ */
21
+ export declare const STATUS_CHECK: unique symbol;
22
+ /**
23
+ * 实体管理器
24
+ */
25
+ export declare const ENTITY_MANAGER: unique symbol;
26
+ export declare const ɵEntityDeleteCheck: unique symbol;
27
+ export declare const UPDATED_BY: unique symbol;
28
+ export declare const UPDATED_BY_SYSTEM: string;
29
+ export declare const UPDATED_BY_USER: string;
30
+ export type UpdatedBy = typeof UPDATED_BY_SYSTEM | typeof UPDATED_BY_USER | UUID | null;
31
+ /**
32
+ * 是否是本地数据库适配器
33
+ */
34
+ export declare const isLocalAdapter: <K extends keyof RxDBAdapters>(adapterName: K, options: RxDBOptions) => boolean;
35
+ /**
36
+ * 是否是事务事件
37
+ */
38
+ export declare const isTransactionEvent: (event: RxDBEvent) => boolean;
39
+ /**
40
+ * 是否是数据库事件
41
+ */
42
+ export declare const isDatabaseEvent: (event: RxDBEvent) => boolean;
43
+ /**
44
+ * 实体管理内部方法
45
+ */
46
+ export type EntityManagerPrivate = {
47
+ [ɵProxy]: (entity: any) => any;
48
+ [ɵEntityDeleteCheck]: (event: RxDBEvent) => void;
49
+ } & EntityManager;
50
+ /**
51
+ * Entity 私有属性
52
+ */
53
+ export type EntityPrivate = {
54
+ [UPDATED_BY]: UpdatedBy;
55
+ };
@@ -0,0 +1,57 @@
1
+ import { EntityPropertyMetadata, EntityRelationMetadata } from '../entity/entity-metadata-options.interface';
2
+ import { EntityMetadata } from '../entity/entity-metadata.interface';
3
+ import { EntityType } from '../entity/entity.interface';
4
+ import { RxDB } from '../RxDB';
5
+ type FindMappedRelationResult<T> = {
6
+ metadata: EntityMetadata;
7
+ relation: T;
8
+ } | undefined;
9
+ /**
10
+ * SchemaManager
11
+ */
12
+ export declare class SchemaManager {
13
+ #private;
14
+ protected readonly rxdb: RxDB;
15
+ constructor(rxdb: RxDB);
16
+ /**
17
+ * 查找当前关系属性的映射关系
18
+ * @param relation 当前关系属性
19
+ */
20
+ findMappedRelation(meta: EntityMetadata, relation: EntityRelationMetadata): FindMappedRelationResult<EntityRelationMetadata>;
21
+ /**
22
+ * 通过查询条件的字段找出关系数组
23
+ * @param field 查询条件的字段
24
+ */
25
+ getFieldRelations(metadata: EntityMetadata, field: string): GetFieldRelationsResult;
26
+ /**
27
+ * 获取实体元数据
28
+ */
29
+ getEntityMetadata(name: string, namespace: string): EntityMetadata | undefined;
30
+ /**
31
+ * 获取实体元数据
32
+ */
33
+ getEntityType(name: string, namespace: string): EntityType | undefined;
34
+ }
35
+ interface GetFieldRelationsResult {
36
+ /**
37
+ * 关系组
38
+ */
39
+ relations: {
40
+ metadata: EntityMetadata;
41
+ relation: EntityRelationMetadata;
42
+ }[];
43
+ /**
44
+ * 要查询的属性
45
+ */
46
+ property: EntityPropertyMetadata;
47
+ /**
48
+ * 查询的属性名字
49
+ * 当 isForeignKey = true 的时候 propertyName = xxxId
50
+ */
51
+ propertyName: string;
52
+ /**
53
+ * 要查询的属性是否是当前查询 Entity 外键
54
+ */
55
+ isForeignKey: boolean;
56
+ }
57
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 记录所有实体更改变化
3
+ */
4
+ export declare class RxDBChange {
5
+ id: number;
6
+ namespace?: string;
7
+ entity: string;
8
+ entityId: string;
9
+ type: string;
10
+ inversePatch?: Record<string, any>;
11
+ patch?: Record<string, any>;
12
+ changedAt: Date;
13
+ }
@@ -0,0 +1,9 @@
1
+ import { UUID } from '../entity/entity.interface';
2
+ /**
3
+ * 数据库变更合并记录
4
+ */
5
+ export declare class RxDBMigration {
6
+ readonly id: UUID;
7
+ readonly name: string;
8
+ readonly executedAt?: Date | null;
9
+ }