Skip to content

Commit f849230

Browse files
author
hknokh2
committed
fix: support polymorphic ExportFiles parsing and sync v5.6.1 notes
1 parent a1d74c7 commit f849230

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/modules/addons/modules/sfdmu-run/ExportFiles/index.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
ERRORS_FIELD_NAME,
1717
MAX_CHUNK_SIZE,
1818
MAX_FILE_SIZE,
19+
POLYMORPHIC_FIELD_PARSER_PLACEHOLDER,
20+
REFERENCE_FIELD_OBJECT_SEPARATOR,
1921
} from '../../../../constants/Constants.js';
2022
import CjsDependencyAdapters from '../../../../dependencies/CjsDependencyAdapters.js';
2123
import ScriptObject from '../../../../models/script/ScriptObject.js';
@@ -168,9 +170,9 @@ export default class ExportFiles implements ISfdmuRunCustomAddonModule {
168170
const script = this.runtime.getScript();
169171
const targetObject = script.getAllObjects().find((object) => object.name === context.objectName);
170172
if (targetObject && context.objectName === 'FeedItem' && targetObject.query) {
171-
const parsedQuery = parseQuery(targetObject.query);
173+
const parsedQuery = parseQuery(this._sanitizeQueryForParser(targetObject.query));
172174
Common.addOrRemoveQueryFields(parsedQuery, ['Type']);
173-
targetObject.query = composeQuery(parsedQuery);
175+
targetObject.query = this._restoreQueryFromParser(composeQuery(parsedQuery));
174176
}
175177
void args;
176178
return Promise.resolve(new AddonResult());
@@ -735,6 +737,34 @@ export default class ExportFiles implements ISfdmuRunCustomAddonModule {
735737
};
736738
}
737739

740+
/**
741+
* Sanitizes polymorphic query markers for SOQL parser compatibility.
742+
*
743+
* @param query - Raw query text.
744+
* @returns Query safe for parser.
745+
*/
746+
private _sanitizeQueryForParser(query: string): string {
747+
void this;
748+
if (!query || !query.includes(REFERENCE_FIELD_OBJECT_SEPARATOR)) {
749+
return query;
750+
}
751+
return query.replaceAll(REFERENCE_FIELD_OBJECT_SEPARATOR, POLYMORPHIC_FIELD_PARSER_PLACEHOLDER);
752+
}
753+
754+
/**
755+
* Restores polymorphic query markers after query composition.
756+
*
757+
* @param query - Parser-safe query text.
758+
* @returns Query with original polymorphic markers.
759+
*/
760+
private _restoreQueryFromParser(query: string): string {
761+
void this;
762+
if (!query || !query.includes(POLYMORPHIC_FIELD_PARSER_PLACEHOLDER)) {
763+
return query;
764+
}
765+
return query.replaceAll(POLYMORPHIC_FIELD_PARSER_PLACEHOLDER, REFERENCE_FIELD_OBJECT_SEPARATOR);
766+
}
767+
738768
/**
739769
* Resolves max file size for the run.
740770
*

test/modules/addons/core-addons.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,26 @@ describe('Core add-ons', () => {
103103
assert.equal(filteredRecords.length, 1);
104104
assert.equal(filteredRecords[0]?.['Name'], 'Bad foo');
105105
});
106+
107+
it('initializes core ExportFiles with polymorphic FeedItem fields', async () => {
108+
const scriptObject = new ScriptObject('FeedItem');
109+
scriptObject.query = "SELECT Id, Body, ParentId$Account FROM FeedItem WHERE Type = 'ContentPost'";
110+
scriptObject.afterAddons = [
111+
new ScriptAddonManifestDefinition({
112+
module: 'core:ExportFiles',
113+
}),
114+
];
115+
116+
const script = new Script();
117+
script.basePath = os.tmpdir();
118+
script.logger = createLoggingService();
119+
script.objectSets = [new ScriptObjectSet([scriptObject])];
120+
121+
const manager = new SfdmuRunAddonManager(script);
122+
await manager.initializeAsync();
123+
124+
assert.ok(scriptObject.query.includes('ParentId$Account'));
125+
assert.ok(scriptObject.query.includes('Type'));
126+
assert.ok(!scriptObject.query.includes('__DOLLAR__'));
127+
});
106128
});

0 commit comments

Comments
 (0)