Skip to content

Commit 25fb4d9

Browse files
committed
refactor: share push JSON detection and clean extras validation
1 parent 3d58cb5 commit 25fb4d9

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/core/dispatch.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { isDeepLinkTarget } from './open-target.ts';
2020
import type { RawSnapshotNode } from '../utils/snapshot.ts';
2121
import type { CliFlags } from '../utils/command-schema.ts';
2222
import { emitDiagnostic, withDiagnosticTimer } from '../utils/diagnostics.ts';
23+
import { looksLikeInlineJson } from '../utils/json-input.ts';
2324

2425
export type BatchStep = {
2526
command: string;
@@ -566,10 +567,6 @@ async function readNotificationPayload(payloadArg: string): Promise<Record<strin
566567
}
567568
}
568569

569-
function looksLikeInlineJson(value: string): boolean {
570-
return (value.startsWith('{') && value.endsWith('}')) || (value.startsWith('[') && value.endsWith(']'));
571-
}
572-
573570
async function resolvePushPayloadText(payloadArg: string, trimmedArg: string): Promise<string> {
574571
const filePayload = await tryReadPushPayloadFile(payloadArg);
575572
if (filePayload !== null) return filePayload;

src/daemon/handlers/session.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
isClickLikeCommand,
3333
parseReplaySeriesFlags,
3434
} from '../script-utils.ts';
35+
import { looksLikeInlineJson } from '../../utils/json-input.ts';
3536
import {
3637
appendAppLogMarker,
3738
clearAppLogFiles,
@@ -880,10 +881,7 @@ function maybeResolvePushPayloadPath(payloadArg: string, cwd?: string): string {
880881
}
881882
return resolvedPath;
882883
}
883-
if (
884-
(trimmed.startsWith('{') && trimmed.endsWith('}')) ||
885-
(trimmed.startsWith('[') && trimmed.endsWith(']'))
886-
) {
884+
if (looksLikeInlineJson(trimmed)) {
887885
return trimmed;
888886
}
889887
throw new AppError('INVALID_ARGS', `Push payload file not found: ${resolvedPath}`);

src/utils/json-input.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function looksLikeInlineJson(value: string): boolean {
2+
const trimmed = value.trim();
3+
return (trimmed.startsWith('{') && trimmed.endsWith('}')) || (trimmed.startsWith('[') && trimmed.endsWith(']'));
4+
}
5+

0 commit comments

Comments
 (0)