All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 50s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import type {
|
|
CreateUrlDumpRequest,
|
|
UpdateDumpRequest,
|
|
} from "../../shared/dump.ts";
|
|
import { VALIDATION } from "../../shared/validation.ts";
|
|
|
|
function isStringArray(value: unknown): value is string[] {
|
|
return Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
}
|
|
|
|
export function isCreateUrlDumpRequest(
|
|
obj: unknown,
|
|
): obj is CreateUrlDumpRequest {
|
|
if (
|
|
!obj || typeof obj !== "object" ||
|
|
!("url" in obj) || typeof obj.url !== "string"
|
|
) return false;
|
|
const o = obj as Record<string, unknown>;
|
|
if (
|
|
"comment" in o && typeof o.comment !== "string" && o.comment !== null
|
|
) return false;
|
|
if (
|
|
typeof o.comment === "string" &&
|
|
(o.comment as string).length > VALIDATION.DUMP_COMMENT_MAX
|
|
) return false;
|
|
if ("title" in o && typeof o.title !== "string" && o.title !== null) {
|
|
return false;
|
|
}
|
|
if (
|
|
typeof o.title === "string" &&
|
|
(o.title as string).length > VALIDATION.DUMP_TITLE_MAX
|
|
) return false;
|
|
if ("isPrivate" in o && typeof o.isPrivate !== "boolean") return false;
|
|
if ("categoryIds" in o && !isStringArray(o.categoryIds)) return false;
|
|
return true;
|
|
}
|
|
|
|
export function isUpdateDumpRequest(obj: unknown): obj is UpdateDumpRequest {
|
|
if (!obj || typeof obj !== "object") return false;
|
|
const o = obj as Record<string, unknown>;
|
|
if ("url" in o && typeof o.url !== "string" && o.url !== null) return false;
|
|
if ("title" in o) {
|
|
if (typeof o.title !== "string") return false;
|
|
const trimmed = (o.title as string).trim();
|
|
if (!trimmed || trimmed.length > VALIDATION.DUMP_TITLE_MAX) return false;
|
|
}
|
|
if (
|
|
"comment" in o && typeof o.comment !== "string" && o.comment !== null
|
|
) return false;
|
|
if (
|
|
typeof o.comment === "string" &&
|
|
(o.comment as string).length > VALIDATION.DUMP_COMMENT_MAX
|
|
) return false;
|
|
if ("isPrivate" in o && typeof o.isPrivate !== "boolean") return false;
|
|
if ("categoryIds" in o && !isStringArray(o.categoryIds)) return false;
|
|
return true;
|
|
}
|