Retaining earlier manuscripts differs from keeping every historical asset public. I inspected how the current media lookup connects publication status and version, then made an anonymous predicate that readers can explore with changed conditions.

Separate historical references from current use

An edit can remove an asset or replace it with another. Previous manuscripts remain useful for recovery but are not identical to current public content. The actual SQL joins a reference to both manuscript identity and current version. A historical use is therefore not treated automatically as present public use.

The new predicate likewise receives one current record per manuscript and compares reference versions. Duplicate current records for one slug are rejected explicitly. It does not select whichever uncertain record happens to appear first. The receiving store needs a unique authoritative current manuscript, with historical revisions managed separately.

Check readiness and review before considering references

A reference from a published article does not establish ordinary public access when the asset is unready or unreviewed. The new function checks readiness and a genuine true review value before finding a current published reference. It does not treat a truth-like string or arbitrary status as the same approval.

This module calculates anonymous public-read eligibility only. Management authentication and expiring signed previews remain separate access paths. A false public result does not mean every administrative read has been blocked. Stored existence, ordinary visitor delivery and reviewer access therefore retain distinct conditions instead of being compressed into one label.

Inspect other current uses of a shared asset

An image or code file can serve several articles. Automatically hiding it when the first article is withdrawn can break another article’s implementation. The actual SQL asks whether any current published reference exists. The new predicate also returns matching manuscript slugs so the supporting references can be inspected.

Before changing visibility, compare that relationship with actual management records. Historical-only use and another article’s current use lead to different next actions. The example lets readers enable another published reference while the first entry is withdrawn. It contains no original customer assets or manuscript identifiers; the relationship is illustrated with anonymous records.

Explore the implementation

Compute ordinary public eligibility from current references

export function currentMediaReference(media,entries,references){
 if(!media||typeof media.id!=='string'||!Array.isArray(entries)||!Array.isArray(references))throw new TypeError('Explicit media and current entries/references required');
 if(media.state!=='ready')return {public:false,reason:'not-ready',slugs:[]};
 if(media.reviewed!==true)return {public:false,reason:'review-required',slugs:[]};
 const current=new Map();
 for(const entry of entries){
  if(!entry||typeof entry.slug!=='string'||!entry.slug||!Number.isSafeInteger(entry.version)||entry.version<1||current.has(entry.slug))throw new TypeError('Unique current entries and positive versions required');
  current.set(entry.slug,entry);
 }
 const slugs=[...new Set(references.filter(reference=>{
  const entry=current.get(reference.slug);
  return reference.media_id===media.id&&entry?.status==='published'&&entry.version===reference.version;
 }).map(reference=>reference.slug))];
 return {public:slugs.length>0,reason:slugs.length?'current-published-reference':'no-current-published-reference',slugs,scope:'Anonymous public-read predicate only. Administrator access and expiring previews are separate; no deletion or recall of downloaded copies.'};
}

Compare the actual query and the new predicate independently

A readable new function can still mislead if its conditions differ from the receiving store. I extracted the actual lookup SQL from source and executed it in local in-memory SQLite. Seven conditions covered old and current revisions, draft and withdrawn entries, shared use, absent review and removed references. Results were compared with the new JavaScript predicate.

Those checks changed no remote D1 operating data. The public function explains the decision; it does not implement the database transaction or authorization system. Agreement between query and predicate is retained as bounded evidence, not expanded into verification of every operating race or cache layer. The independent comparison makes the explanation accountable to the actual source condition.

Change example versions to understand the visibility decision

The model keeps the current manuscript at version two while its reference can point at version one or two. Publication state, media review and another entry’s shared reference can also change. The returned reason and matching slugs explain which condition affected the decision. The interaction remains inside the model and changes no actual content or media visibility.

New rendered browser interaction is still unreviewed. An integration should continue through manuscript storage, current-reference updates and the resulting media response. I want to retain historical recovery material while reading today’s visitor-facing delivery through current-version conditions. Storage history and public delivery keep related but distinguishable responsibilities.