UNPKG

salesforce-alm

Version:

This package contains tools, and APIs, for an improved salesforce.com developer experience.

142 lines (141 loc) 5.75 kB
import { ConfigFile, Logger } from '@salesforce/core'; import { Optional } from '@salesforce/ts-types'; export declare type ChangeElement = { name: string; type: string; deleted?: boolean; }; export declare namespace RemoteSourceTrackingService { interface Options extends ConfigFile.Options { username: string; } } /** * This service handles source tracking of metadata between a local project and an org. * Source tracking state is persisted to .sfdx/orgs/<username>/maxRevision.json. * This JSON file keeps track of `SourceMember` objects and the `serverMaxRevisionCounter`, * which is the highest `serverRevisionCounter` value of all the tracked elements. * * Each SourceMember object has 4 fields: * serverRevisionCounter: the current RevisionCounter on the server for this object * lastRetrievedFromServer: the RevisionCounter last retrieved from the server for this object * memberType: the metadata name of the SourceMember * isNameObsolete: `true` if this object has been deleted in the org * * ex. ``` { serverMaxRevisionCounter: 3, sourceMembers: { ApexClass__MyClass: { serverRevisionCounter: 3, lastRetrievedFromServer: 2, memberType: ApexClass, isNameObsolete: false }, CustomObject__Student__c: { serverRevisionCounter: 1, lastRetrievedFromServer: 1, memberType: CustomObject, isNameObsolete: false } } } ``` * 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. */ export declare class RemoteSourceTrackingService extends ConfigFile<RemoteSourceTrackingService.Options> { logger: Logger; private org; private readonly FIRST_REVISION_COUNTER_API_VERSION; private conn; private currentApiVersion; private static remoteSourceTrackingServiceDictionary; private isSourceTrackedOrg; private queryCache; /** * Get the singleton instance for a given user. * * @param {RemoteSourceTrackingService.Options} options that contain the org's username * @returns {Promise<RemoteSourceTrackingService>} the remoteSourceTrackingService object for the given username */ static getInstance(options: RemoteSourceTrackingService.Options): Promise<RemoteSourceTrackingService>; /** * Returns the name of the file used for remote source tracking persistence. * * @override */ static getFileName(): string; /** * Initializes the service with existing remote source tracking data, or sets * the state to begin source tracking of metadata changes in the org. */ init(): Promise<void>; /** * Returns the `ChangeElement` currently being tracked given a metadata key, * or `undefined` if not found. * * @param key string of the form, `<type>__<name>` e.g.,`ApexClass__MyClass` */ getTrackedElement(key: string): Optional<ChangeElement>; /** * Returns an array of `ChangeElements` currently being tracked. */ getTrackedElements(): ChangeElement[]; /** * 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<ChangeElement[]>; /** * Synchronizes local and remote source tracking with data from the associated org. * * When called without `ChangeElements` passed this will query all `SourceMember` * objects from the last retrieval and update the tracked elements. This is * typically called after retrieving all new, changed, or deleted metadata from * the org. E.g., after a `source:pull` command. * * When called with `ChangeElements` passed this will poll the org for * corresponding `SourceMember` data and update the tracked elements. This is * typically called after deploying metadata from a local project to the org. * E.g., after a `source:push` command. */ sync(metadataNames?: string[]): 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<void>; private getServerMaxRevision; private setServerMaxRevision; private getSourceMembers; private initSourceMembers; private getSourceMember; private setMemberRevision; private trackSourceMembers; private static convertRevisionToChange; private _retrieveUpdates; /** * 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 memberNames Array of metadata names to poll * @param pollingTimeout maximum amount of time in seconds to poll for SourceMembers */ private pollForSourceTracking; private querySourceMembersFrom; private querySourceMembersTo; private sleep; private query; }