a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto bluesky typescript npm
99
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(lexicon-doc): simplify blob accept constraints with wildcard deduplication

Mary a737a3a8 f6cf57b2

+34 -2
+5
.changeset/simplify-blob-accept-validator.md
··· 1 + --- 2 + '@atcute/lexicon-doc': patch 3 + --- 4 + 5 + simplify blob accept constraints by removing specific types covered by wildcards
+29 -2
packages/lexicons/lexicon-doc/lib/validations.ts
··· 373 373 return cell; 374 374 }; 375 375 376 + const simplifyAccept = (accept: string[] | undefined): string[] | undefined => { 377 + if (accept === undefined || accept.length === 0 || accept.includes('*/*')) { 378 + return undefined; 379 + } 380 + 381 + const wildcards = new Set<string>(); 382 + for (const mime of accept) { 383 + if (mime.endsWith('/*')) { 384 + wildcards.add(mime.slice(0, mime.indexOf('/'))); 385 + } 386 + } 387 + 388 + if (wildcards.size === 0) { 389 + return accept; 390 + } 391 + 392 + const simplified = accept.filter((mime) => { 393 + if (mime.endsWith('/*')) { 394 + return true; 395 + } 396 + return !wildcards.has(mime.slice(0, mime.indexOf('/'))); 397 + }); 398 + 399 + return simplified.length > 0 ? simplified : undefined; 400 + }; 401 + 376 402 const buildLexBlob = (ctx: BuildContext, path: LexPath, spec: t.LexBlob): Cell<v.BaseSchema> => { 377 403 let cell = ctx.cache.get(spec); 378 404 if (cell != undefined) { ··· 381 407 382 408 assertRefine(path, refineLexBlob(spec)); 383 409 384 - const { accept, maxSize } = spec; 410 + const accept = simplifyAccept(spec.accept); 411 + const { maxSize } = spec; 385 412 const constraints: v.BaseConstraint<any>[] = []; 386 413 387 414 if (maxSize !== undefined) { 388 415 constraints.push(v.blobSize(maxSize)); 389 416 } 390 417 391 - if (accept !== undefined && accept.length > 0 && !accept.includes('*/*')) { 418 + if (accept !== undefined) { 392 419 constraints.push(v.blobAccept(accept)); 393 420 } 394 421