farseer-cli 1.0.10 → 1.1.0

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