@salesforce/source-tracking
Version:
API for tracking local and remote Salesforce metadata changes
122 lines (121 loc) • 5.24 kB
TypeScript
import { Logger, Org } from '@salesforce/core';
import { ChangeResult, RemoteChangeElement, RemoteSyncInput } from '../types';
export type PinoLogger = ReturnType<(typeof Logger)['getRawRootLogger']>;
/** Options for RemoteSourceTrackingService.getInstance */
export type RemoteSourceTrackingServiceOptions = {
org: Org;
projectPath: string;
};
/**
* This service handles source tracking of metadata between a local project and an org.
* Source tracking state is persisted to .sfdx/orgs/<orgId>/maxRevision.json.
* This JSON file keeps track of `SourceMember` objects and the `serverMaxRevisionCounter`,
* which is the highest `RevisionCounter` value of all the tracked elements.
*
* See @MemberRevision for the structure of the `MemberRevision` object. It's SourceMember (the tooling sobject) with the additional lastRetrievedFromServer field
```
{
fileVersion: 1,
serverMaxRevisionCounter: 3,
sourceMembers: {
ApexClass###MyClass: {
RevisionCounter: 3,
MemberType: ApexClass,
...,
lastRetrievedFromServer: 2,
},
CustomObject###Student__c: {
RevisionCounter: 1,
MemberType: CustomObject,
...,
lastRetrievedFromServer: 1,
}
}
}
```
* In this example, `ApexClass###MyClass` has been changed in the org because the `serverRevisionCounter` is different
* from the `lastRetrievedFromServer`. When a pull is performed, all of the pulled members will have their counters set
* to the corresponding `RevisionCounter` from the `SourceMember` of the org.
*
* Tracking files are written to the older format described in `MemberRevisionLegacy`
* if the environment variable CURRENT_FILE_VERSION_ENV is not set to 1
*
* The "in memorgy" storage is in MemberRevision format.
*/
export declare class RemoteSourceTrackingService {
/** map of constructed, init'ed instances; key is orgId. It's like a singleton at the org level */
private static instanceMap;
readonly filePath: string;
private logger;
private serverMaxRevisionCounter;
private sourceMembers;
private org;
private queryCache;
private userQueryCache;
/**
* Initializes the service with existing remote source tracking data, or sets
* the state to begin source tracking of metadata changes in the org.
*/
private constructor();
/**
* Get the singleton instance for a given user.
*
* @param {RemoteSourceTrackingService.Options} options that contain the org
* @returns {Promise<RemoteSourceTrackingService>} the remoteSourceTrackingService object for the given username
*/
static getInstance(options: RemoteSourceTrackingServiceOptions): Promise<RemoteSourceTrackingService>;
/**
* Delete the RemoteSourceTracking for a given org.
*
* @param orgId
* @returns the path of the deleted source tracking file
*/
static delete(orgId: string): Promise<string>;
/**
* pass in a series of SDR FilResponses .\
* it sets their last retrieved revision to the current revision counter from the server.
*/
syncSpecifiedElements(elements: RemoteSyncInput[]): Promise<void>;
/**
* Resets source tracking state by first clearing all tracked data, then
* queries and synchronizes SourceMembers from the associated org.
*
* If a toRevision is passed, it will query for all `SourceMembers` with
* a `RevisionCounter` less than or equal to the provided revision number.
*
* When no toRevision is passed, it will query and sync all `SourceMembers`.
*
* @param toRevision The `RevisionCounter` number to sync to.
*/
reset(toRevision?: number): Promise<string[]>;
/**
* Queries the org for any new, updated, or deleted metadata and updates
* source tracking state. All `ChangeElements` not in sync with the org
* are returned.
*/
retrieveUpdates(): Promise<RemoteChangeElement[]>;
/**
* Polls the org for SourceMember objects matching the provided metadata member names,
* stopping when all members have been matched or the polling timeout is met or exceeded.
* NOTE: This can be removed when the Team Dependency (TD-0085369) for W-7737094 is delivered.
*
* @param expectedMemberNames Array of metadata names to poll
* @param pollingTimeout maximum amount of time in seconds to poll for SourceMembers
*/
pollForSourceTracking(expectedMembers: RemoteSyncInput[]): Promise<void>;
/**
* Adds the given SourceMembers to the list of tracked MemberRevisions, optionally updating
* the lastRetrievedFromServer field (sync), and persists the changes to maxRevision.json.
*/
private trackSourceMembers;
/** reads the tracking file and inits the logger and contents */
private init;
/** Return a tracked element as MemberRevision data.*/
private getSourceMember;
private setMemberRevision;
}
/**
* pass in an RCE, and this will return a pullable ChangeResult.
* Useful for correcing bundle types where the files show change results with types but aren't resolvable
*/
export declare const remoteChangeElementToChangeResult: (rce: RemoteChangeElement) => ChangeResult;