import type { Block, KnownBlock } from "@slack/web-api";
export const SLACK_MAX_BLOCKS = 50;
function parseBlocksJson(raw: string) { try { return JSON.parse(raw);
} catch { thrownew Error("blocks must be valid JSON");
}
}
function assertBlocksArray(raw: unknown) { if (!Array.isArray(raw)) { thrownew Error("blocks must be an array");
} if (raw.length === 0) { thrownew Error("blocks must contain at least one block");
} if (raw.length > SLACK_MAX_BLOCKS) { thrownew Error(`blocks cannot exceed ${SLACK_MAX_BLOCKS} items`);
} for (const block of raw) { if (!block || typeof block !== "object" || Array.isArray(block)) { thrownew Error("each block must be an object");
} const type = (block as { type?: unknown }).type; if (typeof type !== "string" || type.trim().length === 0) { thrownew Error("each block must include a non-empty string type");
}
}
}
export function validateSlackBlocksArray(raw: unknown): (Block | KnownBlock)[] {
assertBlocksArray(raw); return raw as (Block | KnownBlock)[];
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.