farseer-cli 1.0.9 → 1.0.10
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/commands/app.js +344 -316
- package/dist/commands/apps.js +83 -103
- package/dist/commands/checkout.js +156 -134
- package/dist/commands/config.js +126 -124
- package/dist/commands/diff.js +194 -169
- package/dist/commands/dimensions.js +122 -137
- package/dist/commands/files.js +77 -88
- package/dist/commands/install.js +77 -74
- package/dist/commands/list.js +74 -89
- package/dist/commands/login.js +101 -126
- package/dist/commands/logout.js +42 -57
- package/dist/commands/mcp-server.js +24 -39
- package/dist/commands/model.js +176 -184
- package/dist/commands/pull.js +276 -248
- package/dist/commands/push.js +222 -200
- package/dist/commands/run.js +322 -274
- package/dist/commands/status.js +170 -147
- package/dist/commands/variables.js +192 -168
- package/dist/commands/whoami.js +45 -61
- package/dist/index.js +115 -117
- package/dist/mcp/index.js +17 -33
- package/dist/mcp/prompts/workflows.js +146 -191
- package/dist/mcp/resources/documentation.js +149 -158
- package/dist/mcp/server.js +34 -50
- package/dist/mcp/tools/appTools.js +278 -307
- package/dist/mcp/tools/authTools.js +123 -130
- package/dist/mcp/tools/dataTools.js +271 -275
- package/dist/mcp/tools/modelTools.js +233 -265
- package/dist/mcp/tools/runTools.js +205 -199
- package/dist/mcp/tools/syncTools.js +315 -341
- package/dist/mcp/utils/helpers.js +124 -117
- package/dist/services/appSyncService.js +438 -379
- package/dist/services/configService.js +144 -154
- package/dist/services/farseerApi.js +401 -401
- package/dist/services/farseerFactory.js +274 -208
- package/dist/services/farseerService.js +488 -455
- package/dist/services/syncService.js +732 -657
- package/dist/utils/constants.js +20 -45
- package/dist/utils/helpers.js +366 -333
- package/dist/utils/logger.js +43 -74
- package/package.json +8 -1
- package/dist/commands/app.js.map +0 -7
- package/dist/commands/apps.js.map +0 -7
- package/dist/commands/checkout.js.map +0 -7
- package/dist/commands/config.js.map +0 -7
- package/dist/commands/diff.js.map +0 -7
- package/dist/commands/dimensions.js.map +0 -7
- package/dist/commands/files.js.map +0 -7
- package/dist/commands/install.js.map +0 -7
- package/dist/commands/list.js.map +0 -7
- package/dist/commands/login.js.map +0 -7
- package/dist/commands/logout.js.map +0 -7
- package/dist/commands/mcp-server.js.map +0 -7
- package/dist/commands/model.js.map +0 -7
- package/dist/commands/pull.js.map +0 -7
- package/dist/commands/push.js.map +0 -7
- package/dist/commands/run.js.map +0 -7
- package/dist/commands/status.js.map +0 -7
- package/dist/commands/variables.js.map +0 -7
- package/dist/commands/whoami.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/mcp/index.js.map +0 -7
- package/dist/mcp/prompts/workflows.js.map +0 -7
- package/dist/mcp/resources/documentation.js.map +0 -7
- package/dist/mcp/server.js.map +0 -7
- package/dist/mcp/tools/appTools.js.map +0 -7
- package/dist/mcp/tools/authTools.js.map +0 -7
- package/dist/mcp/tools/dataTools.js.map +0 -7
- package/dist/mcp/tools/modelTools.js.map +0 -7
- package/dist/mcp/tools/runTools.js.map +0 -7
- package/dist/mcp/tools/syncTools.js.map +0 -7
- package/dist/mcp/utils/helpers.js.map +0 -7
- package/dist/services/appSyncService.js.map +0 -7
- package/dist/services/configService.js.map +0 -7
- package/dist/services/farseerApi.js.map +0 -7
- package/dist/services/farseerFactory.js.map +0 -7
- package/dist/services/farseerService.js.map +0 -7
- package/dist/services/syncService.js.map +0 -7
- package/dist/utils/constants.js.map +0 -7
- package/dist/utils/helpers.js.map +0 -7
- package/dist/utils/logger.js.map +0 -7
|
@@ -1,689 +1,764 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var syncService_exports = {};
|
|
29
|
-
__export(syncService_exports, {
|
|
30
|
-
SyncService: () => SyncService
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
31
17
|
});
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SyncService = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const farseerFactory_1 = require("./farseerFactory");
|
|
40
|
+
const helpers_1 = require("../utils/helpers");
|
|
41
|
+
const logger_1 = require("../utils/logger");
|
|
38
42
|
class SyncService {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
loadSyncState() {
|
|
44
|
-
const syncFilePath = (0, import_helpers.getSyncFilePath)(this.tenant);
|
|
45
|
-
if (!fs.existsSync(syncFilePath)) {
|
|
46
|
-
return {
|
|
47
|
-
lastSync: "",
|
|
48
|
-
files: {}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const content = fs.readFileSync(syncFilePath, "utf-8");
|
|
53
|
-
return JSON.parse(content);
|
|
54
|
-
} catch {
|
|
55
|
-
return {
|
|
56
|
-
lastSync: "",
|
|
57
|
-
files: {}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
saveSyncState(state) {
|
|
62
|
-
const syncFilePath = (0, import_helpers.getSyncFilePath)(this.tenant);
|
|
63
|
-
(0, import_helpers.ensureDirectoryExists)(path.dirname(syncFilePath));
|
|
64
|
-
fs.writeFileSync(syncFilePath, JSON.stringify(state, null, 2), "utf-8");
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Fast status check that uses sync state instead of downloading remote file content.
|
|
68
|
-
* This is much faster than getStatus() but may miss changes made by others since last pull.
|
|
69
|
-
* Use this for push operations where we trust the sync state.
|
|
70
|
-
*/
|
|
71
|
-
async getStatusFast(options) {
|
|
72
|
-
const syncState = this.loadSyncState();
|
|
73
|
-
const filesDir = (0, import_helpers.getTenantFilesDir)(this.tenant);
|
|
74
|
-
let localFiles = (0, import_helpers.getAllFilesInDir)(filesDir);
|
|
75
|
-
if (!options?.all) {
|
|
76
|
-
localFiles = localFiles.filter(
|
|
77
|
-
(f) => import_farseerFactory.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.toLowerCase().endsWith(ext))
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
let remoteFiles = await this.farseerClient.listFiles();
|
|
81
|
-
if (!options?.all) {
|
|
82
|
-
remoteFiles = remoteFiles.filter(
|
|
83
|
-
(f) => import_farseerFactory.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.name.toLowerCase().endsWith(ext))
|
|
84
|
-
);
|
|
43
|
+
constructor(tenant, farseerClient) {
|
|
44
|
+
this.tenant = tenant;
|
|
45
|
+
this.farseerClient = farseerClient;
|
|
85
46
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
conflicts: []
|
|
94
|
-
};
|
|
95
|
-
for (const localFile of localFiles) {
|
|
96
|
-
const localPath = path.join(filesDir, localFile);
|
|
97
|
-
const content = fs.readFileSync(localPath);
|
|
98
|
-
const localHash = (0, import_helpers.calculateHash)(content);
|
|
99
|
-
const syncInfo = syncState.files[localFile];
|
|
100
|
-
if (remoteFilePaths.has(localFile)) {
|
|
101
|
-
if (syncInfo && localHash === syncInfo.localHash) {
|
|
102
|
-
status.inSync.push(localFile);
|
|
103
|
-
} else {
|
|
104
|
-
status.modifiedLocally.push(localFile);
|
|
47
|
+
loadSyncState() {
|
|
48
|
+
const syncFilePath = (0, helpers_1.getSyncFilePath)(this.tenant);
|
|
49
|
+
if (!fs.existsSync(syncFilePath)) {
|
|
50
|
+
return {
|
|
51
|
+
lastSync: '',
|
|
52
|
+
files: {},
|
|
53
|
+
};
|
|
105
54
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
status.conflicts.push({
|
|
110
|
-
filePath: localFile,
|
|
111
|
-
type: "local_modified_remote_deleted",
|
|
112
|
-
description: "File modified locally but deleted on remote"
|
|
113
|
-
});
|
|
114
|
-
} else {
|
|
115
|
-
status.modifiedRemotely.push(localFile);
|
|
116
|
-
}
|
|
117
|
-
} else {
|
|
118
|
-
status.onlyLocal.push(localFile);
|
|
55
|
+
try {
|
|
56
|
+
const content = fs.readFileSync(syncFilePath, 'utf-8');
|
|
57
|
+
return JSON.parse(content);
|
|
119
58
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (syncInfo && syncInfo.localHash) {
|
|
126
|
-
status.modifiedLocally.push(remoteFile.path);
|
|
127
|
-
} else {
|
|
128
|
-
status.onlyRemote.push(remoteFile.path);
|
|
59
|
+
catch {
|
|
60
|
+
return {
|
|
61
|
+
lastSync: '',
|
|
62
|
+
files: {},
|
|
63
|
+
};
|
|
129
64
|
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return status;
|
|
133
|
-
}
|
|
134
|
-
async getStatus(options) {
|
|
135
|
-
const syncState = this.loadSyncState();
|
|
136
|
-
const filesDir = (0, import_helpers.getTenantFilesDir)(this.tenant);
|
|
137
|
-
let localFiles = (0, import_helpers.getAllFilesInDir)(filesDir);
|
|
138
|
-
if (!options?.all) {
|
|
139
|
-
localFiles = localFiles.filter(
|
|
140
|
-
(f) => import_farseerFactory.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.toLowerCase().endsWith(ext))
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
const localHashes = /* @__PURE__ */ new Map();
|
|
144
|
-
for (const file of localFiles) {
|
|
145
|
-
const fullPath = path.join(filesDir, file);
|
|
146
|
-
const content = fs.readFileSync(fullPath);
|
|
147
|
-
localHashes.set(file, (0, import_helpers.calculateHash)(content));
|
|
148
65
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
(
|
|
153
|
-
);
|
|
66
|
+
saveSyncState(state) {
|
|
67
|
+
const syncFilePath = (0, helpers_1.getSyncFilePath)(this.tenant);
|
|
68
|
+
(0, helpers_1.ensureDirectoryExists)(path.dirname(syncFilePath));
|
|
69
|
+
fs.writeFileSync(syncFilePath, JSON.stringify(state, null, 2), 'utf-8');
|
|
154
70
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const status = {
|
|
169
|
-
modifiedLocally: [],
|
|
170
|
-
modifiedRemotely: [],
|
|
171
|
-
onlyLocal: [],
|
|
172
|
-
onlyRemote: [],
|
|
173
|
-
inSync: [],
|
|
174
|
-
conflicts: []
|
|
175
|
-
};
|
|
176
|
-
for (const c of comparisons) {
|
|
177
|
-
switch (c.changeType) {
|
|
178
|
-
case "unchanged":
|
|
179
|
-
status.inSync.push(c.filePath);
|
|
180
|
-
break;
|
|
181
|
-
case "local_modified":
|
|
182
|
-
status.modifiedLocally.push(c.filePath);
|
|
183
|
-
break;
|
|
184
|
-
case "remote_modified":
|
|
185
|
-
status.modifiedRemotely.push(c.filePath);
|
|
186
|
-
break;
|
|
187
|
-
case "local_new":
|
|
188
|
-
status.onlyLocal.push(c.filePath);
|
|
189
|
-
break;
|
|
190
|
-
case "remote_new":
|
|
191
|
-
status.onlyRemote.push(c.filePath);
|
|
192
|
-
break;
|
|
193
|
-
case "remote_deleted":
|
|
194
|
-
status.modifiedRemotely.push(c.filePath);
|
|
195
|
-
break;
|
|
196
|
-
case "local_deleted":
|
|
197
|
-
status.modifiedLocally.push(c.filePath);
|
|
198
|
-
break;
|
|
199
|
-
default:
|
|
200
|
-
status.conflicts.push(
|
|
201
|
-
SyncService.buildConflicts([c])[0]
|
|
202
|
-
);
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return status;
|
|
207
|
-
}
|
|
208
|
-
async pull(options) {
|
|
209
|
-
const filesDir = (0, import_helpers.getTenantFilesDir)(this.tenant);
|
|
210
|
-
(0, import_helpers.ensureDirectoryExists)(filesDir);
|
|
211
|
-
const syncState = this.loadSyncState();
|
|
212
|
-
let remoteFiles = await this.farseerClient.listFiles();
|
|
213
|
-
if (!options?.all) {
|
|
214
|
-
remoteFiles = remoteFiles.filter(
|
|
215
|
-
(f) => import_farseerFactory.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.name.toLowerCase().endsWith(ext))
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
remoteFiles = await this.fetchMetadataForFiles(remoteFiles);
|
|
219
|
-
const result = {
|
|
220
|
-
downloaded: [],
|
|
221
|
-
deleted: [],
|
|
222
|
-
unchanged: [],
|
|
223
|
-
conflicts: [],
|
|
224
|
-
conflictFilesWritten: []
|
|
225
|
-
};
|
|
226
|
-
import_logger.logger.dim(`Fetching ${remoteFiles.length} files in parallel...`);
|
|
227
|
-
const fileContents = await (0, import_helpers.fetchWithConcurrency)(
|
|
228
|
-
remoteFiles,
|
|
229
|
-
async (file, index) => {
|
|
230
|
-
const content = await this.farseerClient.getFileContentAsBuffer(file.reference);
|
|
231
|
-
if ((index + 1) % 10 === 0 || index === remoteFiles.length - 1) {
|
|
232
|
-
process.stdout.write(`\r Progress: ${index + 1}/${remoteFiles.length} files`);
|
|
71
|
+
/**
|
|
72
|
+
* Fast status check that uses sync state instead of downloading remote file content.
|
|
73
|
+
* This is much faster than getStatus() but may miss changes made by others since last pull.
|
|
74
|
+
* Use this for push operations where we trust the sync state.
|
|
75
|
+
*/
|
|
76
|
+
async getStatusFast(options) {
|
|
77
|
+
const syncState = this.loadSyncState();
|
|
78
|
+
const filesDir = (0, helpers_1.getTenantFilesDir)(this.tenant);
|
|
79
|
+
// Get local files
|
|
80
|
+
let localFiles = (0, helpers_1.getAllFilesInDir)(filesDir);
|
|
81
|
+
// Filter to scripts only unless --all is specified
|
|
82
|
+
if (!options?.all) {
|
|
83
|
+
localFiles = localFiles.filter((f) => farseerFactory_1.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.toLowerCase().endsWith(ext)));
|
|
233
84
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
case "unchanged":
|
|
266
|
-
case "local_modified":
|
|
267
|
-
case "local_new":
|
|
268
|
-
result.unchanged.push(filePath);
|
|
269
|
-
if (remoteInfo) {
|
|
270
|
-
const existingSync = syncState.files[filePath];
|
|
271
|
-
if (existingSync) {
|
|
272
|
-
existingSync.remoteHash = remoteInfo.hash;
|
|
273
|
-
existingSync.metadata = this.buildMetadata(remoteInfo.file);
|
|
85
|
+
// Get remote file list only (no content download)
|
|
86
|
+
let remoteFiles = await this.farseerClient.listFiles();
|
|
87
|
+
// Filter to scripts only unless --all is specified
|
|
88
|
+
if (!options?.all) {
|
|
89
|
+
remoteFiles = remoteFiles.filter((f) => farseerFactory_1.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.name.toLowerCase().endsWith(ext)));
|
|
90
|
+
}
|
|
91
|
+
const remoteFilePaths = new Set(remoteFiles.map((f) => f.path));
|
|
92
|
+
const status = {
|
|
93
|
+
modifiedLocally: [],
|
|
94
|
+
modifiedRemotely: [],
|
|
95
|
+
onlyLocal: [],
|
|
96
|
+
onlyRemote: [],
|
|
97
|
+
inSync: [],
|
|
98
|
+
conflicts: [],
|
|
99
|
+
};
|
|
100
|
+
// Check local files
|
|
101
|
+
for (const localFile of localFiles) {
|
|
102
|
+
const localPath = path.join(filesDir, localFile);
|
|
103
|
+
const content = fs.readFileSync(localPath);
|
|
104
|
+
const localHash = (0, helpers_1.calculateHash)(content);
|
|
105
|
+
const syncInfo = syncState.files[localFile];
|
|
106
|
+
if (remoteFilePaths.has(localFile)) {
|
|
107
|
+
// File exists both locally and remotely
|
|
108
|
+
if (syncInfo && localHash === syncInfo.localHash) {
|
|
109
|
+
// Local file hasn't changed since last sync
|
|
110
|
+
status.inSync.push(localFile);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Local file changed (or no sync info)
|
|
114
|
+
status.modifiedLocally.push(localFile);
|
|
115
|
+
}
|
|
274
116
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
result.deleted.push(filePath);
|
|
296
|
-
delete syncState.files[filePath];
|
|
297
|
-
break;
|
|
298
|
-
case "conflict_both_modified":
|
|
299
|
-
case "conflict_local_modified_remote_deleted":
|
|
300
|
-
case "conflict_local_deleted_remote_modified":
|
|
301
|
-
case "conflict_both_new": {
|
|
302
|
-
if (options?.force) {
|
|
303
|
-
if (remoteInfo) {
|
|
304
|
-
(0, import_helpers.ensureDirectoryExists)(path.dirname(localPath));
|
|
305
|
-
fs.writeFileSync(localPath, remoteInfo.content);
|
|
306
|
-
result.downloaded.push(filePath);
|
|
307
|
-
syncState.files[filePath] = {
|
|
308
|
-
localHash: remoteInfo.hash,
|
|
309
|
-
remoteHash: remoteInfo.hash,
|
|
310
|
-
metadata: this.buildMetadata(remoteInfo.file)
|
|
311
|
-
};
|
|
312
|
-
} else {
|
|
313
|
-
if (fs.existsSync(localPath)) {
|
|
314
|
-
fs.unlinkSync(localPath);
|
|
315
|
-
result.deleted.push(filePath);
|
|
316
|
-
}
|
|
317
|
-
delete syncState.files[filePath];
|
|
117
|
+
else {
|
|
118
|
+
// File only exists locally
|
|
119
|
+
if (syncInfo && syncInfo.remoteHash) {
|
|
120
|
+
// Was synced before, deleted on remote
|
|
121
|
+
if (localHash !== syncInfo.localHash) {
|
|
122
|
+
// Local also modified - CONFLICT
|
|
123
|
+
status.conflicts.push({
|
|
124
|
+
filePath: localFile,
|
|
125
|
+
type: 'local_modified_remote_deleted',
|
|
126
|
+
description: 'File modified locally but deleted on remote',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// Local unchanged, safe to mark as remote change
|
|
131
|
+
status.modifiedRemotely.push(localFile);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
status.onlyLocal.push(localFile);
|
|
136
|
+
}
|
|
318
137
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
case "keep_local":
|
|
328
|
-
if (fs.existsSync(localPath)) {
|
|
329
|
-
const localContent = fs.readFileSync(localPath);
|
|
330
|
-
const localHash = (0, import_helpers.calculateHash)(localContent);
|
|
331
|
-
syncState.files[filePath] = {
|
|
332
|
-
localHash,
|
|
333
|
-
remoteHash: comparison.currentRemoteHash ?? "",
|
|
334
|
-
metadata: remoteInfo ? this.buildMetadata(remoteInfo.file) : void 0
|
|
335
|
-
};
|
|
336
|
-
} else {
|
|
337
|
-
delete syncState.files[filePath];
|
|
338
|
-
}
|
|
339
|
-
result.unchanged.push(filePath);
|
|
340
|
-
break;
|
|
341
|
-
case "keep_remote":
|
|
342
|
-
if (remoteInfo) {
|
|
343
|
-
(0, import_helpers.ensureDirectoryExists)(path.dirname(localPath));
|
|
344
|
-
fs.writeFileSync(localPath, remoteInfo.content);
|
|
345
|
-
result.downloaded.push(filePath);
|
|
346
|
-
syncState.files[filePath] = {
|
|
347
|
-
localHash: remoteInfo.hash,
|
|
348
|
-
remoteHash: remoteInfo.hash,
|
|
349
|
-
metadata: this.buildMetadata(remoteInfo.file)
|
|
350
|
-
};
|
|
351
|
-
} else {
|
|
352
|
-
if (fs.existsSync(localPath)) {
|
|
353
|
-
fs.unlinkSync(localPath);
|
|
354
|
-
result.deleted.push(filePath);
|
|
138
|
+
}
|
|
139
|
+
// Check remote files that don't exist locally
|
|
140
|
+
for (const remoteFile of remoteFiles) {
|
|
141
|
+
if (!localFiles.includes(remoteFile.path)) {
|
|
142
|
+
const syncInfo = syncState.files[remoteFile.path];
|
|
143
|
+
if (syncInfo && syncInfo.localHash) {
|
|
144
|
+
// Was synced before, deleted locally
|
|
145
|
+
status.modifiedLocally.push(remoteFile.path);
|
|
355
146
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (remoteInfo) {
|
|
361
|
-
const ext = path.extname(filePath);
|
|
362
|
-
const base = filePath.slice(0, -ext.length || void 0);
|
|
363
|
-
const conflictFileName = `${base}.remote${ext}`;
|
|
364
|
-
const conflictPath = path.join(filesDir, conflictFileName);
|
|
365
|
-
(0, import_helpers.ensureDirectoryExists)(path.dirname(conflictPath));
|
|
366
|
-
fs.writeFileSync(conflictPath, remoteInfo.content);
|
|
367
|
-
result.conflictFilesWritten.push(conflictFileName);
|
|
368
|
-
}
|
|
369
|
-
if (fs.existsSync(localPath)) {
|
|
370
|
-
const localContent = fs.readFileSync(localPath);
|
|
371
|
-
const localHash = (0, import_helpers.calculateHash)(localContent);
|
|
372
|
-
syncState.files[filePath] = {
|
|
373
|
-
localHash,
|
|
374
|
-
remoteHash: comparison.currentRemoteHash ?? "",
|
|
375
|
-
metadata: remoteInfo ? this.buildMetadata(remoteInfo.file) : void 0
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
result.unchanged.push(filePath);
|
|
379
|
-
break;
|
|
380
|
-
}
|
|
381
|
-
break;
|
|
147
|
+
else {
|
|
148
|
+
status.onlyRemote.push(remoteFile.path);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
382
151
|
}
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
syncState.lastSync = (/* @__PURE__ */ new Date()).toISOString();
|
|
386
|
-
this.saveSyncState(syncState);
|
|
387
|
-
return result;
|
|
388
|
-
}
|
|
389
|
-
buildMetadata(file) {
|
|
390
|
-
if (!file.metadata) return void 0;
|
|
391
|
-
return {
|
|
392
|
-
uploadTime: file.metadata.uploadTime,
|
|
393
|
-
uploaderEmail: file.metadata.uploader?.email,
|
|
394
|
-
uploaderName: file.metadata.uploader ? `${file.metadata.uploader.firstName} ${file.metadata.uploader.lastName}`.trim() : void 0,
|
|
395
|
-
lastFetched: (/* @__PURE__ */ new Date()).toISOString()
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
async push(options) {
|
|
399
|
-
const filesDir = (0, import_helpers.getTenantFilesDir)(this.tenant);
|
|
400
|
-
const syncState = this.loadSyncState();
|
|
401
|
-
const result = {
|
|
402
|
-
uploaded: [],
|
|
403
|
-
updated: [],
|
|
404
|
-
deleted: [],
|
|
405
|
-
unchanged: [],
|
|
406
|
-
conflicts: []
|
|
407
|
-
};
|
|
408
|
-
const remoteFiles = await this.farseerClient.listFiles();
|
|
409
|
-
const remoteFileMap = /* @__PURE__ */ new Map();
|
|
410
|
-
for (const file of remoteFiles) {
|
|
411
|
-
remoteFileMap.set(file.path, file);
|
|
412
|
-
}
|
|
413
|
-
const localFiles = (0, import_helpers.getAllFilesInDir)(filesDir);
|
|
414
|
-
const localHashes = /* @__PURE__ */ new Map();
|
|
415
|
-
const localContents = /* @__PURE__ */ new Map();
|
|
416
|
-
for (const localFile of localFiles) {
|
|
417
|
-
const localPath = path.join(filesDir, localFile);
|
|
418
|
-
const content = fs.readFileSync(localPath);
|
|
419
|
-
localHashes.set(localFile, (0, import_helpers.calculateHash)(content));
|
|
420
|
-
localContents.set(localFile, content);
|
|
152
|
+
return status;
|
|
421
153
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (
|
|
428
|
-
|
|
154
|
+
async getStatus(options) {
|
|
155
|
+
const syncState = this.loadSyncState();
|
|
156
|
+
const filesDir = (0, helpers_1.getTenantFilesDir)(this.tenant);
|
|
157
|
+
// Get local files and their hashes
|
|
158
|
+
let localFiles = (0, helpers_1.getAllFilesInDir)(filesDir);
|
|
159
|
+
if (!options?.all) {
|
|
160
|
+
localFiles = localFiles.filter((f) => farseerFactory_1.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.toLowerCase().endsWith(ext)));
|
|
429
161
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const filesToFetchRemote = [.../* @__PURE__ */ new Set([...candidateFiles, ...locallyDeletedFiles])];
|
|
436
|
-
const remoteHashes = /* @__PURE__ */ new Map();
|
|
437
|
-
if (filesToFetchRemote.length > 0 && !options?.force) {
|
|
438
|
-
const toFetch = filesToFetchRemote.filter((f) => remoteFileMap.has(f)).map((f) => remoteFileMap.get(f));
|
|
439
|
-
const fetched = await (0, import_helpers.fetchWithConcurrency)(toFetch, async (file) => {
|
|
440
|
-
const content = await this.farseerClient.getFileContentAsBuffer(file.reference);
|
|
441
|
-
return { file, hash: (0, import_helpers.calculateHash)(content) };
|
|
442
|
-
}, 15);
|
|
443
|
-
for (const { file, hash } of fetched) {
|
|
444
|
-
remoteHashes.set(file.path, hash);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
const comparisons = this.compareFiles({ localHashes, remoteHashes, syncState, all: true });
|
|
448
|
-
const conflictPaths = /* @__PURE__ */ new Set();
|
|
449
|
-
if (!options?.force) {
|
|
450
|
-
for (const c of comparisons) {
|
|
451
|
-
if (c.changeType.startsWith("conflict_")) {
|
|
452
|
-
const conflict = SyncService.buildConflicts([c])[0];
|
|
453
|
-
result.conflicts.push(conflict);
|
|
454
|
-
conflictPaths.add(c.filePath);
|
|
162
|
+
const localHashes = new Map();
|
|
163
|
+
for (const file of localFiles) {
|
|
164
|
+
const fullPath = path.join(filesDir, file);
|
|
165
|
+
const content = fs.readFileSync(fullPath);
|
|
166
|
+
localHashes.set(file, (0, helpers_1.calculateHash)(content));
|
|
455
167
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
const localPath = path.join(filesDir, localFile);
|
|
461
|
-
const content = localContents.get(localFile);
|
|
462
|
-
const localHash = localHashes.get(localFile);
|
|
463
|
-
const remoteFile = remoteFileMap.get(localFile);
|
|
464
|
-
const syncInfo = syncState.files[localFile];
|
|
465
|
-
if (remoteFile) {
|
|
466
|
-
if (syncInfo && localHash === syncInfo.localHash) {
|
|
467
|
-
result.unchanged.push(localFile);
|
|
468
|
-
} else {
|
|
469
|
-
await this.farseerClient.updateFile(remoteFile.reference, content, path.basename(localFile));
|
|
470
|
-
result.updated.push(localFile);
|
|
471
|
-
syncState.files[localFile] = {
|
|
472
|
-
localHash,
|
|
473
|
-
remoteHash: localHash
|
|
474
|
-
};
|
|
168
|
+
// Get remote files and their hashes
|
|
169
|
+
let remoteFiles = await this.farseerClient.listFiles();
|
|
170
|
+
if (!options?.all) {
|
|
171
|
+
remoteFiles = remoteFiles.filter((f) => farseerFactory_1.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.name.toLowerCase().endsWith(ext)));
|
|
475
172
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
await this.farseerClient.createFile(content, fileName, folderPath);
|
|
484
|
-
result.uploaded.push(localFile);
|
|
485
|
-
syncState.files[localFile] = {
|
|
486
|
-
localHash,
|
|
487
|
-
remoteHash: localHash
|
|
488
|
-
};
|
|
173
|
+
const remoteHashes = new Map();
|
|
174
|
+
const fileContents = await (0, helpers_1.fetchWithConcurrency)(remoteFiles, async (file) => {
|
|
175
|
+
const content = await this.farseerClient.getFileContentAsBuffer(file.reference);
|
|
176
|
+
return { path: file.path, hash: (0, helpers_1.calculateHash)(content) };
|
|
177
|
+
}, 15);
|
|
178
|
+
for (const { path: filePath, hash } of fileContents) {
|
|
179
|
+
remoteHashes.set(filePath, hash);
|
|
489
180
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
181
|
+
// Three-way comparison
|
|
182
|
+
const comparisons = this.compareFiles({ localHashes, remoteHashes, syncState, all: options?.all });
|
|
183
|
+
const status = {
|
|
184
|
+
modifiedLocally: [],
|
|
185
|
+
modifiedRemotely: [],
|
|
186
|
+
onlyLocal: [],
|
|
187
|
+
onlyRemote: [],
|
|
188
|
+
inSync: [],
|
|
189
|
+
conflicts: [],
|
|
190
|
+
};
|
|
191
|
+
for (const c of comparisons) {
|
|
192
|
+
switch (c.changeType) {
|
|
193
|
+
case 'unchanged':
|
|
194
|
+
status.inSync.push(c.filePath);
|
|
195
|
+
break;
|
|
196
|
+
case 'local_modified':
|
|
197
|
+
status.modifiedLocally.push(c.filePath);
|
|
198
|
+
break;
|
|
199
|
+
case 'remote_modified':
|
|
200
|
+
status.modifiedRemotely.push(c.filePath);
|
|
201
|
+
break;
|
|
202
|
+
case 'local_new':
|
|
203
|
+
status.onlyLocal.push(c.filePath);
|
|
204
|
+
break;
|
|
205
|
+
case 'remote_new':
|
|
206
|
+
status.onlyRemote.push(c.filePath);
|
|
207
|
+
break;
|
|
208
|
+
case 'remote_deleted':
|
|
209
|
+
status.modifiedRemotely.push(c.filePath);
|
|
210
|
+
break;
|
|
211
|
+
case 'local_deleted':
|
|
212
|
+
status.modifiedLocally.push(c.filePath);
|
|
213
|
+
break;
|
|
214
|
+
default:
|
|
215
|
+
// All conflict types
|
|
216
|
+
status.conflicts.push(SyncService.buildConflicts([c])[0]);
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
500
219
|
}
|
|
501
|
-
|
|
502
|
-
}
|
|
503
|
-
syncState.lastSync = (/* @__PURE__ */ new Date()).toISOString();
|
|
504
|
-
this.saveSyncState(syncState);
|
|
505
|
-
return result;
|
|
506
|
-
}
|
|
507
|
-
async checkRemoteChanges() {
|
|
508
|
-
const syncState = this.loadSyncState();
|
|
509
|
-
let remoteFiles = await this.farseerClient.listFiles();
|
|
510
|
-
remoteFiles = remoteFiles.filter(
|
|
511
|
-
(f) => import_farseerFactory.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.name.toLowerCase().endsWith(ext))
|
|
512
|
-
);
|
|
513
|
-
for (const file of remoteFiles) {
|
|
514
|
-
const syncInfo = syncState.files[file.path];
|
|
515
|
-
if (!syncInfo) {
|
|
516
|
-
return true;
|
|
517
|
-
}
|
|
220
|
+
return status;
|
|
518
221
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
222
|
+
async pull(options) {
|
|
223
|
+
const filesDir = (0, helpers_1.getTenantFilesDir)(this.tenant);
|
|
224
|
+
(0, helpers_1.ensureDirectoryExists)(filesDir);
|
|
225
|
+
const syncState = this.loadSyncState();
|
|
226
|
+
let remoteFiles = await this.farseerClient.listFiles();
|
|
227
|
+
// Filter to scripts only unless --all is specified
|
|
228
|
+
if (!options?.all) {
|
|
229
|
+
remoteFiles = remoteFiles.filter((f) => farseerFactory_1.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.name.toLowerCase().endsWith(ext)));
|
|
230
|
+
}
|
|
231
|
+
// Batch fetch metadata for all files
|
|
232
|
+
remoteFiles = await this.fetchMetadataForFiles(remoteFiles);
|
|
233
|
+
const result = {
|
|
234
|
+
downloaded: [],
|
|
235
|
+
deleted: [],
|
|
236
|
+
unchanged: [],
|
|
237
|
+
conflicts: [],
|
|
238
|
+
conflictFilesWritten: [],
|
|
239
|
+
};
|
|
240
|
+
// Download file contents in parallel with concurrency limit
|
|
241
|
+
logger_1.logger.dim(`Fetching ${remoteFiles.length} files in parallel...`);
|
|
242
|
+
const fileContents = await (0, helpers_1.fetchWithConcurrency)(remoteFiles, async (file, index) => {
|
|
243
|
+
const content = await this.farseerClient.getFileContentAsBuffer(file.reference);
|
|
244
|
+
// Show progress every 10 files
|
|
245
|
+
if ((index + 1) % 10 === 0 || index === remoteFiles.length - 1) {
|
|
246
|
+
process.stdout.write(`\r Progress: ${index + 1}/${remoteFiles.length} files`);
|
|
247
|
+
}
|
|
248
|
+
return { file, content };
|
|
249
|
+
}, 15);
|
|
250
|
+
// Clear progress line
|
|
251
|
+
if (remoteFiles.length > 0) {
|
|
252
|
+
process.stdout.write('\r' + ' '.repeat(50) + '\r');
|
|
253
|
+
}
|
|
254
|
+
// Build remote content map with hashes
|
|
255
|
+
const remoteContentMap = new Map();
|
|
256
|
+
const remoteHashes = new Map();
|
|
257
|
+
for (const { file, content } of fileContents) {
|
|
258
|
+
const hash = (0, helpers_1.calculateHash)(content);
|
|
259
|
+
remoteContentMap.set(file.path, { file, content, hash });
|
|
260
|
+
remoteHashes.set(file.path, hash);
|
|
261
|
+
}
|
|
262
|
+
// Build local hashes
|
|
263
|
+
const localFiles = (0, helpers_1.getAllFilesInDir)(filesDir);
|
|
264
|
+
const localHashes = new Map();
|
|
265
|
+
for (const localFile of localFiles) {
|
|
266
|
+
if (!options?.all && !farseerFactory_1.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => localFile.toLowerCase().endsWith(ext))) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const localPath = path.join(filesDir, localFile);
|
|
270
|
+
const content = fs.readFileSync(localPath);
|
|
271
|
+
localHashes.set(localFile, (0, helpers_1.calculateHash)(content));
|
|
272
|
+
}
|
|
273
|
+
// Three-way comparison
|
|
274
|
+
const comparisons = this.compareFiles({ localHashes, remoteHashes, syncState, all: options?.all });
|
|
275
|
+
const resolutions = options?.conflictResolutions ?? {};
|
|
276
|
+
for (const comparison of comparisons) {
|
|
277
|
+
const { filePath, changeType } = comparison;
|
|
278
|
+
const localPath = path.join(filesDir, filePath);
|
|
279
|
+
const remoteInfo = remoteContentMap.get(filePath);
|
|
280
|
+
switch (changeType) {
|
|
281
|
+
case 'unchanged':
|
|
282
|
+
case 'local_modified':
|
|
283
|
+
case 'local_new':
|
|
284
|
+
result.unchanged.push(filePath);
|
|
285
|
+
// Update sync state for remote side if we have remote info
|
|
286
|
+
if (remoteInfo) {
|
|
287
|
+
const existingSync = syncState.files[filePath];
|
|
288
|
+
if (existingSync) {
|
|
289
|
+
existingSync.remoteHash = remoteInfo.hash;
|
|
290
|
+
existingSync.metadata = this.buildMetadata(remoteInfo.file);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
break;
|
|
294
|
+
case 'local_deleted':
|
|
295
|
+
// Local deleted, remote unchanged - skip (push will handle)
|
|
296
|
+
result.unchanged.push(filePath);
|
|
297
|
+
break;
|
|
298
|
+
case 'remote_modified':
|
|
299
|
+
case 'remote_new':
|
|
300
|
+
// Safe to write
|
|
301
|
+
(0, helpers_1.ensureDirectoryExists)(path.dirname(localPath));
|
|
302
|
+
fs.writeFileSync(localPath, remoteInfo.content);
|
|
303
|
+
result.downloaded.push(filePath);
|
|
304
|
+
syncState.files[filePath] = {
|
|
305
|
+
localHash: remoteInfo.hash,
|
|
306
|
+
remoteHash: remoteInfo.hash,
|
|
307
|
+
metadata: this.buildMetadata(remoteInfo.file),
|
|
308
|
+
};
|
|
309
|
+
break;
|
|
310
|
+
case 'remote_deleted':
|
|
311
|
+
// Safe to delete (local is unchanged)
|
|
312
|
+
if (fs.existsSync(localPath)) {
|
|
313
|
+
fs.unlinkSync(localPath);
|
|
314
|
+
}
|
|
315
|
+
result.deleted.push(filePath);
|
|
316
|
+
delete syncState.files[filePath];
|
|
317
|
+
break;
|
|
318
|
+
case 'conflict_both_modified':
|
|
319
|
+
case 'conflict_local_modified_remote_deleted':
|
|
320
|
+
case 'conflict_local_deleted_remote_modified':
|
|
321
|
+
case 'conflict_both_new': {
|
|
322
|
+
if (options?.force) {
|
|
323
|
+
// Force: apply remote state
|
|
324
|
+
if (remoteInfo) {
|
|
325
|
+
(0, helpers_1.ensureDirectoryExists)(path.dirname(localPath));
|
|
326
|
+
fs.writeFileSync(localPath, remoteInfo.content);
|
|
327
|
+
result.downloaded.push(filePath);
|
|
328
|
+
syncState.files[filePath] = {
|
|
329
|
+
localHash: remoteInfo.hash,
|
|
330
|
+
remoteHash: remoteInfo.hash,
|
|
331
|
+
metadata: this.buildMetadata(remoteInfo.file),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
// Remote deleted, force means delete local
|
|
336
|
+
if (fs.existsSync(localPath)) {
|
|
337
|
+
fs.unlinkSync(localPath);
|
|
338
|
+
result.deleted.push(filePath);
|
|
339
|
+
}
|
|
340
|
+
delete syncState.files[filePath];
|
|
341
|
+
}
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
const resolution = resolutions[filePath];
|
|
345
|
+
if (!resolution) {
|
|
346
|
+
// No resolution provided - report conflict, skip file
|
|
347
|
+
result.conflicts.push(SyncService.buildConflicts([comparison])[0]);
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
switch (resolution) {
|
|
351
|
+
case 'keep_local':
|
|
352
|
+
// Keep local as-is, update sync state to mark conflict resolved
|
|
353
|
+
if (fs.existsSync(localPath)) {
|
|
354
|
+
const localContent = fs.readFileSync(localPath);
|
|
355
|
+
const localHash = (0, helpers_1.calculateHash)(localContent);
|
|
356
|
+
syncState.files[filePath] = {
|
|
357
|
+
localHash,
|
|
358
|
+
remoteHash: comparison.currentRemoteHash ?? '',
|
|
359
|
+
metadata: remoteInfo ? this.buildMetadata(remoteInfo.file) : undefined,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
// Local was deleted, user wants to keep that decision
|
|
364
|
+
delete syncState.files[filePath];
|
|
365
|
+
}
|
|
366
|
+
result.unchanged.push(filePath);
|
|
367
|
+
break;
|
|
368
|
+
case 'keep_remote':
|
|
369
|
+
if (remoteInfo) {
|
|
370
|
+
(0, helpers_1.ensureDirectoryExists)(path.dirname(localPath));
|
|
371
|
+
fs.writeFileSync(localPath, remoteInfo.content);
|
|
372
|
+
result.downloaded.push(filePath);
|
|
373
|
+
syncState.files[filePath] = {
|
|
374
|
+
localHash: remoteInfo.hash,
|
|
375
|
+
remoteHash: remoteInfo.hash,
|
|
376
|
+
metadata: this.buildMetadata(remoteInfo.file),
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
// Remote deleted
|
|
381
|
+
if (fs.existsSync(localPath)) {
|
|
382
|
+
fs.unlinkSync(localPath);
|
|
383
|
+
result.deleted.push(filePath);
|
|
384
|
+
}
|
|
385
|
+
delete syncState.files[filePath];
|
|
386
|
+
}
|
|
387
|
+
break;
|
|
388
|
+
case 'keep_both':
|
|
389
|
+
if (remoteInfo) {
|
|
390
|
+
// Write remote version as .remote file alongside local
|
|
391
|
+
const ext = path.extname(filePath);
|
|
392
|
+
const base = filePath.slice(0, -ext.length || undefined);
|
|
393
|
+
const conflictFileName = `${base}.remote${ext}`;
|
|
394
|
+
const conflictPath = path.join(filesDir, conflictFileName);
|
|
395
|
+
(0, helpers_1.ensureDirectoryExists)(path.dirname(conflictPath));
|
|
396
|
+
fs.writeFileSync(conflictPath, remoteInfo.content);
|
|
397
|
+
result.conflictFilesWritten.push(conflictFileName);
|
|
398
|
+
}
|
|
399
|
+
// Keep local, update sync state
|
|
400
|
+
if (fs.existsSync(localPath)) {
|
|
401
|
+
const localContent = fs.readFileSync(localPath);
|
|
402
|
+
const localHash = (0, helpers_1.calculateHash)(localContent);
|
|
403
|
+
syncState.files[filePath] = {
|
|
404
|
+
localHash,
|
|
405
|
+
remoteHash: comparison.currentRemoteHash ?? '',
|
|
406
|
+
metadata: remoteInfo ? this.buildMetadata(remoteInfo.file) : undefined,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
result.unchanged.push(filePath);
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
syncState.lastSync = new Date().toISOString();
|
|
417
|
+
this.saveSyncState(syncState);
|
|
418
|
+
return result;
|
|
526
419
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
420
|
+
buildMetadata(file) {
|
|
421
|
+
if (!file.metadata)
|
|
422
|
+
return undefined;
|
|
423
|
+
return {
|
|
424
|
+
uploadTime: file.metadata.uploadTime,
|
|
425
|
+
uploaderEmail: file.metadata.uploader?.email,
|
|
426
|
+
uploaderName: file.metadata.uploader
|
|
427
|
+
? `${file.metadata.uploader.firstName} ${file.metadata.uploader.lastName}`.trim()
|
|
428
|
+
: undefined,
|
|
429
|
+
lastFetched: new Date().toISOString(),
|
|
430
|
+
};
|
|
536
431
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
432
|
+
async push(options) {
|
|
433
|
+
const filesDir = (0, helpers_1.getTenantFilesDir)(this.tenant);
|
|
434
|
+
const syncState = this.loadSyncState();
|
|
435
|
+
const result = {
|
|
436
|
+
uploaded: [],
|
|
437
|
+
updated: [],
|
|
438
|
+
deleted: [],
|
|
439
|
+
unchanged: [],
|
|
440
|
+
conflicts: [],
|
|
441
|
+
};
|
|
442
|
+
// Get current remote files (just the list, not content)
|
|
443
|
+
const remoteFiles = await this.farseerClient.listFiles();
|
|
444
|
+
const remoteFileMap = new Map();
|
|
445
|
+
for (const file of remoteFiles) {
|
|
446
|
+
remoteFileMap.set(file.path, file);
|
|
447
|
+
}
|
|
448
|
+
// Get local files and hashes
|
|
449
|
+
const localFiles = (0, helpers_1.getAllFilesInDir)(filesDir);
|
|
450
|
+
const localHashes = new Map();
|
|
451
|
+
const localContents = new Map();
|
|
452
|
+
for (const localFile of localFiles) {
|
|
453
|
+
const localPath = path.join(filesDir, localFile);
|
|
454
|
+
const content = fs.readFileSync(localPath);
|
|
455
|
+
localHashes.set(localFile, (0, helpers_1.calculateHash)(content));
|
|
456
|
+
localContents.set(localFile, content);
|
|
457
|
+
}
|
|
458
|
+
// Identify candidates that need remote content check for conflict detection
|
|
459
|
+
const candidateFiles = [];
|
|
460
|
+
for (const localFile of localFiles) {
|
|
461
|
+
const syncInfo = syncState.files[localFile];
|
|
462
|
+
const localHash = localHashes.get(localFile);
|
|
463
|
+
if (!syncInfo || localHash !== syncInfo.localHash) {
|
|
464
|
+
// Changed or new locally
|
|
465
|
+
if (remoteFileMap.has(localFile)) {
|
|
466
|
+
candidateFiles.push(localFile);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
// Also check files in sync state that no longer exist locally (local deletions)
|
|
471
|
+
const locallyDeletedFiles = Object.keys(syncState.files).filter((f) => !localFiles.includes(f) && remoteFileMap.has(f));
|
|
472
|
+
const filesToFetchRemote = [...new Set([...candidateFiles, ...locallyDeletedFiles])];
|
|
473
|
+
// Fetch remote content for conflict detection
|
|
474
|
+
const remoteHashes = new Map();
|
|
475
|
+
if (filesToFetchRemote.length > 0 && !options?.force) {
|
|
476
|
+
const toFetch = filesToFetchRemote.filter((f) => remoteFileMap.has(f)).map((f) => remoteFileMap.get(f));
|
|
477
|
+
const fetched = await (0, helpers_1.fetchWithConcurrency)(toFetch, async (file) => {
|
|
478
|
+
const content = await this.farseerClient.getFileContentAsBuffer(file.reference);
|
|
479
|
+
return { file, hash: (0, helpers_1.calculateHash)(content) };
|
|
480
|
+
}, 15);
|
|
481
|
+
for (const { file, hash } of fetched) {
|
|
482
|
+
remoteHashes.set(file.path, hash);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
// Three-way comparison for conflict detection
|
|
486
|
+
const comparisons = this.compareFiles({ localHashes, remoteHashes, syncState, all: true });
|
|
487
|
+
const conflictPaths = new Set();
|
|
488
|
+
if (!options?.force) {
|
|
489
|
+
for (const c of comparisons) {
|
|
490
|
+
if (c.changeType.startsWith('conflict_')) {
|
|
491
|
+
const conflict = SyncService.buildConflicts([c])[0];
|
|
492
|
+
result.conflicts.push(conflict);
|
|
493
|
+
conflictPaths.add(c.filePath);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
// Process non-conflicting files
|
|
498
|
+
for (const localFile of localFiles) {
|
|
499
|
+
if (conflictPaths.has(localFile))
|
|
500
|
+
continue;
|
|
501
|
+
const localPath = path.join(filesDir, localFile);
|
|
502
|
+
const content = localContents.get(localFile);
|
|
503
|
+
const localHash = localHashes.get(localFile);
|
|
504
|
+
const remoteFile = remoteFileMap.get(localFile);
|
|
505
|
+
const syncInfo = syncState.files[localFile];
|
|
506
|
+
if (remoteFile) {
|
|
507
|
+
// File exists on remote - check if local changed since last sync
|
|
508
|
+
if (syncInfo && localHash === syncInfo.localHash) {
|
|
509
|
+
result.unchanged.push(localFile);
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
// Local file changed - needs update
|
|
513
|
+
await this.farseerClient.updateFile(remoteFile.reference, content, path.basename(localFile));
|
|
514
|
+
result.updated.push(localFile);
|
|
515
|
+
syncState.files[localFile] = {
|
|
516
|
+
localHash: localHash,
|
|
517
|
+
remoteHash: localHash,
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
// File doesn't exist on remote
|
|
523
|
+
if (syncInfo && localHash === syncInfo.localHash) {
|
|
524
|
+
// Local unchanged, was deleted on remote - skip (don't re-upload)
|
|
525
|
+
result.unchanged.push(localFile);
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
// New or modified local file - upload
|
|
529
|
+
const pathParts = localFile.split('/');
|
|
530
|
+
const fileName = pathParts.pop();
|
|
531
|
+
const folderPath = ['Files', ...pathParts];
|
|
532
|
+
await this.farseerClient.createFile(content, fileName, folderPath);
|
|
533
|
+
result.uploaded.push(localFile);
|
|
534
|
+
syncState.files[localFile] = {
|
|
535
|
+
localHash: localHash,
|
|
536
|
+
remoteHash: localHash,
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
// Delete files on remote that were deleted locally (non-conflicting only)
|
|
542
|
+
const localFileSet = new Set(localFiles);
|
|
543
|
+
for (const [remotePath, remoteFile] of remoteFileMap) {
|
|
544
|
+
if (!localFileSet.has(remotePath) && !conflictPaths.has(remotePath)) {
|
|
545
|
+
const syncInfo = syncState.files[remotePath];
|
|
546
|
+
if (syncInfo) {
|
|
547
|
+
// Was synced before, now deleted locally - delete on remote
|
|
548
|
+
await this.farseerClient.deleteFile(remoteFile.reference);
|
|
549
|
+
result.deleted.push(remotePath);
|
|
550
|
+
delete syncState.files[remotePath];
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
syncState.lastSync = new Date().toISOString();
|
|
555
|
+
this.saveSyncState(syncState);
|
|
556
|
+
return result;
|
|
540
557
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
558
|
+
async checkRemoteChanges() {
|
|
559
|
+
const syncState = this.loadSyncState();
|
|
560
|
+
let remoteFiles = await this.farseerClient.listFiles();
|
|
561
|
+
// Filter to scripts only (same as pull/status) to avoid false positives
|
|
562
|
+
// from non-script files like .json, .png, etc.
|
|
563
|
+
remoteFiles = remoteFiles.filter((f) => farseerFactory_1.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.name.toLowerCase().endsWith(ext)));
|
|
564
|
+
// Quick check: new files on remote that we don't have in sync state
|
|
565
|
+
for (const file of remoteFiles) {
|
|
566
|
+
const syncInfo = syncState.files[file.path];
|
|
567
|
+
if (!syncInfo) {
|
|
568
|
+
return true; // New file on remote
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
// Quick check: files deleted on remote that we have in sync state
|
|
572
|
+
for (const filePath of Object.keys(syncState.files)) {
|
|
573
|
+
// Only check script files
|
|
574
|
+
const isScript = farseerFactory_1.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => filePath.toLowerCase().endsWith(ext));
|
|
575
|
+
if (!isScript)
|
|
576
|
+
continue;
|
|
577
|
+
const exists = remoteFiles.some((f) => f.path === filePath);
|
|
578
|
+
if (!exists && syncState.files[filePath].remoteHash) {
|
|
579
|
+
return true; // File was deleted on remote
|
|
580
|
+
}
|
|
559
581
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
} else if (!hadBaseline) {
|
|
574
|
-
changeType = "conflict_both_new";
|
|
575
|
-
} else {
|
|
576
|
-
const localChanged = currentLocalHash !== baselineLocalHash;
|
|
577
|
-
const remoteChanged = currentRemoteHash !== baselineRemoteHash;
|
|
578
|
-
if (localChanged && remoteChanged) {
|
|
579
|
-
changeType = "conflict_both_modified";
|
|
580
|
-
} else if (localChanged) {
|
|
581
|
-
changeType = "local_modified";
|
|
582
|
-
} else if (remoteChanged) {
|
|
583
|
-
changeType = "remote_modified";
|
|
584
|
-
} else {
|
|
585
|
-
changeType = "unchanged";
|
|
586
|
-
}
|
|
582
|
+
// Note: We don't check for content changes here anymore for performance.
|
|
583
|
+
// After a pull, sync state is accurate. Content changes by others
|
|
584
|
+
// between pull and push are a rare edge case - user should pull first.
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
async getFileDiff(filePath) {
|
|
588
|
+
const filesDir = (0, helpers_1.getTenantFilesDir)(this.tenant);
|
|
589
|
+
const localPath = path.join(filesDir, filePath);
|
|
590
|
+
let localContent = null;
|
|
591
|
+
let remoteContent = null;
|
|
592
|
+
if (fs.existsSync(localPath)) {
|
|
593
|
+
// For diff, read as text (diff only makes sense for text files)
|
|
594
|
+
localContent = fs.readFileSync(localPath, 'utf-8');
|
|
587
595
|
}
|
|
588
|
-
|
|
589
|
-
if (
|
|
590
|
-
|
|
591
|
-
} else {
|
|
592
|
-
const localChanged = currentLocalHash !== baselineLocalHash;
|
|
593
|
-
if (localChanged) {
|
|
594
|
-
changeType = "conflict_local_modified_remote_deleted";
|
|
595
|
-
} else {
|
|
596
|
-
changeType = "remote_deleted";
|
|
597
|
-
}
|
|
596
|
+
const remoteFile = await this.farseerClient.getFileByPath(filePath);
|
|
597
|
+
if (remoteFile) {
|
|
598
|
+
remoteContent = await this.farseerClient.getFileContent(remoteFile.reference);
|
|
598
599
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
600
|
+
return { localContent, remoteContent };
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Three-way comparison of all files.
|
|
604
|
+
* Compares current local state, current remote state, and baseline from sync state.
|
|
605
|
+
*/
|
|
606
|
+
compareFiles(options) {
|
|
607
|
+
const { localHashes, remoteHashes, syncState } = options;
|
|
608
|
+
// Union of all known file paths
|
|
609
|
+
const allPaths = new Set([
|
|
610
|
+
...localHashes.keys(),
|
|
611
|
+
...remoteHashes.keys(),
|
|
612
|
+
...Object.keys(syncState.files),
|
|
613
|
+
]);
|
|
614
|
+
const results = [];
|
|
615
|
+
for (const filePath of allPaths) {
|
|
616
|
+
// Filter non-script files unless --all
|
|
617
|
+
if (!options.all) {
|
|
618
|
+
if (!farseerFactory_1.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => filePath.toLowerCase().endsWith(ext))) {
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
const currentLocalHash = localHashes.get(filePath) ?? null;
|
|
623
|
+
const currentRemoteHash = remoteHashes.get(filePath) ?? null;
|
|
624
|
+
const baseline = syncState.files[filePath];
|
|
625
|
+
const baselineLocalHash = baseline?.localHash ?? null;
|
|
626
|
+
const baselineRemoteHash = baseline?.remoteHash ?? null;
|
|
627
|
+
const localExists = currentLocalHash !== null;
|
|
628
|
+
const remoteExists = currentRemoteHash !== null;
|
|
629
|
+
const hadBaseline = baseline != null;
|
|
630
|
+
let changeType;
|
|
631
|
+
if (localExists && remoteExists) {
|
|
632
|
+
// Both exist
|
|
633
|
+
if (currentLocalHash === currentRemoteHash) {
|
|
634
|
+
changeType = 'unchanged';
|
|
635
|
+
}
|
|
636
|
+
else if (!hadBaseline) {
|
|
637
|
+
changeType = 'conflict_both_new';
|
|
638
|
+
}
|
|
639
|
+
else {
|
|
640
|
+
const localChanged = currentLocalHash !== baselineLocalHash;
|
|
641
|
+
const remoteChanged = currentRemoteHash !== baselineRemoteHash;
|
|
642
|
+
if (localChanged && remoteChanged) {
|
|
643
|
+
changeType = 'conflict_both_modified';
|
|
644
|
+
}
|
|
645
|
+
else if (localChanged) {
|
|
646
|
+
changeType = 'local_modified';
|
|
647
|
+
}
|
|
648
|
+
else if (remoteChanged) {
|
|
649
|
+
changeType = 'remote_modified';
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
changeType = 'unchanged';
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
else if (localExists && !remoteExists) {
|
|
657
|
+
// Only local exists
|
|
658
|
+
if (!hadBaseline) {
|
|
659
|
+
changeType = 'local_new';
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
const localChanged = currentLocalHash !== baselineLocalHash;
|
|
663
|
+
if (localChanged) {
|
|
664
|
+
changeType = 'conflict_local_modified_remote_deleted';
|
|
665
|
+
}
|
|
666
|
+
else {
|
|
667
|
+
changeType = 'remote_deleted';
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
else if (!localExists && remoteExists) {
|
|
672
|
+
// Only remote exists
|
|
673
|
+
if (!hadBaseline) {
|
|
674
|
+
changeType = 'remote_new';
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
const remoteChanged = currentRemoteHash !== baselineRemoteHash;
|
|
678
|
+
if (remoteChanged) {
|
|
679
|
+
changeType = 'conflict_local_deleted_remote_modified';
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
changeType = 'local_deleted';
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
else {
|
|
687
|
+
// Neither exists - both deleted since baseline, clean up
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
690
|
+
results.push({
|
|
691
|
+
filePath,
|
|
692
|
+
changeType,
|
|
693
|
+
currentLocalHash,
|
|
694
|
+
currentRemoteHash,
|
|
695
|
+
baselineLocalHash,
|
|
696
|
+
baselineRemoteHash,
|
|
697
|
+
});
|
|
609
698
|
}
|
|
610
|
-
|
|
611
|
-
continue;
|
|
612
|
-
}
|
|
613
|
-
results.push({
|
|
614
|
-
filePath,
|
|
615
|
-
changeType,
|
|
616
|
-
currentLocalHash,
|
|
617
|
-
currentRemoteHash,
|
|
618
|
-
baselineLocalHash,
|
|
619
|
-
baselineRemoteHash
|
|
620
|
-
});
|
|
699
|
+
return results;
|
|
621
700
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
701
|
+
/**
|
|
702
|
+
* Extract SyncConflict[] from FileCompareResult[].
|
|
703
|
+
*/
|
|
704
|
+
static buildConflicts(comparisons) {
|
|
705
|
+
const conflicts = [];
|
|
706
|
+
for (const c of comparisons) {
|
|
707
|
+
switch (c.changeType) {
|
|
708
|
+
case 'conflict_both_modified':
|
|
709
|
+
conflicts.push({
|
|
710
|
+
filePath: c.filePath,
|
|
711
|
+
type: 'both_modified',
|
|
712
|
+
description: 'Both local and remote versions modified since last sync',
|
|
713
|
+
});
|
|
714
|
+
break;
|
|
715
|
+
case 'conflict_local_modified_remote_deleted':
|
|
716
|
+
conflicts.push({
|
|
717
|
+
filePath: c.filePath,
|
|
718
|
+
type: 'local_modified_remote_deleted',
|
|
719
|
+
description: 'File modified locally but deleted on remote',
|
|
720
|
+
});
|
|
721
|
+
break;
|
|
722
|
+
case 'conflict_local_deleted_remote_modified':
|
|
723
|
+
conflicts.push({
|
|
724
|
+
filePath: c.filePath,
|
|
725
|
+
type: 'local_deleted_remote_modified',
|
|
726
|
+
description: 'File deleted locally but modified on remote',
|
|
727
|
+
});
|
|
728
|
+
break;
|
|
729
|
+
case 'conflict_both_new':
|
|
730
|
+
conflicts.push({
|
|
731
|
+
filePath: c.filePath,
|
|
732
|
+
type: 'both_new',
|
|
733
|
+
description: 'File exists both locally and remotely with different content (no sync baseline)',
|
|
734
|
+
});
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return conflicts;
|
|
660
739
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
740
|
+
/**
|
|
741
|
+
* Batch fetch metadata for multiple files in parallel.
|
|
742
|
+
* Fetches metadata in batches of 10 to avoid overwhelming the API.
|
|
743
|
+
* Non-critical operation - failures are silently ignored.
|
|
744
|
+
*/
|
|
745
|
+
async fetchMetadataForFiles(files) {
|
|
746
|
+
const batchSize = 10;
|
|
747
|
+
for (let i = 0; i < files.length; i += batchSize) {
|
|
748
|
+
const batch = files.slice(i, i + batchSize);
|
|
749
|
+
await Promise.all(batch.map(async (file) => {
|
|
750
|
+
try {
|
|
751
|
+
const metadata = await this.farseerClient.getFileMetadata(file.reference);
|
|
752
|
+
if (metadata) {
|
|
753
|
+
file.metadata = metadata;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
catch {
|
|
757
|
+
// Silently ignore metadata fetch errors - non-critical
|
|
758
|
+
}
|
|
759
|
+
}));
|
|
679
760
|
}
|
|
680
|
-
|
|
761
|
+
return files;
|
|
681
762
|
}
|
|
682
|
-
return files;
|
|
683
|
-
}
|
|
684
763
|
}
|
|
685
|
-
|
|
686
|
-
0 && (module.exports = {
|
|
687
|
-
SyncService
|
|
688
|
-
});
|
|
689
|
-
//# sourceMappingURL=syncService.js.map
|
|
764
|
+
exports.SyncService = SyncService;
|