// SPDX-FileCopyrightText: 2026 Kerstin Humm // // SPDX-License-Identifier: AGPL-3.0-or-later import { isJsonArray, isUrl, JsonValue, Rule } from "../types.js"; export default { name: "to attribute", validate: (self) => { if (isJsonArray(self["to"])) { return { annotations: [], object: { "to": { annotations: [], array: self["to"].map((url: JsonValue) => (typeof url === "string") ? (isUrl(url) ? { kind: "Correct", text: "Correct URL", } : { kind: "Violation", text: "Not a valid URL", }) : { kind: "Violation", text: "url is not a string", } ), }, }, }; } else { return { annotations: [], object: { "to": { kind: "Violation", id: "InvalidArray", text: `The to field ${self["to"]} is not an array`, }, }, }; } }, tests: [{ value: { "to": ["https://www.w3.org/ns/activitystreams#Public"] }, result: { annotations: [], object: { "to": { annotations: [], array: ["Correct"] } }, }, }], } satisfies Rule;