UNPKG

8.8 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.INTEGRATION_NAMES = ['capacitor', 'cordova'];
4function isCommand(c) {
5 const cmd = c;
6 return cmd && typeof cmd.run === 'function';
7}
8exports.isCommand = isCommand;
9function isCommandPreRun(c) {
10 const cmd = c;
11 return cmd && typeof cmd.preRun === 'function';
12}
13exports.isCommandPreRun = isCommandPreRun;
14function isStarterManifest(o) {
15 const obj = o;
16 return obj &&
17 typeof obj.name === 'string' &&
18 typeof obj.baseref === 'string';
19}
20exports.isStarterManifest = isStarterManifest;
21function isCordovaPackageJson(o) {
22 const obj = o;
23 return obj &&
24 typeof obj.name === 'string' &&
25 typeof obj.cordova === 'object' &&
26 typeof obj.cordova.platforms === 'object' &&
27 typeof obj.cordova.plugins === 'object';
28}
29exports.isCordovaPackageJson = isCordovaPackageJson;
30function isExitCodeException(e) {
31 const err = e;
32 return err && typeof err.exitCode === 'number' && err.exitCode >= 0 && err.exitCode <= 255;
33}
34exports.isExitCodeException = isExitCodeException;
35function isSuperAgentError(e) {
36 const err = e;
37 return e && err.response && typeof err.response === 'object';
38}
39exports.isSuperAgentError = isSuperAgentError;
40function isAPIResponseSuccess(r) {
41 const res = r;
42 return res && (typeof res.data === 'object' || typeof res.data === 'string');
43}
44exports.isAPIResponseSuccess = isAPIResponseSuccess;
45function isAPIResponseError(r) {
46 const res = r;
47 return res && typeof res.error === 'object';
48}
49exports.isAPIResponseError = isAPIResponseError;
50function isOrg(o) {
51 const org = o;
52 return org && typeof org.name === 'string';
53}
54exports.isOrg = isOrg;
55function isGithubRepo(r) {
56 const repo = r;
57 return repo
58 && typeof repo.full_name === 'string'
59 && typeof repo.id === 'number';
60}
61exports.isGithubRepo = isGithubRepo;
62function isGithubBranch(r) {
63 const branch = r;
64 return branch
65 && typeof branch.name === 'string';
66}
67exports.isGithubBranch = isGithubBranch;
68function isGithubRepoListResponse(r) {
69 if (!isAPIResponseSuccess(r) || !Array.isArray(r.data)) {
70 return false;
71 }
72 if (r.data.length === 0) {
73 return true;
74 }
75 return typeof r.data[0] === 'object' && isGithubRepo(r.data[0]);
76}
77exports.isGithubRepoListResponse = isGithubRepoListResponse;
78function isGithubBranchListResponse(r) {
79 if (!isAPIResponseSuccess(r) || !Array.isArray(r.data)) {
80 return false;
81 }
82 if (r.data.length === 0) {
83 return true;
84 }
85 return typeof r.data[0] === 'object' && isGithubBranch(r.data[0]);
86}
87exports.isGithubBranchListResponse = isGithubBranchListResponse;
88function isAppAssociation(a) {
89 const association = a;
90 return (association &&
91 typeof association.repository === 'object' &&
92 typeof association.repository.html_url === 'string' &&
93 (isGithubRepoAssociation(association.repository) ||
94 isBitbucketCloudRepoAssociation(association.repository) ||
95 isBitbucketServerRepoAssociation(association.repository)));
96}
97exports.isAppAssociation = isAppAssociation;
98function isAppAssociationResponse(r) {
99 return isAPIResponseSuccess(r)
100 && typeof r.data === 'object'
101 && isAppAssociation(r.data);
102}
103exports.isAppAssociationResponse = isAppAssociationResponse;
104function isGithubRepoAssociation(a) {
105 const repo = a;
106 return repo
107 && repo.type === 'github'
108 && typeof repo.id === 'number';
109}
110exports.isGithubRepoAssociation = isGithubRepoAssociation;
111function isBitbucketCloudRepoAssociation(a) {
112 const repo = a;
113 return repo
114 && repo.type === 'bitbucket_cloud'
115 && typeof repo.id === 'string';
116}
117exports.isBitbucketCloudRepoAssociation = isBitbucketCloudRepoAssociation;
118function isBitbucketServerRepoAssociation(a) {
119 const repo = a;
120 return repo
121 && repo.type === 'bitbucket_server'
122 && typeof repo.id === 'number';
123}
124exports.isBitbucketServerRepoAssociation = isBitbucketServerRepoAssociation;
125function isApp(d) {
126 const details = d;
127 return details
128 && typeof details === 'object'
129 && typeof details.id === 'string'
130 && typeof details.name === 'string'
131 && typeof details.slug === 'string'
132 && (!details.org || isOrg(details.org))
133 && (!details.association || isAppAssociation(details.association));
134}
135exports.isApp = isApp;
136function isAppResponse(r) {
137 return isAPIResponseSuccess(r)
138 && typeof r.data === 'object'
139 && isApp(r.data);
140}
141exports.isAppResponse = isAppResponse;
142function isAppsResponse(r) {
143 if (!isAPIResponseSuccess(r) || !Array.isArray(r.data)) {
144 return false;
145 }
146 if (r.data.length === 0) {
147 return true;
148 }
149 return typeof r.data[0] === 'object' && isApp(r.data[0]);
150}
151exports.isAppsResponse = isAppsResponse;
152function isOAuthLoginResponse(r) {
153 const res = r;
154 return isAPIResponseSuccess(res) && typeof res.data === 'object' && typeof res.data.redirect_url === 'string';
155}
156exports.isOAuthLoginResponse = isOAuthLoginResponse;
157function isSnapshot(s) {
158 const snapshot = s;
159 return snapshot
160 && typeof snapshot.id === 'string'
161 && typeof snapshot.sha === 'string'
162 && typeof snapshot.ref === 'string'
163 && typeof snapshot.state === 'string'
164 && typeof snapshot.created === 'string'
165 && typeof snapshot.note === 'string';
166}
167exports.isSnapshot = isSnapshot;
168function isSnapshotResponse(r) {
169 const res = r;
170 return isAPIResponseSuccess(res) && isSnapshot(res.data);
171}
172exports.isSnapshotResponse = isSnapshotResponse;
173function isSnapshotListResponse(r) {
174 if (!isAPIResponseSuccess(r) || !Array.isArray(r.data)) {
175 return false;
176 }
177 if (r.data.length === 0) {
178 return true;
179 }
180 return typeof r.data[0] === 'object' && isSnapshot(r.data[0]);
181}
182exports.isSnapshotListResponse = isSnapshotListResponse;
183function isLogin(l) {
184 const login = l;
185 return login
186 && isUser(login.user)
187 && typeof login.token === 'string';
188}
189exports.isLogin = isLogin;
190function isLoginResponse(r) {
191 const res = r;
192 return isAPIResponseSuccess(res)
193 && typeof res.data === 'object'
194 && isLogin(res.data);
195}
196exports.isLoginResponse = isLoginResponse;
197function isUser(u) {
198 const user = u;
199 return user
200 && typeof user.id === 'number'
201 && typeof user.email === 'string';
202}
203exports.isUser = isUser;
204function isUserResponse(r) {
205 return isAPIResponseSuccess(r)
206 && typeof r.data === 'object'
207 && isUser(r.data);
208}
209exports.isUserResponse = isUserResponse;
210function isSSHKey(k) {
211 const key = k;
212 return key
213 && typeof key.id === 'string'
214 && typeof key.pubkey === 'string'
215 && typeof key.fingerprint === 'string'
216 && typeof key.annotation === 'string'
217 && typeof key.name === 'string'
218 && typeof key.created === 'string'
219 && typeof key.updated === 'string';
220}
221exports.isSSHKey = isSSHKey;
222function isSSHKeyListResponse(r) {
223 if (!isAPIResponseSuccess(r) || !Array.isArray(r.data)) {
224 return false;
225 }
226 if (r.data.length === 0) {
227 return true;
228 }
229 return typeof r.data[0] === 'object' && isSSHKey(r.data[0]);
230}
231exports.isSSHKeyListResponse = isSSHKeyListResponse;
232function isSSHKeyResponse(r) {
233 return isAPIResponseSuccess(r)
234 && typeof r.data === 'object'
235 && isSSHKey(r.data);
236}
237exports.isSSHKeyResponse = isSSHKeyResponse;
238function isSecurityProfile(o) {
239 const obj = o;
240 return obj && typeof obj === 'object'
241 && typeof obj.name === 'string'
242 && typeof obj.tag === 'string'
243 && typeof obj.type === 'string'
244 && typeof obj.created === 'string'
245 && typeof obj.credentials === 'object';
246}
247exports.isSecurityProfile = isSecurityProfile;
248function isSecurityProfileResponse(r) {
249 const res = r;
250 return isAPIResponseSuccess(res) && isSecurityProfile(res.data);
251}
252exports.isSecurityProfileResponse = isSecurityProfileResponse;
253function isTreatableAilment(a) {
254 const ailment = a;
255 return ailment && ailment.treatable && typeof ailment.getTreatmentSteps === 'function';
256}
257exports.isTreatableAilment = isTreatableAilment;
258function isIntegrationName(name) {
259 const n = name;
260 return exports.INTEGRATION_NAMES.includes(n);
261}
262exports.isIntegrationName = isIntegrationName;
263function isProjectConfig(configFile) {
264 return configFile !== undefined && !configFile.hasOwnProperty('projects');
265}
266exports.isProjectConfig = isProjectConfig;
267function isMultiProjectConfig(configFile) {
268 return configFile !== undefined && configFile.hasOwnProperty('projects');
269}
270exports.isMultiProjectConfig = isMultiProjectConfig;