"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseChunker = void 0;
const uuid_1 = require("uuid");
class BaseChunker {
constructor(context) {
this.context = context;
}
createBaseChunk(name, content, path = '', symbols = [], references = []) {
return {
id: this.generateChunkId(name, path),
orgId: this.context.orgId,
type: this.context.metadataType,
name,
content: content.trim(),
symbols,
references,
path,
raw: this.context.originalMetadata,
metadata: {
size: content.length,
lineCount: content.split('\n').length,
createdDate: this.context.originalMetadata.createdDate,
lastModifiedDate: this.context.originalMetadata.lastModifiedDate
}
};
}
generateChunkId(name, path) {
const prefix = `${this.context.orgId}_${this.context.metadataType}_${name}`;
const pathSuffix = path ? `_${path.replace(/[^a-zA-Z0-9]/g, '_')}` : '';
return `${prefix}${pathSuffix}_${(0, uuid_1.v4)().substring(0, 8)}`;
}
extractBasicSymbols(content) {
const symbols = new Set();
// Extract Salesforce object references (e.g., Account, Contact)
const objectMatches = content.match(/\b[A-Z][a-zA-Z0-9_]*__c\b/g) || [];
objectMatches.forEach(match => symbols.add(match));
// Extract standard objects
const standardObjects = content.match(/\b(Account|Contact|Lead|Opportunity|Case|User|Profile)\b/g) || [];
standardObjects.forEach(match => symbols.add(match));
// Extract field references (Object.Field or Object__c.Field__c)
const fieldMatches = content.match(/\b[A-Z][a-zA-Z0-9_]*(__c)?\.[A-Za-z][a-zA-Z0-9_]*(__c)?\b/g) || [];
fieldMatches.forEach(match => symbols.add(match));
return Array.from(symbols);
}
extractBasicReferences(content) {
const references = [];
// Extract object references
const objectMatches = content.match(/\b[A-Z][a-zA-Z0-9_]*(__c)?\b/g) || [];
objectMatches.forEach(match => {
if (match.endsWith('__c') || ['Account', 'Contact', 'Lead', 'Opportunity', 'Case'].includes(match)) {
references.push({
type: 'object',
name: match,
fullName: match
});
}
});
// Extract field references
const fieldMatches = content.match(/\b([A-Z][a-zA-Z0-9_]*(__c)?)\.([A-Za-z][a-zA-Z0-9_]*(__c)?)\b/g) || [];
fieldMatches.forEach(match => {
const [object, field] = match.split('.');
references.push({
type: 'field',
name: field,
fullName: match,
context: object
});
});
return references;
}
}
exports.BaseChunker = BaseChunker;