Skip to content

Commit

Permalink
feat: support setting export query for vlocode CLI export command
Browse files Browse the repository at this point in the history
  • Loading branch information
Codeneos committed Aug 21, 2024
1 parent 38e843f commit b15cc93
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/vlocity-deploy/src/export/datapackExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DescribeSObjectResult, Field, SalesforceLookupService, SalesforceSchema
import { ObjectFilter, ObjectRelationship } from "./exportDefinitions";
import { VlocityDatapackLookupReference, VlocityDatapackMatchingReference, VlocityDatapackReference, VlocityDatapackReferenceType, VlocityDatapackSObject, VlocityDatapackSourceKey, VlocityDatapackType, VlocityMatchingKeyService } from "@vlocode/vlocity";
import { forEachAsyncParallel, formatString, mapAsyncParallel, Timer } from "@vlocode/util";
import { DistinctLogger, Logger, injectable } from "@vlocode/core";
import { Logger, injectable } from "@vlocode/core";
import { DatapackExpandResult, DatapackExpander } from "./datapackExpander";
import { DatapackExportDefinitionStore } from "./exportDefinitionStore";
import { randomUUID } from "crypto";
Expand Down Expand Up @@ -83,7 +83,6 @@ export class DatapackExporter {

private datapacks: Record<string, ExportDatapack> = {};
private matchingKeys: Record<string, string> = {};
private distinctLogger = new DistinctLogger(this.logger);

/**
* Maximum depth to export objects, when the depth is reached the
Expand All @@ -107,6 +106,7 @@ export class DatapackExporter {
private readonly vlocityMatchingKeys: VlocityMatchingKeyService,
private readonly logger: Logger,
) {
this.logger = logger.distinct();
this.lookupService.enableLookupCache(true);
}

Expand Down Expand Up @@ -506,7 +506,7 @@ export class DatapackExporter {
}

// If matching key fields are empty use auto-generated matching key
const allFieldsEmpty = matchingKeyFields.every(field => data[field] === undefined);
const allFieldsEmpty = matchingKeyFields.every(field => data[field] === '' || data[field] === undefined || data[field] === null);
if (allFieldsEmpty) {
this.logger.warn(`${data['id']} (${describe.name}) all matching key fields empty -- using auto-generated matching key instead`);
return this.getAutoMatchingKey(describe, data['id'], scope);
Expand Down Expand Up @@ -569,7 +569,7 @@ export class DatapackExporter {
) {
try {
return JSON.parse(value);
} catch (e) {
} catch {
// Ignore errors when not valid JSON
}
}
Expand All @@ -583,12 +583,16 @@ export class DatapackExporter {

const sfMatchingKey = (await this.vlocityMatchingKeys.getMatchingKeyDefinition(type.name)).fields;
if (sfMatchingKey.length > 0) {
this.distinctLogger.debug(`Using Vlocity DR Matching keys for: ${type.name}`);
return sfMatchingKey;
this.logger.debug(`Using Vlocity DR Matching keys for: ${type.name}`);
return this.validateFieldList(type, sfMatchingKey);
}

const detectedFields = this.guessMatchingFields(type);
this.distinctLogger.warn(`No matching fields defined for ${type.name} - using fields: ${detectedFields}`);
if (detectedFields.length > 0) {
this.logger.warn(`No matching fields defined for ${type.name} - using fields: ${detectedFields}`);
} else {
this.logger.warn(`No matching fields defined for ${type.name} - no unique fields found`);
}
return detectedFields;
}

Expand Down

0 comments on commit b15cc93

Please sign in to comment.