@longzai-intelligence-git/massive-sync-runner 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/dist/index.d.ts +154 -0
- package/dist/index.js +1 -0
- package/dist/rolldown-runtime-BqT_7tdF.js +1 -0
- package/package.json +39 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import "./rolldown-runtime-BqT_7tdF.js";
|
|
2
|
+
import { GitExecutor } from "@longzai-intelligence-git/core";
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 同步策略
|
|
6
|
+
*/
|
|
7
|
+
type SyncStrategy = 'rebase' | 'fast_forward_only' | 'merge';
|
|
8
|
+
/**
|
|
9
|
+
* 同步阶段标识
|
|
10
|
+
*/
|
|
11
|
+
type SyncStage = 'fetch' | 'rebase' | 'merge' | 'push';
|
|
12
|
+
/**
|
|
13
|
+
* 同步进度(单次快照)
|
|
14
|
+
*/
|
|
15
|
+
type SyncProgress = {
|
|
16
|
+
stage: SyncStage;
|
|
17
|
+
stageRatio: number;
|
|
18
|
+
overallRatio: number;
|
|
19
|
+
processedCount: number;
|
|
20
|
+
totalCount: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* 同步断点(阶段完成时落盘,供 resume 恢复)
|
|
24
|
+
*/
|
|
25
|
+
type SyncCheckpoint = {
|
|
26
|
+
id: string;
|
|
27
|
+
taskId: string;
|
|
28
|
+
completedStages: SyncStage[];
|
|
29
|
+
currentPosition?: string | null;
|
|
30
|
+
processedCount: number;
|
|
31
|
+
updatedAt: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* 单阶段结果
|
|
35
|
+
*/
|
|
36
|
+
type SyncStageResult = {
|
|
37
|
+
stage: SyncStage;
|
|
38
|
+
status: 'completed' | 'skipped';
|
|
39
|
+
durationMs: number;
|
|
40
|
+
resultingSha: string | null;
|
|
41
|
+
error: string | null;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* 同步任务最终结果
|
|
45
|
+
*/
|
|
46
|
+
type SyncResult = {
|
|
47
|
+
taskId: string;
|
|
48
|
+
stages: SyncStageResult[];
|
|
49
|
+
totalDurationMs: number;
|
|
50
|
+
success: boolean;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* 同步执行入参(全字段可选,缺省由 runner 填默认值)
|
|
54
|
+
*/
|
|
55
|
+
type SyncInput = {
|
|
56
|
+
remote?: string;
|
|
57
|
+
ref?: string;
|
|
58
|
+
strategy?: SyncStrategy;
|
|
59
|
+
segmentSize?: number;
|
|
60
|
+
stallTimeoutMs?: number;
|
|
61
|
+
absoluteTimeoutMs?: number;
|
|
62
|
+
stageTimeoutMs?: number;
|
|
63
|
+
stageRetries?: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* 断点存储接口(平台无关,file/in-memory 实现各自满足)
|
|
67
|
+
*/
|
|
68
|
+
type CheckpointStore = {
|
|
69
|
+
save(checkpoint: SyncCheckpoint): Promise<void>;
|
|
70
|
+
remove(id: string): Promise<void>;
|
|
71
|
+
list(): Promise<SyncCheckpoint[]>;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* 运行器依赖
|
|
75
|
+
*/
|
|
76
|
+
type SyncRunnerDeps = {
|
|
77
|
+
/**
|
|
78
|
+
* git 执行器
|
|
79
|
+
*/
|
|
80
|
+
executor: GitExecutor;
|
|
81
|
+
/**
|
|
82
|
+
* 仓库工作目录
|
|
83
|
+
*/
|
|
84
|
+
repoPath: string;
|
|
85
|
+
/**
|
|
86
|
+
* 断点存储(可选,传入后阶段完成时落盘,支持 resume)
|
|
87
|
+
*/
|
|
88
|
+
checkpointStore?: CheckpointStore;
|
|
89
|
+
/**
|
|
90
|
+
* 进度回调(可选)
|
|
91
|
+
*/
|
|
92
|
+
onProgress?: (progress: SyncProgress) => void;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* 执行结果(成功/失败二态,失败时可选携带部分断点)
|
|
96
|
+
*/
|
|
97
|
+
type SyncRunOutcome = {
|
|
98
|
+
success: true;
|
|
99
|
+
result: SyncResult;
|
|
100
|
+
} | {
|
|
101
|
+
success: false;
|
|
102
|
+
error: Error;
|
|
103
|
+
partial?: SyncCheckpoint;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* 同步运行器(函数式 API)
|
|
107
|
+
*/
|
|
108
|
+
type SyncRunner = {
|
|
109
|
+
/**
|
|
110
|
+
* 执行完整同步(fetch→rebase/merge→push)
|
|
111
|
+
*/
|
|
112
|
+
run(input: SyncInput): Promise<SyncRunOutcome>;
|
|
113
|
+
/**
|
|
114
|
+
* 从断点恢复同步
|
|
115
|
+
*/
|
|
116
|
+
resume(input: SyncInput, checkpoint: SyncCheckpoint): Promise<SyncRunOutcome>;
|
|
117
|
+
/**
|
|
118
|
+
* 取消运行中的同步(协作式,在阶段切换处生效)
|
|
119
|
+
*/
|
|
120
|
+
cancel(): void;
|
|
121
|
+
};
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/create-sync-runner.d.ts
|
|
124
|
+
/**
|
|
125
|
+
* 创建同步运行器
|
|
126
|
+
*
|
|
127
|
+
* @param deps - 运行器依赖(executor + repoPath + 可选 checkpointStore/onProgress)
|
|
128
|
+
* @returns SyncRunner 实例(run/resume/cancel)
|
|
129
|
+
*/
|
|
130
|
+
declare const createSyncRunner: (deps: SyncRunnerDeps) => SyncRunner;
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/file-checkpoint-store.d.ts
|
|
133
|
+
/**
|
|
134
|
+
* 文件存储选项
|
|
135
|
+
*/
|
|
136
|
+
type FileCheckpointStoreOptions = {
|
|
137
|
+
/**
|
|
138
|
+
* 仓库工作目录(`.git` 的父目录)
|
|
139
|
+
*/
|
|
140
|
+
repoPath: string;
|
|
141
|
+
/**
|
|
142
|
+
* 断点目录(相对 repoPath,默认 `.git/lzi-sync`)
|
|
143
|
+
*/
|
|
144
|
+
dirName?: string;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* 创建文件系统断点存储
|
|
148
|
+
*
|
|
149
|
+
* @param options - 文件存储选项(仓库路径 + 可选断点目录名)
|
|
150
|
+
* @returns CheckpointStore 实现,所有方法均落盘到 `<repoPath>/<dirName>/<taskId>.json`
|
|
151
|
+
*/
|
|
152
|
+
declare const createFileCheckpointStore: (options: FileCheckpointStoreOptions) => CheckpointStore;
|
|
153
|
+
//#endregion
|
|
154
|
+
export { type CheckpointStore, type FileCheckpointStoreOptions, type SyncCheckpoint, type SyncInput, type SyncProgress, type SyncResult, type SyncRunOutcome, type SyncRunner, type SyncRunnerDeps, type SyncStage, type SyncStageResult, type SyncStrategy, createFileCheckpointStore, createSyncRunner };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{createRefName as e}from"@longzai-intelligence-git/core";import{createSyncPipeline as t}from"@longzai-intelligence-git/massive-sync-pipeline";import{promises as n}from"node:fs";import*as r from"node:path";const i={remote:`origin`,ref:`refs/heads/main`,strategy:`rebase`,segmentSize:1e3,stallTimeoutMs:12e4,absoluteTimeoutMs:18e5,stageTimeoutMs:3e5,stageRetries:3},a=e=>e,o=n=>{let r={cancelled:!1},o=`sync-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,s=async(s,c)=>{let l=t(n.executor),u=[],d=Date.now();try{let t=await l.execute({executor:n.executor,repoPath:n.repoPath,remote:s.remote??i.remote,ref:e(s.ref??i.ref),strategy:s.strategy??i.strategy,segmentSize:s.segmentSize??i.segmentSize,stallTimeoutMs:s.stallTimeoutMs??i.stallTimeoutMs,absoluteTimeoutMs:s.absoluteTimeoutMs??i.absoluteTimeoutMs,stageTimeoutMs:s.stageTimeoutMs??i.stageTimeoutMs,stageRetries:s.stageRetries??i.stageRetries,resumeFrom:c==null?void 0:{completedStages:c.completedStages,currentPosition:c.currentPosition??void 0},hooks:{onStageCompleted:async(e,t,r)=>{let i=a(e);u.includes(i)||u.push(i),n.checkpointStore!=null&&await n.checkpointStore.save({id:o,taskId:o,completedStages:[...u],currentPosition:t,processedCount:r,updatedAt:Date.now()})},onProgress:e=>{n.onProgress?.(e)},shouldCancel:()=>r.cancelled}});if(n.checkpointStore!=null)try{await n.checkpointStore.remove(o)}catch{}let f=t.stages.map(e=>({stage:a(e.stage),status:e.status,durationMs:e.durationMs,resultingSha:e.resultingSha,error:e.error}));return{success:!0,result:{taskId:o,stages:f,totalDurationMs:Date.now()-d,success:!0}}}catch(e){return{success:!1,error:e instanceof Error?e:Error(String(e)),partial:n.checkpointStore==null?void 0:{id:o,taskId:o,completedStages:[...u],currentPosition:null,processedCount:0,updatedAt:Date.now()}}}};return{run:e=>s(e,void 0),resume:(e,t)=>s(e,t),cancel:()=>{r.cancelled=!0}}};function s(e){return typeof e!=`object`||!e?!1:`id`in e&&`taskId`in e&&`completedStages`in e&&`processedCount`in e&&`updatedAt`in e}const c=e=>{if(s(e))return e;throw TypeError(`JSON 结构不符合 SyncCheckpoint`)},l=e=>{let t=r.join(e.repoPath,e.dirName??`.git/lzi-sync`),i=async()=>{await n.mkdir(t,{recursive:!0})},a=e=>r.join(t,`${e}.json`);return{async save(e){await i(),await n.writeFile(a(e.taskId),JSON.stringify(e,null,2),`utf8`)},async remove(e){try{await n.unlink(a(e))}catch{}},async list(){try{let e=await n.readdir(t),i=[];for(let a of e)if(a.endsWith(`.json`))try{let e=await n.readFile(r.join(t,a),`utf8`);i.push(c(JSON.parse(e)))}catch{}return i}catch{return[]}}}};export{l as createFileCheckpointStore,o as createSyncRunner};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"node:module";export{};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-git/massive-sync-runner",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Longzai Intelligence Git - 巨量同步任务运行器(函数式状态机执行核心,cli/desktop 直接消费,非 Port)",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "lzi-builder",
|
|
19
|
+
"build:prod": "NODE_ENV=production bun run build",
|
|
20
|
+
"prepublishOnly": "bun run build:prod",
|
|
21
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
22
|
+
"typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
|
|
23
|
+
"typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
|
|
24
|
+
"typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
|
|
25
|
+
"lint": "oxlint && oxfmt --check",
|
|
26
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
27
|
+
"test": "bun test",
|
|
28
|
+
"test:watch": "bun test --watch",
|
|
29
|
+
"test:coverage": "bun test --coverage",
|
|
30
|
+
"clean": "lzi-dev-cli clean"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@longzai-intelligence-git/core": "0.0.1",
|
|
34
|
+
"@longzai-intelligence-git/massive-sync-pipeline": "0.0.1"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"zod": "^4.4.3"
|
|
38
|
+
}
|
|
39
|
+
}
|