UNPKG

@atproto/api

Version:

Client library for atproto and Bluesky

72 lines 2.22 kB
import { z } from 'zod'; import { AtUri } from '@atproto/syntax'; export function sanitizeMutedWordValue(value) { return (value .trim() .replace(/^#(?!\ufe0f)/, '') // eslint-disable-next-line no-misleading-character-class .replace(/[\r\n\u00AD\u2060\u200D\u200C\u200B]+/, '')); } export function savedFeedsToUriArrays(savedFeeds) { const pinned = []; const saved = []; for (const feed of savedFeeds) { if (feed.pinned) { pinned.push(feed.value); // saved in v1 includes pinned saved.push(feed.value); } else { saved.push(feed.value); } } return { pinned, saved, }; } /** * Get the type of a saved feed, used by deprecated methods for backwards * compat. Should not be used moving forward. *Invalid URIs will throw.* * * @param uri - The AT URI of the saved feed */ export function getSavedFeedType(uri) { const urip = new AtUri(uri); switch (urip.collection) { case 'app.bsky.feed.generator': return 'feed'; case 'app.bsky.graph.list': return 'list'; default: return 'unknown'; } } export function validateSavedFeed(savedFeed) { if (!savedFeed.id) { throw new Error('Saved feed must have an `id` - use a TID'); } if (['feed', 'list'].includes(savedFeed.type)) { const uri = new AtUri(savedFeed.value); const isFeed = uri.collection === 'app.bsky.feed.generator'; const isList = uri.collection === 'app.bsky.graph.list'; if (savedFeed.type === 'feed' && !isFeed) { throw new Error(`Saved feed of type 'feed' must be a feed, got ${uri.collection}`); } if (savedFeed.type === 'list' && !isList) { throw new Error(`Saved feed of type 'list' must be a list, got ${uri.collection}`); } } } export const nuxSchema = z .object({ id: z.string().max(64), completed: z.boolean(), data: z.string().max(300).optional(), expiresAt: z.string().datetime().optional(), }) .strict(); export function validateNux(nux) { nuxSchema.parse(nux); } //# sourceMappingURL=util.js.map