Skip to content

Commit 95c100d

Browse files
robingenzclaude
andauthored
refactor: helpers take the subject and one object of named values (#123)
The error classes and the helpers that took two values of one type, or an optional or nullable value by position, now take the subject first and the rest in one destructured object, so a call reads without the signature. The prompts, fetchResourceId, waitUntilLive, ApiError and InvalidParameterError already had this shape since the shape pass. Two functions passed the line cap after the reformat, so the React host import write and the missing Gradle file edit are their own functions. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 8b9b4c4 commit 95c100d

59 files changed

Lines changed: 566 additions & 376 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/commands/binary/create.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ async function createBuildBinary(
203203
const channelIdByShape = resolveChannelIdByShape(buildStep.channelReference);
204204
const offlineCause = resolveOfflineCause();
205205
if (offlineCause !== undefined) {
206-
return resolveOfflineCreation(offlineCause, channelIdByShape);
206+
return resolveOfflineCreation(offlineCause, { channelIdByShape });
207207
}
208208
const hotCodePush = createApiClient();
209209
let channelId: string;
@@ -338,7 +338,7 @@ function resolveFailedCreation(
338338

339339
function resolveOfflineCreation(
340340
offlineCause: OfflineCause,
341-
channelIdByShape: string | null,
341+
{ channelIdByShape }: { channelIdByShape: string | null },
342342
): BinaryCreation {
343343
if (offlineCause === 'no-token' && isCi()) {
344344
return resolveFailedCreation(
@@ -349,14 +349,16 @@ function resolveOfflineCreation(
349349
return {
350350
binary: null,
351351
channelId: channelIdByShape,
352-
skippedReason: resolveOfflineText(offlineCause, channelIdByShape),
352+
skippedReason: resolveOfflineText(offlineCause, {
353+
channelId: channelIdByShape,
354+
}),
353355
upload: NO_UPLOAD,
354356
};
355357
}
356358

357359
function resolveOfflineText(
358360
offlineCause: OfflineCause,
359-
channelId: string | null,
361+
{ channelId }: { channelId: string | null },
360362
): string {
361363
const causeText =
362364
offlineCause === 'offline-switch'

‎src/commands/bundle/upload.test.ts‎

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,13 @@ describe('bundle upload', () => {
140140
);
141141
}
142142

143-
function respondWithBinaryCounts(
144-
binaryCount: number,
145-
fingerprintBinaryCount: number,
146-
): void {
143+
function respondWithBinaryCounts({
144+
binaryCount,
145+
fingerprintBinaryCount,
146+
}: {
147+
binaryCount: number;
148+
fingerprintBinaryCount: number;
149+
}): void {
147150
harness.routes[`GET ${BINARY_COUNT_PATH}`] = () =>
148151
Response.json({ count: binaryCount });
149152
harness.routes[
@@ -155,7 +158,7 @@ describe('bundle upload', () => {
155158
harness.routes[`POST ${BUNDLES_PATH}`] = () =>
156159
Response.json({ ...READY_BUNDLE, status: 'uploading' }, { status: 201 });
157160
respondWithMissingFiles();
158-
respondWithBinaryCounts(1, 1);
161+
respondWithBinaryCounts({ binaryCount: 1, fingerprintBinaryCount: 1 });
159162
harness.routes[`PUT /v1/apps/${DEMO_APP.id}/files/${APP_JS_SHA256}`] =
160163
request => {
161164
// The upload removes its temporary files when it ends, so the bytes are read as each request arrives.
@@ -178,10 +181,13 @@ describe('bundle upload', () => {
178181
Response.json(READY_BUNDLE);
179182
}
180183

181-
function readRequest(
182-
method: string,
183-
pathSuffix: string,
184-
): Request | undefined {
184+
function readRequest({
185+
method,
186+
pathSuffix,
187+
}: {
188+
method: string;
189+
pathSuffix: string;
190+
}): Request | undefined {
185191
return harness.requests.find(
186192
request =>
187193
request.method === method &&
@@ -201,11 +207,14 @@ describe('bundle upload', () => {
201207
undefined,
202208
);
203209

204-
const createRequest = readRequest('POST', '/bundles');
205-
const filesRequest = readRequest(
206-
'GET',
207-
`/bundles/${READY_BUNDLE.id}/files`,
208-
);
210+
const createRequest = readRequest({
211+
method: 'POST',
212+
pathSuffix: '/bundles',
213+
});
214+
const filesRequest = readRequest({
215+
method: 'GET',
216+
pathSuffix: `/bundles/${READY_BUNDLE.id}/files`,
217+
});
209218
expect(
210219
Object.fromEntries(new URL(filesRequest?.url ?? API_URL).searchParams),
211220
).toEqual({ isStored: 'false', limit: '1000', offset: '0' });
@@ -224,7 +233,10 @@ describe('bundle upload', () => {
224233
platforms: ['ios'],
225234
signature: null,
226235
});
227-
const fileRequest = readRequest('PUT', `/files/${APP_JS_SHA256}`);
236+
const fileRequest = readRequest({
237+
method: 'PUT',
238+
pathSuffix: `/files/${APP_JS_SHA256}`,
239+
});
228240
expect(fileRequest).toBeDefined();
229241
expect(fileRequest?.headers.get('content-type')).toBe('application/gzip');
230242
expect(Number(fileRequest?.headers.get('content-length'))).toBeGreaterThan(
@@ -235,12 +247,16 @@ describe('bundle upload', () => {
235247
Buffer.from((await uploadedFileBytes) ?? new ArrayBuffer(0)),
236248
).toString(),
237249
).toBe(APP_JS);
238-
expect(readRequest('PUT', `/files/${INDEX_SHA256}`)).toBeUndefined();
250+
expect(
251+
readRequest({ method: 'PUT', pathSuffix: `/files/${INDEX_SHA256}` }),
252+
).toBeUndefined();
239253
const packEntries = await readPackEntries(
240254
(await uploadedPackBytes) ?? new ArrayBuffer(0),
241255
);
242256
expect([...packEntries.keys()]).toEqual([APP_JS_SHA256, INDEX_SHA256]);
243-
expect(readRequest('POST', '/complete')).toBeDefined();
257+
expect(
258+
readRequest({ method: 'POST', pathSuffix: '/complete' }),
259+
).toBeDefined();
244260
expect(harness.readLines()).toEqual([
245261
'Uploaded bundle #17 · 1.4.2.',
246262
`ID ${READY_BUNDLE.id}`,
@@ -262,7 +278,9 @@ describe('bundle upload', () => {
262278
undefined,
263279
);
264280

265-
expect(await readRequest('POST', '/bundles')?.json()).toMatchObject({
281+
expect(
282+
await readRequest({ method: 'POST', pathSuffix: '/bundles' })?.json(),
283+
).toMatchObject({
266284
files: [
267285
{ path: 'assets/app.js', sha256: APP_JS_SHA256, sizeBytes: 14 },
268286
{ path: 'index.html', sha256: INDEX_SHA256, sizeBytes: 11 },
@@ -310,23 +328,23 @@ describe('bundle upload', () => {
310328
}
311329

312330
it("should warn on stderr when the app has binaries and none carries the bundle's fingerprint", async () => {
313-
respondWithBinaryCounts(2, 0);
331+
respondWithBinaryCounts({ binaryCount: 2, fingerprintBinaryCount: 0 });
314332

315333
await runBundleUpload();
316334

317335
expect(harness.readDiagnostics()).toBe(FINGERPRINT_WARNING);
318336
});
319337

320338
it('should stay silent when the app has no binary yet', async () => {
321-
respondWithBinaryCounts(0, 0);
339+
respondWithBinaryCounts({ binaryCount: 0, fingerprintBinaryCount: 0 });
322340

323341
await runBundleUpload();
324342

325343
expect(harness.readDiagnostics()).not.toContain(FINGERPRINT_WARNING);
326344
});
327345

328346
it("should stay silent and count no other binary when a binary carries the bundle's fingerprint", async () => {
329-
respondWithBinaryCounts(2, 1);
347+
respondWithBinaryCounts({ binaryCount: 2, fingerprintBinaryCount: 1 });
330348

331349
await runBundleUpload();
332350

@@ -396,7 +414,10 @@ describe('bundle upload', () => {
396414
);
397415

398416
const { files, fingerprint, platforms, signature, version } =
399-
(await readRequest('POST', '/bundles')?.json()) as {
417+
(await readRequest({
418+
method: 'POST',
419+
pathSuffix: '/bundles',
420+
})?.json()) as {
400421
files: object[];
401422
fingerprint: string;
402423
platforms: string[];
@@ -426,14 +447,19 @@ describe('bundle upload', () => {
426447
it('should sign the manifest with the private key file --private-key-path names', async () => {
427448
respondWithUploadRoutes();
428449
const privateKeyPath = join(projectDirectoryPath, 'private-key.pem');
429-
writeSigningPrivateKeyFile(privateKeyPath, SIGNING_PRIVATE_KEY);
450+
writeSigningPrivateKeyFile(privateKeyPath, {
451+
privateKey: SIGNING_PRIVATE_KEY,
452+
});
430453

431454
await bundleUploadCommand.action(
432455
{ config: listPublicKey(), json: true, noGit: true, privateKeyPath },
433456
undefined,
434457
);
435458

436-
const { signature } = (await readRequest('POST', '/bundles')?.json()) as {
459+
const { signature } = (await readRequest({
460+
method: 'POST',
461+
pathSuffix: '/bundles',
462+
})?.json()) as {
437463
signature: { keyId: string };
438464
};
439465
expect(signature.keyId).toBe(SIGNING_KEY.keyId);
@@ -515,7 +541,9 @@ describe('bundle upload', () => {
515541
message: 'Which version label does the bundle carry?',
516542
}),
517543
);
518-
expect(await readRequest('POST', '/bundles')?.json()).toMatchObject({
544+
expect(
545+
await readRequest({ method: 'POST', pathSuffix: '/bundles' })?.json(),
546+
).toMatchObject({
519547
version: '2.0.0',
520548
});
521549
});
@@ -579,7 +607,7 @@ describe('bundle upload', () => {
579607
{ status: 201 },
580608
);
581609
respondWithMissingFiles([]);
582-
respondWithBinaryCounts(1, 1);
610+
respondWithBinaryCounts({ binaryCount: 1, fingerprintBinaryCount: 1 });
583611
harness.routes[`PUT ${BUNDLES_PATH}/${READY_BUNDLE.id}/pack`] = () =>
584612
Response.json({ sizeBytes: 1536 });
585613
harness.routes[`POST ${BUNDLES_PATH}/${READY_BUNDLE.id}/complete`] = () =>
@@ -668,7 +696,9 @@ describe('bundle upload', () => {
668696
);
669697

670698
expect(runCommandLineVisibly).not.toHaveBeenCalled();
671-
expect(await readRequest('POST', '/bundles')?.json()).toMatchObject({
699+
expect(
700+
await readRequest({ method: 'POST', pathSuffix: '/bundles' })?.json(),
701+
).toMatchObject({
672702
files: [expect.objectContaining({ path: 'main.jsbundle' })],
673703
platforms: ['ios'],
674704
});

‎src/commands/channel/get.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export default defineCommand({
5252
),
5353
['Active devices', String(fleet.deviceCount)],
5454
['Current devices', String(fleet.currentDeviceCount)],
55-
['Embedded devices', String(resolveReleaseDeviceCount(fleet, null))],
55+
[
56+
'Embedded devices',
57+
String(resolveReleaseDeviceCount(fleet, { releaseId: null })),
58+
],
5659
['Created', fetchedChannel.createdAt],
5760
]);
5861
},

‎src/commands/device/list.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ export default defineCommand({
9191
printJson({ devices: listedDevices, nextOffset });
9292
return;
9393
}
94-
printDeviceTable(listedDevices, nextOffset);
94+
printDeviceTable(listedDevices, { nextOffset });
9595
},
9696
});
9797

9898
function printDeviceTable(
9999
listedDevices: Device[],
100-
nextOffset: number | null,
100+
{ nextOffset }: { nextOffset: number | null },
101101
): void {
102102
printTable({
103103
emptyText: 'No devices match. A device appears with its first check.',

‎src/commands/device/probe.ts‎

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,15 @@ export default defineCommand({
117117
action: async options => {
118118
const hotCodePush = createApiClient();
119119
const target = await fetchProbeTarget(hotCodePush, options);
120-
const identity = await promptBinaryIdentity(options, target.fetchedDevice);
121-
const binary = await fetchBinary(hotCodePush, {
122-
appId: target.appId,
123-
identity,
124-
});
120+
const { appId, channel, fetchedDevice } = target;
121+
const identity = await promptBinaryIdentity(options, { fetchedDevice });
122+
const binary = await fetchBinary(hotCodePush, { appId, identity });
125123
const servedIndex = await fetchServedIndex({
126-
appId: target.appId,
127-
channelId: target.channel.id,
124+
appId,
125+
channelId: channel.id,
128126
platform: identity.platform,
129127
});
130-
const unknownFacts = resolveUnknownFacts(target.fetchedDevice, binary);
128+
const unknownFacts = resolveUnknownFacts({ binary, fetchedDevice });
131129
const device = await fetchDeviceInfo(hotCodePush, {
132130
binary,
133131
identity,
@@ -137,7 +135,7 @@ export default defineCommand({
137135
});
138136
const probe: Probe = {
139137
builtAt: binary?.createdAt ?? null,
140-
channel: target.channel,
138+
channel,
141139
device,
142140
evaluation:
143141
servedIndex.index === null
@@ -267,14 +265,17 @@ async function fetchDeviceInfo(
267265
},
268266
): Promise<DeviceInfo> {
269267
return {
270-
attributes: resolveDeviceAttributes(fetchedDevice, options.attribute),
268+
attributes: resolveDeviceAttributes({
269+
attribute: options.attribute,
270+
fetchedDevice,
271+
}),
271272
binaryBuild: identity.binaryBuild,
272273
binaryVersion: identity.binaryVersion,
273274
builtAt: binary?.createdAt ?? NO_FLOOR,
274275
...(fetchedDevice === undefined
275276
? { currentRelease: null, failedBundleIds: [] }
276277
: await fetchDeviceHistory(hotCodePush, { fetchedDevice, servedIndex })),
277-
...resolveReportedFacts(fetchedDevice, binary),
278+
...resolveReportedFacts({ binary, fetchedDevice }),
278279
};
279280
}
280281

@@ -292,7 +293,7 @@ async function fetchFailedBundleIds(
292293
...page,
293294
}),
294295
);
295-
return resolveFailedBundleIds(events, servedIndex.index);
296+
return resolveFailedBundleIds(events, { index: servedIndex.index });
296297
}
297298

298299
async function fetchProbeTarget(
@@ -409,7 +410,7 @@ function printProbeJson({
409410
// A flag wins over the probed device, and a missing fact is asked for.
410411
async function promptBinaryIdentity(
411412
options: ProbeOptions,
412-
fetchedDevice: Device | undefined,
413+
{ fetchedDevice }: { fetchedDevice: Device | undefined },
413414
): Promise<BinaryIdentity> {
414415
const platform =
415416
options.platform ??
@@ -454,10 +455,13 @@ function resolveConditionsText(
454455
return conditionTexts.join(', ') || 'none';
455456
}
456457

457-
function resolveDeviceAttributes(
458-
fetchedDevice: Device | undefined,
459-
attribute: string[] | undefined,
460-
): DeviceInfo['attributes'] {
458+
function resolveDeviceAttributes({
459+
attribute,
460+
fetchedDevice,
461+
}: {
462+
attribute: string[] | undefined;
463+
fetchedDevice: Device | undefined;
464+
}): DeviceInfo['attributes'] {
461465
return {
462466
...fetchedDevice?.attributes,
463467
...Object.fromEntries(
@@ -468,7 +472,7 @@ function resolveDeviceAttributes(
468472

469473
function resolveFailedBundleIds(
470474
events: readonly ReleaseDeviceEvent[],
471-
index: ChannelIndex | null,
475+
{ index }: { index: ChannelIndex | null },
472476
): string[] {
473477
const failedReleaseIds = new Set(
474478
events
@@ -496,10 +500,13 @@ function resolveOutcomeText({ outcome }: ChannelIndexEvaluation): string {
496500
}
497501

498502
// Without a probed device, the binary's fingerprint stands in for the device's.
499-
function resolveReportedFacts(
500-
fetchedDevice: Device | undefined,
501-
binary: Binary | undefined,
502-
): Pick<DeviceInfo, 'deviceId' | 'fingerprint' | 'osVersion' | 'reportedAt'> {
503+
function resolveReportedFacts({
504+
binary,
505+
fetchedDevice,
506+
}: {
507+
binary: Binary | undefined;
508+
fetchedDevice: Device | undefined;
509+
}): Pick<DeviceInfo, 'deviceId' | 'fingerprint' | 'osVersion' | 'reportedAt'> {
503510
const binaryFingerprint = binary?.fingerprint ?? null;
504511
if (fetchedDevice === undefined) {
505512
return {
@@ -524,10 +531,13 @@ function resolveServedIndexText({ index, status, url }: ServedIndex): string {
524531
: `published ${new Date(index.sequence).toISOString()}`;
525532
}
526533

527-
function resolveUnknownFacts(
528-
fetchedDevice: Device | undefined,
529-
binary: Binary | undefined,
530-
): UnknownFact[] {
534+
function resolveUnknownFacts({
535+
binary,
536+
fetchedDevice,
537+
}: {
538+
binary: Binary | undefined;
539+
fetchedDevice: Device | undefined;
540+
}): UnknownFact[] {
531541
if (fetchedDevice !== undefined) {
532542
return [];
533543
}

0 commit comments

Comments
 (0)