-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathtypes.ts
More file actions
140 lines (117 loc) · 4.09 KB
/
Copy pathtypes.ts
File metadata and controls
140 lines (117 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Copyright 2025, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
ComponentStatus,
FileResponse,
MetadataApiDeployStatus,
MetadataApiRetrieveStatus,
RequestStatus,
SourceComponent,
FileResponseFailure,
FileResponseSuccess,
ComponentLike,
} from '@salesforce/source-deploy-retrieve';
import { isObject } from '@salesforce/ts-types';
import { DefaultReportOptions } from '@salesforce/apex-node';
export const reportsFormatters = Object.keys(DefaultReportOptions);
export enum TestLevel {
NoTestRun = 'NoTestRun',
RunSpecifiedTests = 'RunSpecifiedTests',
RunLocalTests = 'RunLocalTests',
RunAllTestsInOrg = 'RunAllTestsInOrg',
RunRelevantTests = 'RunRelevantTests',
}
export enum API {
SOAP = 'SOAP',
REST = 'REST',
}
export type PathInfo = {
type: 'directory' | 'file';
path: string;
};
export type Verbosity = 'verbose' | 'concise' | 'normal';
export type AsyncDeployResultJson = Omit<Partial<MetadataApiDeployStatus>, 'status'> & {
status: RequestStatus | 'Queued' | 'Nothing to deploy';
files: FileResponse[];
zipSize?: number;
zipFileCount?: number;
deployUrl?: string;
};
type ConvertEntry = {
fullName: string;
type: string;
filePath: string;
state: 'Add';
};
export type ConvertMdapiJson = ConvertEntry[];
export type ConvertResultJson = {
location: string;
};
export type DeleteSourceJson = {
deletedSource?: FileResponse[];
deployedSource: FileResponse[];
outboundFiles: string[];
deploys?: MetadataApiDeployStatus[];
deletes?: MetadataApiDeployStatus[];
replacements?: Record<string, string[]>;
coverage?: CoverageResultsFileInfo;
junit?: string;
} & MetadataApiDeployStatus;
export type CoverageResultsFileInfo = Record<keyof Partial<typeof DefaultReportOptions>, string>;
export type DeployResultJson =
| (MetadataApiDeployStatus & {
files: FileResponse[];
replacements?: Record<string, string[]>;
zipSize?: number;
zipFileCount?: number;
deployUrl?: string;
})
| AsyncDeployResultJson;
export type MetadataRetrieveResultJson = Omit<MetadataApiRetrieveStatus, 'zipFile'> & {
zipFilePath: string;
files: FileResponse[];
};
export type RetrieveResultJson =
| (Omit<MetadataApiRetrieveStatus, 'zipFile'> & { files: FileResponse[] })
| MetadataRetrieveResultJson;
export type Formatter<T> = {
getJson: () => Promise<T>;
display: () => void;
};
/** validates source component with fullname, type, and xml props */
export const isSourceComponent = (sc: ComponentLike): sc is SourceComponent =>
isObject(sc) &&
'type' in sc &&
typeof sc.type === 'object' &&
sc.type !== null &&
'name' in sc.type &&
typeof sc.type.name === 'string' &&
'fullName' in sc &&
'walkContent' in sc &&
// (typeof sc.fullName === 'string' || typeof sc.fullName === 'function');
typeof sc.fullName === 'string';
export const isSourceComponentWithXml = (sc: ComponentLike): sc is SourceComponent & { xml: string } =>
isSourceComponent(sc) && 'xml' in sc && typeof sc.xml === 'string';
export const isSdrFailure = (fileResponse: FileResponse): fileResponse is FileResponseFailure =>
fileResponse.state === ComponentStatus.Failed;
export const isSdrSuccess = (fileResponse: FileResponse): fileResponse is FileResponseSuccess =>
fileResponse.state !== ComponentStatus.Failed;
export const isFileResponseDeleted = (fileResponse: FileResponseSuccess): boolean =>
fileResponse.state === ComponentStatus.Deleted;
export const isDefined = <T>(value?: T): value is T => value !== undefined;
export function isTruthy(value: string | undefined): boolean {
return value !== '0' && value !== 'false';
}