Skip to content

Commit f100cb8

Browse files
committed
feat: most of sourceStatus logic, code cleanup
1 parent b8877e1 commit f100cb8

8 files changed

+281
-66
lines changed

src/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,12 @@
77

88
export * from './sourceTracking';
99
export * from './compatibility';
10-
export { RemoteSyncInput } from './shared/types';
10+
export {
11+
RemoteSyncInput,
12+
ChangeOptionType,
13+
ChangeOptions,
14+
LocalUpdateOptions,
15+
ChangeResult,
16+
ConflictError,
17+
} from './shared/types';
18+
export { getKeyFromObject } from './shared/functions';

src/shared/functions.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2020, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { RemoteChangeElement, ChangeResult } from './types';
9+
10+
export const getMetadataKey = (metadataType: string, metadataName: string): string => {
11+
return `${metadataType}__${metadataName}`;
12+
};
13+
14+
export const getKeyFromObject = (element: RemoteChangeElement | ChangeResult): string => {
15+
if (element.type && element.name) {
16+
return getMetadataKey(element.type, element.name);
17+
}
18+
throw new Error(`unable to complete key from ${JSON.stringify(element)}`);
19+
};

src/shared/guards.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2020, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
import { SourceComponent } from '@salesforce/source-deploy-retrieve';
8+
9+
export const stringGuard = (input: string | undefined): input is string => {
10+
return typeof input === 'string';
11+
};
12+
13+
export const sourceComponentGuard = (input: SourceComponent | undefined): input is SourceComponent => {
14+
return input instanceof SourceComponent;
15+
};

src/shared/metadataKeys.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import * as path from 'path';
88
import { RemoteSyncInput } from './types';
9-
import { getMetadataKey } from './remoteSourceTrackingService';
9+
import { getMetadataKey } from './functions';
1010

1111
// LWC can have child folders (ex: dynamic templates like /templates/noDataIllustration.html
1212
const pathAfterFullName = (fileResponse: RemoteSyncInput): string =>

src/shared/remoteSourceTrackingService.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import { ConfigFile, Logger, Org, SfdxError, Messages, fs } from '@salesforce/co
1313
import { ComponentStatus } from '@salesforce/source-deploy-retrieve';
1414
import { Dictionary, Optional } from '@salesforce/ts-types';
1515
import { env, toNumber } from '@salesforce/kit';
16-
import { RemoteSyncInput } from '../shared/types';
16+
import { RemoteSyncInput, RemoteChangeElement } from '../shared/types';
1717
import { getMetadataKeyFromFileResponse } from './metadataKeys';
18+
import { getMetadataKey } from './functions';
1819

1920
export type MemberRevision = {
2021
serverRevisionCounter: number;
@@ -30,13 +31,6 @@ export type SourceMember = {
3031
RevisionCounter: number;
3132
};
3233

33-
export type RemoteChangeElement = {
34-
name: string;
35-
type: string;
36-
deleted?: boolean;
37-
modified?: boolean;
38-
};
39-
4034
// represents the contents of the config file stored in 'maxRevision.json'
4135
interface Contents {
4236
serverMaxRevisionCounter: number;
@@ -52,10 +46,6 @@ export namespace RemoteSourceTrackingService {
5246
}
5347
}
5448

55-
export const getMetadataKey = (metadataType: string, metadataName: string): string => {
56-
return `${metadataType}__${metadataName}`;
57-
};
58-
5949
/**
6050
* This service handles source tracking of metadata between a local project and an org.
6151
* Source tracking state is persisted to .sfdx/orgs/<orgId>/maxRevision.json.

src/shared/types.ts

+41-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,46 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { FileResponse } from '@salesforce/source-deploy-retrieve';
8+
import { FileResponse, SourceComponent } from '@salesforce/source-deploy-retrieve';
9+
import { getMetadataKey } from '../shared/functions';
10+
11+
export interface ChangeOptions {
12+
origin: 'local' | 'remote';
13+
state: 'add' | 'delete' | 'modify' | 'nondelete';
14+
format: 'ChangeResult' | 'SourceComponent' | 'string' | 'ChangeResultWithPaths';
15+
}
916

1017
export type RemoteSyncInput = Pick<FileResponse, 'fullName' | 'filePath' | 'type' | 'state'>;
18+
19+
export type StatusOutputRow = Pick<FileResponse, 'fullName' | 'filePath' | 'type'> & {
20+
conflict?: boolean;
21+
ignored?: boolean;
22+
} & Pick<ChangeOptions, 'origin' | 'state'>;
23+
24+
export interface LocalUpdateOptions {
25+
files?: string[];
26+
deletedFiles?: string[];
27+
}
28+
29+
export type RemoteChangeElement = {
30+
name: string;
31+
type: string;
32+
deleted?: boolean;
33+
modified?: boolean;
34+
};
35+
36+
/**
37+
* Summary type that supports both local and remote change types
38+
*/
39+
export type ChangeResult = Partial<RemoteChangeElement> & {
40+
origin: 'local' | 'remote';
41+
filenames?: string[];
42+
};
43+
44+
export interface ConflictError {
45+
message: string;
46+
name: 'conflict';
47+
conflicts: ChangeResult[];
48+
}
49+
50+
export type ChangeOptionType = ChangeResult | SourceComponent | string;

0 commit comments

Comments
 (0)