@tenonhq/sincronia-core 0.0.49 → 0.0.51

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.
@@ -56,7 +56,7 @@ var __importStar = (this && this.__importStar) || (function () {
56
56
  const fsp = fs.promises;
57
57
  // Custom function to process manifest with specific source directory
58
58
  async function processManifestForScope(manifest, sourceDirectory, forceWrite = false) {
59
- var _a;
59
+ var _a, _b;
60
60
  try {
61
61
  // Ensure the source directory exists
62
62
  Logger_1.logger.info(`Creating source directory: ${sourceDirectory}`);
@@ -85,26 +85,21 @@ var __importStar = (this && this.__importStar) || (function () {
85
85
  const recordDirName = record.name || recordName;
86
86
  const recordPath = path.join(tablePath, recordDirName);
87
87
  FileLogger_1.fileLogger.debug(`Processing record: ${recordDirName} with ${((_a = record.files) === null || _a === void 0 ? void 0 : _a.length) || 0} files`);
88
+ // Check if metadata file exists in the files from server
89
+ const hasMetadataFromServer = (_b = record.files) === null || _b === void 0 ? void 0 : _b.some((f) => f.name === 'metaData' && f.type === 'json');
90
+ if (hasMetadataFromServer) {
91
+ FileLogger_1.fileLogger.debug(`*** METADATA FILE EXISTS FROM SERVER for ${recordDirName} ***`);
92
+ }
88
93
  // Ensure the record directory exists
89
94
  await fsp.mkdir(recordPath, { recursive: true });
90
- // Create metadata file for this record
91
- const metadataFilePath = path.join(recordPath, "metaData.json");
92
- const metadataContent = {
93
- _generatedAt: new Date().toISOString(),
94
- };
95
- FileLogger_1.fileLogger.debug(`*** CREATING METADATA FILE: ${metadataFilePath}`);
96
- FileLogger_1.fileLogger.debug(`Metadata content: ${JSON.stringify(metadataContent)}`);
97
- try {
98
- await fsp.writeFile(metadataFilePath, JSON.stringify(metadataContent, null, 2), "utf8");
99
- FileLogger_1.fileLogger.debug(`*** SUCCESSFULLY CREATED METADATA FILE for ${recordDirName}`);
100
- }
101
- catch (metaError) {
102
- Logger_1.logger.error(`Failed to write metadata file ${metadataFilePath}: ${metaError}`);
103
- }
104
95
  // Process each file in the record
105
96
  for (const file of record.files || []) {
106
97
  const filePath = path.join(recordPath, `${file.name}.${file.type}`);
107
98
  const fileContent = file.content || "";
99
+ if (file.name === 'metaData' && file.type === 'json') {
100
+ FileLogger_1.fileLogger.debug(`*** WRITING METADATA FILE FROM SERVER: ${filePath}`);
101
+ FileLogger_1.fileLogger.debug(`Metadata content length: ${fileContent.length} chars`);
102
+ }
108
103
  // Ensure the parent directory exists before writing the file
109
104
  const fileDir = path.dirname(filePath);
110
105
  Logger_1.logger.debug(`Creating directory: ${fileDir}`);
@@ -113,12 +108,31 @@ var __importStar = (this && this.__importStar) || (function () {
113
108
  Logger_1.logger.debug(`Writing file: ${filePath}`);
114
109
  try {
115
110
  await fsp.writeFile(filePath, fileContent, "utf8");
111
+ if (file.name === 'metaData' && file.type === 'json') {
112
+ FileLogger_1.fileLogger.debug(`*** SUCCESSFULLY WROTE METADATA FILE: ${filePath}`);
113
+ }
116
114
  }
117
115
  catch (writeError) {
118
116
  Logger_1.logger.error(`Failed to write file ${filePath}: ${writeError}`);
119
117
  throw writeError;
120
118
  }
121
119
  }
120
+ // If no metadata from server, create a basic one
121
+ if (!hasMetadataFromServer) {
122
+ const metadataFilePath = path.join(recordPath, "metaData.json");
123
+ const metadataContent = {
124
+ _generatedAt: new Date().toISOString(),
125
+ _note: "Generated locally - metadata not provided by server"
126
+ };
127
+ FileLogger_1.fileLogger.debug(`*** CREATING LOCAL METADATA FILE (not from server): ${metadataFilePath}`);
128
+ try {
129
+ await fsp.writeFile(metadataFilePath, JSON.stringify(metadataContent, null, 2), "utf8");
130
+ FileLogger_1.fileLogger.debug(`*** SUCCESSFULLY CREATED LOCAL METADATA FILE for ${recordDirName}`);
131
+ }
132
+ catch (metaError) {
133
+ Logger_1.logger.error(`Failed to write metadata file ${metadataFilePath}: ${metaError}`);
134
+ }
135
+ }
122
136
  }
123
137
  }
124
138
  Logger_1.logger.info(`Successfully processed files for ${sourceDirectory}`);
@@ -175,12 +189,22 @@ var __importStar = (this && this.__importStar) || (function () {
175
189
  }
176
190
  }
177
191
  // Get the actual file contents
192
+ FileLogger_1.fileLogger.debug("Getting missing files with content from ServiceNow...");
178
193
  const filesWithContent = await (0, snClient_1.unwrapSNResponse)(client.getMissingFiles(missingFiles, config.tableOptions || {}));
179
194
  // Merge the content back into the manifest
180
195
  for (const tableName in filesWithContent || {}) {
181
196
  if (manifest.tables[tableName]) {
182
197
  for (const recordName in filesWithContent[tableName].records || {}) {
183
198
  const recordWithContent = filesWithContent[tableName].records[recordName];
199
+ // Log what files are coming from the server
200
+ FileLogger_1.fileLogger.debug(`Files from server for ${tableName}/${recordName}:`);
201
+ for (const file of recordWithContent.files || []) {
202
+ FileLogger_1.fileLogger.debug(` - ${file.name}.${file.type} (content: ${file.content ? file.content.length + ' chars' : 'null'})`);
203
+ if (file.name === 'metaData' && file.type === 'json') {
204
+ FileLogger_1.fileLogger.debug('*** METADATA FILE FOUND FROM SERVER ***');
205
+ FileLogger_1.fileLogger.debug(`Metadata content preview: ${file.content ? file.content.substring(0, 200) : 'no content'}`);
206
+ }
207
+ }
184
208
  const manifestRecord = Object.values(manifest.tables[tableName].records).find((r) => r.sys_id === recordWithContent.sys_id);
185
209
  if (manifestRecord) {
186
210
  manifestRecord.files = recordWithContent.files;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenonhq/sincronia-core",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "description": "Next-gen file syncer",
5
5
  "license": "GPL-3.0",
6
6
  "main": "./dist/index.js",