@aiao/rxdb-plugin-sync 0.0.0-stage → 0.0.26
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/LICENSE +21 -0
- package/README.md +81 -2
- package/dist/SyncManager.d.ts +412 -0
- package/dist/SyncManager.d.ts.map +1 -0
- package/dist/branch-change-id.d.ts +31 -0
- package/dist/branch-change-id.d.ts.map +1 -0
- package/dist/branch-utils.d.ts +8 -0
- package/dist/branch-utils.d.ts.map +1 -0
- package/dist/bulk-sync.d.ts +117 -0
- package/dist/bulk-sync.d.ts.map +1 -0
- package/dist/cascade-blocking.d.ts +38 -0
- package/dist/cascade-blocking.d.ts.map +1 -0
- package/dist/check-repository-updates.d.ts +47 -0
- package/dist/check-repository-updates.d.ts.map +1 -0
- package/dist/cleanup-expired.d.ts +56 -0
- package/dist/cleanup-expired.d.ts.map +1 -0
- package/dist/dependency-graph.d.ts +128 -0
- package/dist/dependency-graph.d.ts.map +1 -0
- package/dist/get-all-repository-sync-status.d.ts +58 -0
- package/dist/get-all-repository-sync-status.d.ts.map +1 -0
- package/dist/get-repository-sync-status.d.ts +68 -0
- package/dist/get-repository-sync-status.d.ts.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3273 -0
- package/dist/plugin.d.ts +70 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/pull-ancestor-changes.d.ts +41 -0
- package/dist/pull-ancestor-changes.d.ts.map +1 -0
- package/dist/pull-batch.d.ts +16 -0
- package/dist/pull-batch.d.ts.map +1 -0
- package/dist/pull-conflict-utils.d.ts +43 -0
- package/dist/pull-conflict-utils.d.ts.map +1 -0
- package/dist/pull-repository.d.ts +36 -0
- package/dist/pull-repository.d.ts.map +1 -0
- package/dist/pull.d.ts +16 -0
- package/dist/pull.d.ts.map +1 -0
- package/dist/push-branch.d.ts +22 -0
- package/dist/push-branch.d.ts.map +1 -0
- package/dist/push-repository.d.ts +63 -0
- package/dist/push-repository.d.ts.map +1 -0
- package/dist/push.d.ts +14 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/query-cache-outbox.d.ts +120 -0
- package/dist/query-cache-outbox.d.ts.map +1 -0
- package/dist/sync-branches.d.ts +35 -0
- package/dist/sync-branches.d.ts.map +1 -0
- package/dist/sync-listeners.d.ts +20 -0
- package/dist/sync-listeners.d.ts.map +1 -0
- package/dist/sync-manager.utils.d.ts +36 -0
- package/dist/sync-manager.utils.d.ts.map +1 -0
- package/dist/sync-repository.d.ts +63 -0
- package/dist/sync-repository.d.ts.map +1 -0
- package/dist/topological-sort.d.ts +126 -0
- package/dist/topological-sort.d.ts.map +1 -0
- package/dist/version.utils.d.ts +3 -0
- package/dist/version.utils.d.ts.map +1 -0
- package/package.json +58 -3
- package/src/SyncManager.ts +662 -0
- package/src/branch-change-id.ts +70 -0
- package/src/branch-utils.ts +37 -0
- package/src/bulk-sync.ts +338 -0
- package/src/cascade-blocking.ts +61 -0
- package/src/check-repository-updates.ts +143 -0
- package/src/cleanup-expired.ts +271 -0
- package/src/dependency-graph.ts +324 -0
- package/src/get-all-repository-sync-status.ts +115 -0
- package/src/get-repository-sync-status.ts +237 -0
- package/src/index.ts +53 -0
- package/src/plugin.ts +124 -0
- package/src/pull-ancestor-changes.ts +61 -0
- package/src/pull-batch.ts +410 -0
- package/src/pull-conflict-utils.ts +280 -0
- package/src/pull-repository.ts +701 -0
- package/src/pull.ts +204 -0
- package/src/push-branch.ts +61 -0
- package/src/push-repository.ts +1002 -0
- package/src/push.ts +104 -0
- package/src/query-cache-outbox.ts +866 -0
- package/src/sync-branches.ts +156 -0
- package/src/sync-listeners.ts +289 -0
- package/src/sync-manager.utils.ts +48 -0
- package/src/sync-repository.ts +302 -0
- package/src/topological-sort.ts +246 -0
- package/src/version.utils.ts +20 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { SyncProgress } from '@aiao/rxdb';
|
|
2
|
+
import { SyncManager } from './SyncManager.js';
|
|
3
|
+
import { PullRepositoryOptions, PullRepositoryResult } from './pull-repository.js';
|
|
4
|
+
import { PushRepositoryOptions, PushRepositoryResult } from './push-repository.js';
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview 仓库级别的同步操作
|
|
7
|
+
*
|
|
8
|
+
* 将仓库的拉取(pull)和推送(push)操作组合在一起,保证正确的执行顺序。
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* 仓库同步选项
|
|
12
|
+
*/
|
|
13
|
+
export interface SyncRepositoryOptions {
|
|
14
|
+
/**
|
|
15
|
+
* 同步方向
|
|
16
|
+
* @default 'sync'
|
|
17
|
+
*/
|
|
18
|
+
direction?: 'pull' | 'push' | 'sync';
|
|
19
|
+
/**
|
|
20
|
+
* 拉取(pull)选项
|
|
21
|
+
*/
|
|
22
|
+
pull?: PullRepositoryOptions;
|
|
23
|
+
/**
|
|
24
|
+
* 推送(push)选项
|
|
25
|
+
*/
|
|
26
|
+
push?: PushRepositoryOptions;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 仓库同步结果
|
|
30
|
+
*/
|
|
31
|
+
export interface SyncRepositoryResult extends SyncProgress {
|
|
32
|
+
/**
|
|
33
|
+
* 拉取结果
|
|
34
|
+
*/
|
|
35
|
+
pullResult: PullRepositoryResult;
|
|
36
|
+
/**
|
|
37
|
+
* 推送结果
|
|
38
|
+
*/
|
|
39
|
+
pushResult: PushRepositoryResult;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 同步一个仓库(先拉取再推送)
|
|
43
|
+
*
|
|
44
|
+
* @param sm - SyncManager 实例
|
|
45
|
+
* @param namespace - 实体命名空间
|
|
46
|
+
* @param entity - 实体名称
|
|
47
|
+
* @param options - 同步选项
|
|
48
|
+
* @returns 同步结果
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* // 同步 Todo 仓库(pull + push)
|
|
53
|
+
* const result = await syncRepository(sm, 'public', 'Todo');
|
|
54
|
+
*
|
|
55
|
+
* // 使用自定义选项同步
|
|
56
|
+
* const result = await syncRepository(sm, 'public', 'Todo', {
|
|
57
|
+
* pull: { limit: 500, fetchAll: true },
|
|
58
|
+
* push: { batchSize: 100 }
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function syncRepository(sm: SyncManager, namespace: string, entity: string, options?: SyncRepositoryOptions): Promise<SyncRepositoryResult>;
|
|
63
|
+
//# sourceMappingURL=sync-repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-repository.d.ts","sourceRoot":"","sources":["../src/sync-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,YAAY,EAClB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAGL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAC1B,MAAM,sBAAsB,CAAC;AAC9B;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAErC;;OAEG;IACH,IAAI,CAAC,EAAE,qBAAqB,CAAC;IAE7B;;OAEG;IACH,IAAI,CAAC,EAAE,qBAAqB,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD;;OAEG;IACH,UAAU,EAAE,oBAAoB,CAAC;IAEjC;;OAEG;IACH,UAAU,EAAE,oBAAoB,CAAC;CAClC;AAkGD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,cAAc,CAClC,EAAE,EAAE,WAAW,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,oBAAoB,CAAC,CA+B/B"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { DependencyGraph, RepositoryIdentifier } from './dependency-graph.js';
|
|
2
|
+
/**
|
|
3
|
+
* 排序方向
|
|
4
|
+
*/
|
|
5
|
+
export type SortDirection = 'pull' | 'push';
|
|
6
|
+
/**
|
|
7
|
+
* 依赖图上的一条边。
|
|
8
|
+
*
|
|
9
|
+
* - `dependsOn`:本仓库**依赖**的仓库(父,外键指过去的那一端)
|
|
10
|
+
* - `requiredBy`:**依赖本仓库**的仓库(子,外键指过来的那一端)
|
|
11
|
+
*/
|
|
12
|
+
export type DependencyEdge = 'dependsOn' | 'requiredBy';
|
|
13
|
+
/**
|
|
14
|
+
* 排序方向沿依赖图上的哪条边展开。
|
|
15
|
+
*
|
|
16
|
+
* 这条对应关系是整个级联调度的枢纽,所以只在这里写一次:拓扑序沿哪条边建立,
|
|
17
|
+
* 「谁排在我前面」就是哪条边,级联的依赖闸门也必须看同一条边。
|
|
18
|
+
* 从前它以 `direction === 'pull' ? dep.dependsOn : dep.requiredBy` 的形式散在
|
|
19
|
+
* {@link topologicalSort} 里,闸门那一侧则各写各的,于是 DELETE 相位的闸门看错了边。
|
|
20
|
+
*/
|
|
21
|
+
export declare function dependencyEdgeOf(direction: SortDirection): DependencyEdge;
|
|
22
|
+
/**
|
|
23
|
+
* 本相位的依赖闸门该看哪条边 —— 也就是「本相位里谁排在我前面」。
|
|
24
|
+
*
|
|
25
|
+
* DELETE 相位子先父后,父被子阻断,看 `requiredBy`;
|
|
26
|
+
* INSERT/UPDATE 相位父先子后,子被父阻断,看 `dependsOn`。
|
|
27
|
+
*
|
|
28
|
+
* 与 {@link topologicalSortForAction} 共用 {@link sortDirectionForAction},
|
|
29
|
+
* 保证「执行顺序」和「阻断关系」不可能各说各话。
|
|
30
|
+
*
|
|
31
|
+
* @param action - 本相位提交的变更类型
|
|
32
|
+
* @returns 该相位下判定阻断所依据的依赖边
|
|
33
|
+
*/
|
|
34
|
+
export declare function dependencyEdgeForAction(action: SortActionKind): DependencyEdge;
|
|
35
|
+
/**
|
|
36
|
+
* 拓扑排序
|
|
37
|
+
*
|
|
38
|
+
* @param graph - 依赖图
|
|
39
|
+
* @param direction - 排序方向
|
|
40
|
+
* - 'pull': 父实体在前(User -> Todo -> Comment)
|
|
41
|
+
* - 'push': 子实体在前(Comment -> Todo -> User)
|
|
42
|
+
* @returns 排序后的 repository 列表
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* // Pull 顺序(父在前)
|
|
47
|
+
* const pullOrder = topologicalSort(graph, 'pull');
|
|
48
|
+
* // 返回: [User, Todo, Comment]
|
|
49
|
+
*
|
|
50
|
+
* // Push 顺序(子在前)
|
|
51
|
+
* const pushOrder = topologicalSort(graph, 'push');
|
|
52
|
+
* // 返回: [Comment, Todo, User]
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function topologicalSort(graph: DependencyGraph, direction: SortDirection): RepositoryIdentifier[];
|
|
56
|
+
/**
|
|
57
|
+
* 拓扑排序(Pull 方向)
|
|
58
|
+
*
|
|
59
|
+
* 确保父实体在前,适用于 Pull 同步
|
|
60
|
+
*
|
|
61
|
+
* @param graph - 依赖图
|
|
62
|
+
* @returns 排序后的 repository 列表
|
|
63
|
+
*/
|
|
64
|
+
export declare function topologicalSortForPull(graph: DependencyGraph): RepositoryIdentifier[];
|
|
65
|
+
/**
|
|
66
|
+
* 拓扑排序(Push 方向)
|
|
67
|
+
*
|
|
68
|
+
* 确保子实体在前,适用于 Push 同步
|
|
69
|
+
*
|
|
70
|
+
* @param graph - 依赖图
|
|
71
|
+
* @returns 排序后的 repository 列表
|
|
72
|
+
*/
|
|
73
|
+
export declare function topologicalSortForPush(graph: DependencyGraph): RepositoryIdentifier[];
|
|
74
|
+
/**
|
|
75
|
+
* 变更类型:决定安全的提交顺序
|
|
76
|
+
*/
|
|
77
|
+
export type SortActionKind = 'INSERT' | 'UPDATE' | 'DELETE';
|
|
78
|
+
/**
|
|
79
|
+
* 按变更类型选排序方向
|
|
80
|
+
*
|
|
81
|
+
* 同一张依赖图,INSERT 和 DELETE 需要的顺序**正好相反**,「push 就是子→父」这个说法
|
|
82
|
+
* 只对 DELETE 成立:
|
|
83
|
+
*
|
|
84
|
+
* - `INSERT` / `UPDATE` → **父先**。子行的外键指向父行,父行不先落库就是悬空引用,FK 失败。
|
|
85
|
+
* - `DELETE` → **子先**。父行还被子行引用着,先删父同样 FK 失败。
|
|
86
|
+
*
|
|
87
|
+
* 所以一次级联推送不可能靠单一顺序扫完,必须分相位:DELETE 走一遍子→父,
|
|
88
|
+
* INSERT/UPDATE 再走一遍父→子。
|
|
89
|
+
*
|
|
90
|
+
* @param graph - 依赖图
|
|
91
|
+
* @param action - 本相位要提交的变更类型
|
|
92
|
+
* @returns 该类型下安全的提交顺序
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* topologicalSortForAction(graph, 'INSERT'); // [User, Todo, Comment]
|
|
97
|
+
* topologicalSortForAction(graph, 'DELETE'); // [Comment, Todo, User]
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function topologicalSortForAction(graph: DependencyGraph, action: SortActionKind): RepositoryIdentifier[];
|
|
101
|
+
/**
|
|
102
|
+
* 过滤并排序指定的 repository 列表
|
|
103
|
+
*
|
|
104
|
+
* 从依赖图中只选择指定的 repositories,并按拓扑顺序排序
|
|
105
|
+
*
|
|
106
|
+
* @param graph - 完整依赖图
|
|
107
|
+
* @param repositories - 要排序的 repository 列表
|
|
108
|
+
* @param direction - 排序方向
|
|
109
|
+
* @returns 排序后的 repository 列表
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* // 只同步 Todo 和 Comment
|
|
114
|
+
* const filtered = filterAndSort(
|
|
115
|
+
* graph,
|
|
116
|
+
* [
|
|
117
|
+
* { namespace: 'public', entity: 'Todo' },
|
|
118
|
+
* { namespace: 'public', entity: 'Comment' }
|
|
119
|
+
* ],
|
|
120
|
+
* 'pull'
|
|
121
|
+
* );
|
|
122
|
+
* // 返回: [Todo, Comment](按依赖顺序)
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function filterAndSort(graph: DependencyGraph, repositories: RepositoryIdentifier[], direction: SortDirection): RepositoryIdentifier[];
|
|
126
|
+
//# sourceMappingURL=topological-sort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topological-sort.d.ts","sourceRoot":"","sources":["../src/topological-sort.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAEnF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,YAAY,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,aAAa,GAAG,cAAc,CAEzE;AAWD;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAE9E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,aAAa,GAAG,oBAAoB,EAAE,CAiDxG;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,eAAe,GAAG,oBAAoB,EAAE,CAErF;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,eAAe,GAAG,oBAAoB,EAAE,CAErF;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,GAAG,oBAAoB,EAAE,CAE/G;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,eAAe,EACtB,YAAY,EAAE,oBAAoB,EAAE,EACpC,SAAS,EAAE,aAAa,GACvB,oBAAoB,EAAE,CA8BxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.utils.d.ts","sourceRoot":"","sources":["../src/version.utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAQ,MAAM,YAAY,CAAC;AAC5D,eAAO,MAAM,sBAAsB,GACjC,cAAc,YAAY,EAAE,EAC5B,MAAM,OAAO,CAAC,UAAU,CAAC,KACxB,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,SAAS,CAAC,EAUjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiao/rxdb-plugin-sync",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.26",
|
|
4
|
+
"description": "Push/pull synchronization, conflict resolution and offline outbox for Aiao RxDB.",
|
|
5
|
+
"homepage": "https://rxdb.netlify.app/docs/plugins",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/aiao-io/rxdb/issues"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"aiao",
|
|
11
|
+
"rxdb",
|
|
12
|
+
"sync",
|
|
13
|
+
"push",
|
|
14
|
+
"pull",
|
|
15
|
+
"conflict",
|
|
16
|
+
"offline-first",
|
|
17
|
+
"typescript"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/aiao-io/rxdb.git",
|
|
23
|
+
"directory": "packages/rxdb-plugin-sync"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
"./package.json": "./package.json",
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"src",
|
|
41
|
+
"!src/**/*.spec.*",
|
|
42
|
+
"!src/**/*.test.*",
|
|
43
|
+
"!src/**/__tests__/**",
|
|
44
|
+
"!**/*.tsbuildinfo"
|
|
45
|
+
],
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"nx": {
|
|
50
|
+
"name": "rxdb-plugin-sync",
|
|
51
|
+
"tags": [
|
|
52
|
+
"js-lib"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"rxjs": "^7.8.2",
|
|
57
|
+
"@aiao/rxdb": "0.0.26",
|
|
58
|
+
"@aiao/utils": "0.0.26",
|
|
59
|
+
"@aiao/rxdb-plugin-history": "0.0.26"
|
|
60
|
+
}
|
|
6
61
|
}
|