app/lib/search/visibility.mjs
27 lines and 2 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| statusForDraft | 11 to 13 | 2 | 100% | OkCRAP 2 | Ok100% |
| isPubliclyVisible | 23 to 33 | 8 | 100% | WatchCRAP 8 | Ok96.6% |
Imports
It imports no other module of this repo. Imported by app/db/client.ts, app/db/dictionary.ts, app/db/pages.ts, app/db/posts.ts, app/db/procedures.ts, app/db/publications.ts, app/lib/content/corpus.mjs, app/lib/editor/post-rows.server.ts, app/lib/search/ask.server.ts, app/lib/search/records.mjs, app/lib/search/search.server.ts.
Source
// Ask has no per-item status, so it must filter at UPLOAD time and composes this rather than restating
// the rule. The FTS build includes drafts on purpose; classic search filters at query time.
/** One spelling: a typo in a status literal fails OPEN on a filter. */
export const PUBLISHED_STATUS = "published";
/**
* @param {boolean | undefined} draft
* @returns {string}
*/
export function statusForDraft(draft) {
return draft === true ? "draft" : PUBLISHED_STATUS;
}
/**
* A missing publishAt means publish immediately, not never. An unparseable one is NOT visible: fail
* closed, since the other way a draft answers a public question on Ask.
*
* @param {{ status?: string, publishAt?: string | Date | number | null }} post
* @param {number} nowMs
* @returns {boolean}
*/
export function isPubliclyVisible(post, nowMs = Date.now()) {
if (post.status !== PUBLISHED_STATUS) return false;
const at = post.publishAt;
if (at === null || at === undefined || at === "") return true;
const when = at instanceof Date ? at.getTime() : typeof at === "number" ? at : Date.parse(at);
if (Number.isNaN(when)) return false;
return when <= nowMs;
}