diff --git a/AGENTS.md b/AGENTS.md index 64c2585..99713c3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -8,3 +8,5 @@ - `pnpm install:api` sends admin requests to a HappyView instance and uploads assets. Do not run it unless the user explicitly approves the target and token in the current conversation. - HTTP runtime tests use a task-owned local Compose project and disposable database. Do not target or tear down unrelated services; note that the Compose bridge network permits egress and the configured proxy is not network-level isolation. - Every new query endpoint needs a case in `happyview-modules/tooling/smoke-cases.js`. Add it to `happyview-modules/tooling/e2e.js` only if it has paging walks, count invariants or batch behaviour. When an endpoint's behavior changes, update the checks that cover it. +- Reuse and extend the canonical Lua helpers in `happyview-modules/lua/shared/` instead of writing a new copy in a handler or another shared file. Before writing a helper, search `happyview-modules/lua/shared/` and `happyview-modules/tooling/shared-helpers.registry.json` for an existing one; the lint only catches some copies. Families: DID, NSID, record URI/key, subject URI, datetime, handle/resolver, list cursor, list limit/includeTotal/sortDirection, query parameter helpers (`invalid`, `keys_only`, `scalar`), record view, actor view and batch request-target. Repeated-parameter (array) parsing has no shared helper yet. +- `pnpm lint` (so `pnpm check` and CI) runs `happyview-modules/tooling/lint-shared-helpers.js` on `lua/shared` and `lua/src`. Every top-level function defined in `lua/shared` is protected automatically: defining the same name in another shared file or in `lua/src` fails lint and names the file that owns it. Nothing to register for a new shared helper, but check the names already there first. `shared-helpers.registry.json` (paths relative to `happyview-modules/`) holds only lookalike name patterns and inline code patterns per family (`id`, `description`, `homes` = files where the patterns legitimately appear, `lookalikes`/`inline`) and the `allowlist`. To keep an existing copy, add `{file, family, symbol, reason}` to `allowlist` (`family` is `shared-helper` for a name defined in `lua/shared`; `symbol` is the function name or inline rule id; add `count` if it occurs more than once). The failure message prints a ready-made entry. An entry that no longer matches fails lint; delete it. The current allowlist is a baseline, not approval for new copies. diff --git a/biome.json b/biome.json index 2317ee8..1cb2672 100644 --- a/biome.json +++ b/biome.json @@ -104,7 +104,8 @@ "happyview-modules/tooling/seed.js", "happyview-modules/tooling/smoke.js", "happyview-modules/tooling/e2e.js", - "happyview-modules/tooling/lint-lua.js" + "happyview-modules/tooling/lint-lua.js", + "happyview-modules/tooling/lint-shared-helpers.js" ], "linter": { "rules": { diff --git a/happyview-modules/package.json b/happyview-modules/package.json index 991d546..1286703 100644 --- a/happyview-modules/package.json +++ b/happyview-modules/package.json @@ -11,7 +11,8 @@ }, "scripts": { "lint:lua": "node tooling/lint-lua.js", - "lint": "pnpm run lint:lua", + "lint:shared-helpers": "node tooling/lint-shared-helpers.js", + "lint": "pnpm run lint:lua && pnpm run lint:shared-helpers", "typecheck": "tsc --project tsconfig.json", "check:generated": "node tooling/build-lua.js --check", "check": "pnpm run check:generated && pnpm run lint && pnpm run typecheck && pnpm run test:unit", diff --git a/happyview-modules/tooling/lint-shared-helpers.js b/happyview-modules/tooling/lint-shared-helpers.js new file mode 100644 index 0000000..357a41b --- /dev/null +++ b/happyview-modules/tooling/lint-shared-helpers.js @@ -0,0 +1,387 @@ +import { readdir, readFile } from "node:fs/promises"; +import path from "node:path"; +import { fileURLToPath, pathToFileURL } from "node:url"; + +const defaultRoot = fileURLToPath(new URL("../", import.meta.url)); +const registryFile = "tooling/shared-helpers.registry.json"; +// Handwritten Lua only. lua/endpoints is generated by build-lua.js from these directories. +const scannedDirectories = ["lua/shared", "lua/src"]; + +// Matches `function name(`, `function M.name(`, `function M:name(` and `M.name = function(`. +// Only the last segment is the helper's name, so a module-table copy is still a copy. +// \s* also spans newlines, so a definition split across lines is still found. +const DEFINITION_PATTERNS = [ + /^[ \t]*(?:local\s+)?function\s+([A-Za-z_]\w*(?:\s*[.:]\s*[A-Za-z_]\w*)*)\s*\(/gm, + /^[ \t]*(?:local\s+)?([A-Za-z_]\w*(?:\s*\.\s*[A-Za-z_]\w*)*)\s*=\s*function\s*\(/gm, +]; + +// Every top-level function in lua/shared is protected. It is not a registry family, so it has no patterns. +const SHARED_FAMILY = { + id: "shared-helper", + description: "a function already defined in lua/shared", + homes: [], +}; + +async function luaFiles(root, directory) { + const entries = await readdir(path.join(root, directory), { + withFileTypes: true, + recursive: true, + }); + return entries + .filter((entry) => entry.isFile() && entry.name.endsWith(".lua")) + .map((entry) => + path.relative(root, path.join(entry.parentPath, entry.name)).split(path.sep).join("/"), + ) + .sort(); +} + +// Sticky: matches only at lastIndex. +const LONG_BRACKET = /\[(=*)\[/y; + +const blank = (text) => text.replace(/[^\n]/g, " "); + +/** End offset of the long bracket (`[[`, `[==[`) opening at `open`, or null if there is none. */ +function longBracketEnd(source, open) { + LONG_BRACKET.lastIndex = open; + const long = LONG_BRACKET.exec(source); + if (!long) return null; + const close = `]${long[1]}]`; + const end = source.indexOf(close, open + long[0].length); + return end === -1 ? source.length : end + close.length; +} + +/** End offset of the quoted string opening at `i`; an unclosed string stops after the newline. */ +function quotedEnd(source, i) { + let stop = i + 1; + while (stop < source.length && source[stop] !== source[i] && source[stop] !== "\n") { + stop += source[stop] === "\\" ? 2 : 1; + } + return Math.min(stop + 1, source.length); +} + +/** The comment, string or single code character starting at `i`, with its end offset. */ +function luaToken(source, i) { + if (source.startsWith("--", i)) { + const longStop = longBracketEnd(source, i + 2); + if (longStop !== null) return { kind: "comment", stop: longStop }; + const end = source.indexOf("\n", i); + return { kind: "comment", stop: end === -1 ? source.length : end }; + } + const longStop = longBracketEnd(source, i); + if (longStop !== null) return { kind: "longString", stop: longStop }; + if (source[i] === '"' || source[i] === "'") return { kind: "quoted", stop: quotedEnd(source, i) }; + return { kind: "code", stop: i + 1 }; +} + +function renderToken(kind, text, keepStrings) { + if (kind === "code" || (keepStrings && kind !== "comment")) return text; + if (kind === "quoted") return text[0] + blank(text.slice(1, -1)) + text.slice(-1); + return blank(text); +} + +/** + * Returns the source with Lua comments blanked to spaces, and string contents too unless + * keepStrings is set. Newlines and offsets are preserved so matches map back to lines. + * Tracking both together is what keeps a `--` inside a string and a `function` inside a + * long comment from being misread. + */ +function blankLua(source, { keepStrings = false } = {}) { + let out = ""; + let i = 0; + while (i < source.length) { + const { kind, stop } = luaToken(source, i); + out += renderToken(kind, source.slice(i, stop), keepStrings); + i = stop; + } + return out; +} + +/** Block nesting depth before each offset: function/if/do/repeat open, end/until close. */ +function depthTracker(code) { + const events = [...code.matchAll(/\b(function|if|do|repeat|end|until)\b/g)].map((m) => ({ + index: m.index, + delta: m[1] === "end" || m[1] === "until" ? -1 : 1, + })); + return (offset) => + events.filter((event) => event.index < offset).reduce((sum, event) => sum + event.delta, 0); +} + +/** Every function definition in a Lua file: last-segment name, 1-based line, top-level or nested, local or not. */ +function definitions(source) { + const code = blankLua(source); + const depthAt = depthTracker(code); + return DEFINITION_PATTERNS.flatMap((pattern) => + [...code.matchAll(pattern)].map((match) => { + const nameStart = match.index + match[0].indexOf(match[1]); + return { + name: match[1].split(/[.:]/).pop().trim(), + // Report the line of the name, not of leading blank space. + line: code.slice(0, nameStart).split("\n").length, + topLevel: depthAt(match.index) === 0, + // A nested definition without `local` still assigns a global, so it replaces any + // earlier binding of the name once the files are concatenated into one chunk. + isLocal: /^\s*local\s/.test(match[0]), + }; + }), + ); +} + +function familyProblems(family, seen) { + const problems = []; + if (!family.id || seen.has(family.id)) + problems.push(`family id missing or duplicated: ${family.id}`); + seen.add(family.id); + if (!family.description) problems.push(`family ${family.id} needs a description`); + if (!Array.isArray(family.homes)) problems.push(`family ${family.id} needs a homes array`); + if (family.homes?.length === 0 && !family.unowned) { + problems.push( + `family ${family.id} has no homes; set "unowned": "" or name the shared file where its patterns belong`, + ); + } + if (!family.lookalikes?.length && !family.inline?.length) { + problems.push(`family ${family.id} needs "lookalikes" or "inline" patterns`); + } + return problems; +} + +function allowlistEntryProblems(entry, index, entries) { + const problems = []; + const first = entries.findIndex( + (other) => + other.file === entry.file && other.family === entry.family && other.symbol === entry.symbol, + ); + if (first !== index) { + problems.push( + `allowlist has more than one entry for ${entry.file} / ${entry.family} / ${entry.symbol}; keep one and set "count"`, + ); + } + if (entry.count !== undefined && !(Number.isInteger(entry.count) && entry.count >= 1)) { + problems.push( + `allowlist entry ${JSON.stringify(entry)} has an invalid "count"; use a positive integer`, + ); + } + for (const key of ["file", "family", "symbol", "reason"]) { + if (typeof entry[key] !== "string" || !entry[key].trim()) { + problems.push( + `allowlist entry ${JSON.stringify(entry)} needs a nonempty "${key}" (reason says why the copy must stay)`, + ); + } + } + return problems; +} + +/** Throws one error listing every problem in the registry itself, so a bad edit fails loudly. */ +function validateRegistry(registry) { + const seen = new Set(); + const problems = [ + ...(registry.families ?? []).flatMap((family) => familyProblems(family, seen)), + ...(registry.allowlist ?? []).flatMap(allowlistEntryProblems), + ]; + if (problems.length > 0) { + throw new Error(`Invalid ${registryFile}:\n- ${problems.join("\n- ")}`); + } +} + +function registryFindings(registry, sources) { + return registry.families.flatMap((family) => + family.homes + .filter((home) => !sources.has(home)) + .map((home) => ({ + message: `${registryFile}: family "${family.id}" home ${home} does not exist. Update the path or remove it.`, + })), + ); +} + +function homeHint(family) { + if (family.homes.length === 0) { + return `No shared helper exists yet (${family.unowned}).`; + } + return `Use the shared helper from ${family.homes.join(" or ")} (declare it in the module's sharedSourcePaths).`; +} + +/** + * Maps each top-level function name in lua/shared to the file that owns it: a registered home + * if one defines it, otherwise the first file that does. + */ +function sharedHelperOwners(parsed, registry) { + const homes = new Set(registry.families.flatMap((family) => family.homes)); + const owners = new Map(); + for (const [file, { defs }] of parsed) { + if (!file.startsWith("lua/shared/")) continue; + for (const def of defs) { + if (!def.topLevel) continue; + if (!owners.has(def.name) || (homes.has(file) && !homes.has(owners.get(def.name)))) { + owners.set(def.name, file); + } + } + } + return owners; +} + +function patternFindings(family, file, { defs, inlineLines }, shared) { + const findings = []; + const lookalikes = (family.lookalikes ?? []).map((pattern) => new RegExp(pattern)); + for (const { name, line } of defs) { + const owner = shared.get(name); + // A copy of a name another shared file defines is reported once, as a shared-helper copy. + if ((!owner || owner === file) && lookalikes.some((regex) => regex.test(name))) { + findings.push({ kind: "lookalike", file, line, family, symbol: name }); + } + } + for (const rule of family.inline ?? []) { + const regex = new RegExp(rule.pattern, "g"); + inlineLines.forEach((text, index) => { + for (let n = [...text.matchAll(regex)].length; n > 0; n -= 1) { + findings.push({ kind: "inline", file, line: index + 1, family, symbol: rule.id, rule }); + } + }); + } + return findings; +} + +function sourceFindings(registry, sources) { + const parsed = new Map( + [...sources].map(([file, source]) => [ + file, + { + defs: definitions(source), + inlineLines: blankLua(source, { keepStrings: true }).split("\n"), + }, + ]), + ); + const shared = sharedHelperOwners(parsed, registry); + const findings = []; + for (const [file, entry] of parsed) { + for (const { name, line, topLevel, isLocal } of entry.defs) { + const owner = shared.get(name); + // Inside lua/shared only a top-level definition or a non-local one can be a second copy; + // a nested `local function` is private to its block. + const counts = file.startsWith("lua/shared/") ? topLevel || !isLocal : true; + if (owner && owner !== file && counts) { + findings.push({ + kind: "redefinition", + file, + line, + family: SHARED_FAMILY, + symbol: name, + owner, + }); + } + } + for (const family of registry.families) { + if (family.homes.includes(file)) continue; + findings.push(...patternFindings(family, file, entry, shared)); + } + } + return findings; +} + +function findingMessage(finding, allowedCount) { + const { kind, file, line, family, symbol, rule, count } = finding; + const hint = + kind === "redefinition" + ? `Use ${symbol} from ${finding.owner} (declare it in the module's sharedSourcePaths), or rename this one.` + : homeHint(family); + const where = `${file}:${line}`; + const what = { + redefinition: () => + `defines "${symbol}", which lua/shared already defines in ${finding.owner}.`, + lookalike: () => + `defines "${symbol}", which looks like a new copy of the ${family.id} helpers (${family.description}).`, + inline: () => `re-implements ${rule.description} inline (${family.description}).`, + }[kind](); + const entry = JSON.stringify({ + file, + family: family.id, + symbol, + ...(count > 1 ? { count } : {}), + reason: "", + }); + const advice = + allowedCount === undefined + ? `If the copy must stay, add to "allowlist" in ${registryFile}:` + : `The allowlist covers ${allowedCount} occurrence(s) but ${count} exist now. Remove the new copy, or raise "count" with a reason:`; + return [`${where}: ${what}`, ` ${hint} ${advice}`, ` ${entry}`].join("\n"); +} + +function allowlistKey(file, family, symbol) { + return `${file}\u0000${family}\u0000${symbol}`; +} + +/** + * Checks handwritten Lua against the shared-helper registry. + * Returns { errors: string[] }; an empty list means the check passed. + */ +async function checkSharedHelpers() { + const root = defaultRoot; + const loaded = JSON.parse(await readFile(path.join(root, registryFile), "utf8")); + validateRegistry(loaded); + + const files = (await Promise.all(scannedDirectories.map((dir) => luaFiles(root, dir)))).flat(); + const sources = new Map( + await Promise.all( + files.map(async (file) => [file, await readFile(path.join(root, file), "utf8")]), + ), + ); + + const errors = registryFindings(loaded, sources).map((finding) => finding.message); + const allowed = new Map( + (loaded.allowlist ?? []).map((entry) => [ + allowlistKey(entry.file, entry.family, entry.symbol), + entry, + ]), + ); + const used = new Set(); + // One report per file, family and symbol: the unit an allowlist entry covers. + const grouped = new Map(); + for (const finding of sourceFindings(loaded, sources)) { + const key = allowlistKey(finding.file, finding.family.id, finding.symbol); + const existing = grouped.get(key); + if (existing) existing.count += 1; + else grouped.set(key, { ...finding, count: 1 }); + } + for (const [key, finding] of grouped) { + const entry = allowed.get(key); + if (!entry) { + errors.push(findingMessage(finding)); + continue; + } + used.add(key); + const allowedCount = entry.count ?? 1; + if (finding.count > allowedCount) errors.push(findingMessage(finding, allowedCount)); + else if (finding.count < allowedCount) { + errors.push( + `${registryFile}: allowlist entry for ${entry.file} / ${entry.family} / ${entry.symbol} allows ${allowedCount} but only ${finding.count} remain. Lower or remove "count".`, + ); + } + } + for (const [key, entry] of allowed) { + if (!used.has(key)) { + errors.push( + `${registryFile}: allowlist entry for ${entry.file} / ${entry.family} / ${entry.symbol} matches nothing. The copy was removed or renamed; delete the entry.`, + ); + } + } + return { errors }; +} + +async function main() { + const { errors } = await checkSharedHelpers(); + if (errors.length > 0) { + process.stderr.write( + `Shared helper check failed (${errors.length}):\n\n${errors.join("\n\n")}\n`, + ); + process.exitCode = 1; + return; + } + process.stdout.write("Shared helper check passed.\n"); +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + try { + await main(); + } catch (error) { + process.stderr.write(`${error.message}\n`); + process.exitCode = 1; + } +} diff --git a/happyview-modules/tooling/shared-helpers.registry.json b/happyview-modules/tooling/shared-helpers.registry.json new file mode 100644 index 0000000..35ea990 --- /dev/null +++ b/happyview-modules/tooling/shared-helpers.registry.json @@ -0,0 +1,796 @@ +{ + "families": [ + { + "id": "did-validation", + "description": "DID syntax check", + "lookalikes": ["^valid_[a-z_]*did"], + "inline": [ + { + "id": "did-pattern", + "pattern": "\\^did:", + "description": "the DID syntax pattern" + } + ], + "homes": ["lua/shared/didValidation.lua"] + }, + { + "id": "nsid-validation", + "description": "NSID syntax check", + "lookalikes": ["^valid_[a-z_]*nsid"], + "homes": ["lua/shared/nsidValidation.lua"] + }, + { + "id": "record-identifier", + "description": "AT-URI record key and record URI parsing", + "lookalikes": ["valid_record_(uri|key)"], + "inline": [ + { + "id": "at-uri-pattern", + "pattern": "\\^at://", + "description": "the AT-URI parsing pattern" + } + ], + "homes": ["lua/shared/recordIdentifier.lua"] + }, + { + "id": "datetime-validation", + "description": "RFC 3339 datetime check", + "lookalikes": ["^valid_[a-z_]*(datetime|timestamp)"], + "homes": ["lua/shared/datetimeValidation.lua"] + }, + { + "id": "handle-resolver", + "description": "handle syntax check and handle resolution", + "lookalikes": ["^valid_(handle|ipv4|ipv6|port)", "resolve_handle"], + "homes": ["lua/shared/identityResolver.lua", "lua/shared/profileLookup.lua"] + }, + { + "id": "list-cursor", + "description": "list cursor encoding and decoding", + "lookalikes": ["cursor_(decode|encode)", "(decode|encode)_([a-z_]+_)?cursor"], + "inline": [ + { + "id": "cursor-hex-decode", + "pattern": "tonumber\\(pair,\\s*16\\)", + "description": "hex cursor decoding" + }, + { + "id": "cursor-length-cap", + "pattern": "#token\\s*>\\s*8192", + "description": "the cursor length cap" + } + ], + "homes": ["lua/shared/listCursor.lua", "lua/shared/listQuery.lua"] + }, + { + "id": "list-params", + "description": "limit, includeTotal and sortDirection parsing", + "lookalikes": ["^parse_[a-z_]*(limit|include_total|sort_direction)"], + "inline": [ + { + "id": "limit-message", + "pattern": "limit must be an integer", + "description": "limit parsing" + }, + { + "id": "include-total-message", + "pattern": "includeTotal must be true or false", + "description": "includeTotal parsing" + }, + { + "id": "sort-direction-message", + "pattern": "sortDirection must be", + "description": "sortDirection parsing" + } + ], + "homes": [ + "lua/shared/listValidation.lua", + "lua/shared/includeTotal.lua", + "lua/shared/listQuery.lua" + ] + }, + { + "id": "query-params", + "description": "InvalidRequest errors, unknown-parameter checks and single-value parameters", + "lookalikes": ["(^|_)(invalid|keys_only|scalar)$"], + "inline": [ + { + "id": "occur-once-message", + "pattern": "must occur once", + "description": "single-value parameter parsing" + } + ], + "homes": ["lua/shared/query.lua"] + }, + { + "id": "repeated-query-array", + "description": "repeated query parameter (array) parsing", + "unowned": "each endpoint has its own; add a shared parser in lua/shared and register it before adding another", + "lookalikes": ["(^|_)array(_values)?$"], + "homes": [] + }, + { + "id": "record-view", + "description": "the {uri, cid, indexedAt, did, record} view of an indexed row", + "lookalikes": ["record_view"], + "inline": [ + { + "id": "indexed-at-null", + "pattern": "indexed_at == nil and NULL", + "description": "the indexedAt null fallback" + } + ], + "homes": ["lua/shared/recordView.lua"] + }, + { + "id": "actor-view", + "description": "actor profile/organization hydration", + "lookalikes": ["^[a-z_]*hydrate_[a-z_]*actor_views$"], + "homes": ["lua/shared/actorView.lua"] + }, + { + "id": "batch-request-target", + "description": "batch GET request-target size limit", + "lookalikes": ["^[a-z_]*request_target[a-z_]*$"], + "homes": ["lua/shared/batchRequestTarget.lua"] + } + ], + "allowlist": [ + { + "file": "lua/shared/acknowledgement.lua", + "family": "record-view", + "symbol": "acknowledgement_record_view", + "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." + }, + { + "file": "lua/shared/acknowledgementList.lua", + "family": "datetime-validation", + "symbol": "valid_cursor_timestamp", + "reason": "Existing cursor timestamp check with its own rules; kept to avoid a behavior change." + }, + { + "file": "lua/shared/acknowledgementList.lua", + "family": "list-cursor", + "symbol": "decode_acknowledgement_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/acknowledgementList.lua", + "family": "repeated-query-array", + "symbol": "acknowledgement_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/shared/activityList.lua", + "family": "list-cursor", + "symbol": "decode_activity_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/activityList.lua", + "family": "query-params", + "symbol": "activity_scalar", + "reason": "Existing endpoint-local copy of the shared query helpers; kept to avoid a behavior change. Use query.lua helpers instead." + }, + { + "file": "lua/shared/activityList.lua", + "family": "record-identifier", + "symbol": "at-uri-pattern", + "reason": "Existing record-URI check that predates the registry; kept to avoid a behavior change. Build on valid_record_uri where the shape allows.", + "count": 2 + }, + { + "file": "lua/shared/activityList.lua", + "family": "repeated-query-array", + "symbol": "activity_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/shared/activityProjection.lua", + "family": "record-view", + "symbol": "activity_projection_record_view", + "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." + }, + { + "file": "lua/shared/actorFollowList.lua", + "family": "list-cursor", + "symbol": "cursor_decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/actorFollowList.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/attachmentList.lua", + "family": "list-cursor", + "symbol": "attachment_cursor_decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/attachmentList.lua", + "family": "repeated-query-array", + "symbol": "attachment_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/shared/collection.lua", + "family": "record-identifier", + "symbol": "collection_valid_record_uri", + "reason": "Existing record-URI check that predates the registry; kept to avoid a behavior change. Build on valid_record_uri where the shape allows." + }, + { + "file": "lua/shared/collectionItems.lua", + "family": "list-cursor", + "symbol": "collection_items_cursor_decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/collectionItems.lua", + "family": "list-cursor", + "symbol": "collection_items_cursor_encode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/collectionItems.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/collectionItems.lua", + "family": "list-cursor", + "symbol": "cursor-length-cap", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/collectionItems.lua", + "family": "query-params", + "symbol": "collection_items_invalid", + "reason": "Existing endpoint-local copy of the shared query helpers; kept to avoid a behavior change. Use query.lua helpers instead." + }, + { + "file": "lua/shared/collectionItems.lua", + "family": "query-params", + "symbol": "collection_items_keys_only", + "reason": "Existing endpoint-local copy of the shared query helpers; kept to avoid a behavior change. Use query.lua helpers instead." + }, + { + "file": "lua/shared/collectionList.lua", + "family": "list-cursor", + "symbol": "collection_list_cursor_decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/collectionList.lua", + "family": "query-params", + "symbol": "collection_scalar", + "reason": "Existing endpoint-local copy of the shared query helpers; kept to avoid a behavior change. Use query.lua helpers instead." + }, + { + "file": "lua/shared/collectionList.lua", + "family": "repeated-query-array", + "symbol": "collection_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/shared/collectionProjection.lua", + "family": "record-identifier", + "symbol": "collection_projection_valid_record_uri", + "reason": "Existing record-URI check that predates the registry; kept to avoid a behavior change. Build on valid_record_uri where the shape allows." + }, + { + "file": "lua/shared/collectionProjection.lua", + "family": "record-view", + "symbol": "collection_projection_record_view", + "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." + }, + { + "file": "lua/shared/entityFollow.lua", + "family": "record-view", + "symbol": "entity_follow_indexed_record_view", + "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." + }, + { + "file": "lua/shared/entityFollow.lua", + "family": "record-view", + "symbol": "entity_follow_record_view", + "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." + }, + { + "file": "lua/shared/entityFollowPagination.lua", + "family": "list-cursor", + "symbol": "entity_follow_decode_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/evaluation.lua", + "family": "repeated-query-array", + "symbol": "evaluation_evaluator_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/shared/evaluationList.lua", + "family": "list-cursor", + "symbol": "decode_evaluation_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/evaluationList.lua", + "family": "repeated-query-array", + "symbol": "evaluation_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/shared/evmLinkIdentifier.lua", + "family": "record-identifier", + "symbol": "at-uri-pattern", + "reason": "Existing record-URI check that predates the registry; kept to avoid a behavior change. Build on valid_record_uri where the shape allows." + }, + { + "file": "lua/shared/evmLinkIdentifier.lua", + "family": "record-view", + "symbol": "evm_link_record_view", + "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." + }, + { + "file": "lua/shared/featureProjection.lua", + "family": "record-view", + "symbol": "feature_projection_record_view", + "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." + }, + { + "file": "lua/shared/feedActorReactions.lua", + "family": "record-view", + "symbol": "feed_actor_reaction_record_view", + "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." + }, + { + "file": "lua/shared/feedReaction.lua", + "family": "list-cursor", + "symbol": "feed_reaction_decode_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/fundingReceipt.lua", + "family": "record-view", + "symbol": "indexed-at-null", + "reason": "funding_receipt_view repeats the record_view null indexedAt fallback because it also adds author; kept to avoid a behavior change." + }, + { + "file": "lua/shared/fundingReceiptList.lua", + "family": "list-cursor", + "symbol": "decode_funding_receipt_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/fundingReceiptList.lua", + "family": "repeated-query-array", + "symbol": "funding_receipt_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/shared/measurementQuery.lua", + "family": "record-identifier", + "symbol": "measurement_valid_record_uri", + "reason": "Existing record-URI check that predates the registry; kept to avoid a behavior change. Build on valid_record_uri where the shape allows." + }, + { + "file": "lua/shared/organizationList.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/organizationList.lua", + "family": "record-identifier", + "symbol": "at-uri-pattern", + "reason": "Existing record-URI check that predates the registry; kept to avoid a behavior change. Build on valid_record_uri where the shape allows." + }, + { + "file": "lua/shared/organizationList.lua", + "family": "repeated-query-array", + "symbol": "array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/shared/profileList.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/profileList.lua", + "family": "record-identifier", + "symbol": "at-uri-pattern", + "reason": "Existing record-URI check that predates the registry; kept to avoid a behavior change. Build on valid_record_uri where the shape allows." + }, + { + "file": "lua/shared/recentFollows.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/recentFollows.lua", + "family": "list-cursor", + "symbol": "recent_cursor_decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/recentFollows.lua", + "family": "list-cursor", + "symbol": "recent_cursor_encode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/recentFollows.lua", + "family": "record-identifier", + "symbol": "recent_valid_record_uri", + "reason": "Existing record-URI check that predates the registry; kept to avoid a behavior change. Build on valid_record_uri where the shape allows." + }, + { + "file": "lua/shared/recentFollows.lua", + "family": "record-view", + "symbol": "recent_record_view", + "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." + }, + { + "file": "lua/shared/rightsIdentifier.lua", + "family": "record-identifier", + "symbol": "rights_valid_record_uri", + "reason": "Existing record-URI check that predates the registry; kept to avoid a behavior change. Build on valid_record_uri where the shape allows." + }, + { + "file": "lua/shared/rightsView.lua", + "family": "actor-view", + "symbol": "rights_hydrate_actor_views", + "reason": "Existing actor hydration variant; kept to avoid a behavior change. Build on hydrate_actor_views where the shape allows." + }, + { + "file": "lua/shared/rightsView.lua", + "family": "record-view", + "symbol": "rights_record_view", + "reason": "Existing record view with endpoint-specific fields; kept to avoid a behavior change. Build on record_view where the shape allows." + }, + { + "file": "lua/shared/vocabTagValidation.lua", + "family": "actor-view", + "symbol": "hydrate_vocab_actor_views", + "reason": "Existing actor hydration variant; kept to avoid a behavior change. Build on hydrate_actor_views where the shape allows." + }, + { + "file": "lua/shared/workscopeTag.lua", + "family": "record-identifier", + "symbol": "workscope_tag_valid_record_uri", + "reason": "Existing record-URI check that predates the registry; kept to avoid a behavior change. Build on valid_record_uri where the shape allows." + }, + { + "file": "lua/shared/workscopeTagList.lua", + "family": "list-cursor", + "symbol": "workscope_tag_decode_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/shared/workscopeTagList.lua", + "family": "repeated-query-array", + "symbol": "workscope_tag_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/src/listBadgeAwards.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listBadgeAwards.lua", + "family": "list-cursor", + "symbol": "decode_badge_award_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listBadgeAwards.lua", + "family": "list-params", + "symbol": "include-total-message", + "reason": "Existing endpoint-local list parameter parsing; kept to avoid a behavior change. Use includeTotal.lua instead." + }, + { + "file": "lua/src/listBadgeAwards.lua", + "family": "repeated-query-array", + "symbol": "array_values", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/src/listBadgeDefinitions.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listBadgeDefinitions.lua", + "family": "list-cursor", + "symbol": "decode_badge_definition_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listBadgeDefinitions.lua", + "family": "repeated-query-array", + "symbol": "badge_definition_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/src/listBadgeResponses.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listBadgeResponses.lua", + "family": "list-cursor", + "symbol": "decode_badge_response_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listContributions.lua", + "family": "list-cursor", + "symbol": "decode_contribution_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listContributorInformation.lua", + "family": "list-cursor", + "symbol": "contributor_information_cursor_decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listContributorInformation.lua", + "family": "repeated-query-array", + "symbol": "contributor_information_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/src/listEvmLinks.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listEvmLinks.lua", + "family": "list-cursor", + "symbol": "decode_evm_link_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listEvmLinks.lua", + "family": "repeated-query-array", + "symbol": "array_values", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/src/listFeatures.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listFeatures.lua", + "family": "list-cursor", + "symbol": "feature_cursor_decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listFeatures.lua", + "family": "query-params", + "symbol": "occur-once-message", + "reason": "Existing endpoint-local copy of the shared query helpers; kept to avoid a behavior change. Use query.lua helpers instead." + }, + { + "file": "lua/src/listFeatures.lua", + "family": "repeated-query-array", + "symbol": "feature_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/src/listLocations.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listMeasurements.lua", + "family": "list-cursor", + "symbol": "decode_measurement_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listMeasurements.lua", + "family": "repeated-query-array", + "symbol": "measurement_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/src/listRights.lua", + "family": "list-cursor", + "symbol": "rights_list_cursor_decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/listRights.lua", + "family": "repeated-query-array", + "symbol": "rights_list_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/src/listVocabTags.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/searchBadgeDefinitions.lua", + "family": "list-cursor", + "symbol": "cursor-hex-decode", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/searchBadgeDefinitions.lua", + "family": "list-cursor", + "symbol": "decode_badge_definition_cursor", + "reason": "Existing endpoint-local cursor code that predates the registry; kept to avoid a behavior change. Move onto decode_cursor where the cursor shape allows." + }, + { + "file": "lua/src/searchBadgeDefinitions.lua", + "family": "repeated-query-array", + "symbol": "badge_definition_array", + "reason": "Existing endpoint-local repeated-parameter parser; no shared parser exists yet. Kept to avoid a behavior change." + }, + { + "file": "lua/shared/actorFollow.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/shared/location.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/shared/organization.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/shared/organizationList.lua", + "family": "shared-helper", + "symbol": "cursor_decode", + "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + }, + { + "file": "lua/shared/profile.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/shared/profileList.lua", + "family": "shared-helper", + "symbol": "array", + "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + }, + { + "file": "lua/shared/profileList.lua", + "family": "shared-helper", + "symbol": "cursor_decode", + "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + }, + { + "file": "lua/shared/workscopeRecordView.lua", + "family": "shared-helper", + "symbol": "record_view", + "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + }, + { + "file": "lua/src/getBadgeAward.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/src/getBadgeDefinition.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/src/getBadgeResponse.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/src/getVocabTag.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/src/listBadgeAwards.lua", + "family": "shared-helper", + "symbol": "valid_badge_definition_uri", + "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + }, + { + "file": "lua/src/listBadgeAwards.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/src/listBadgeAwards.lua", + "family": "shared-helper", + "symbol": "parse_include_total", + "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + }, + { + "file": "lua/src/listBadgeDefinitions.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/src/listBadgeResponses.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/src/listLocations.lua", + "family": "shared-helper", + "symbol": "array", + "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + }, + { + "file": "lua/src/listLocations.lua", + "family": "shared-helper", + "symbol": "add_in", + "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + }, + { + "file": "lua/src/listLocations.lua", + "family": "shared-helper", + "symbol": "cursor_decode", + "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + }, + { + "file": "lua/src/listMeasurements.lua", + "family": "shared-helper", + "symbol": "bind_values", + "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + }, + { + "file": "lua/src/listVocabTags.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + }, + { + "file": "lua/src/listVocabTags.lua", + "family": "shared-helper", + "symbol": "decode_cursor", + "reason": "Existing duplicate of a lua/shared helper; baseline until the consolidation PRs land." + }, + { + "file": "lua/src/searchBadgeDefinitions.lua", + "family": "shared-helper", + "symbol": "query", + "reason": "Per-module query entry point that shares a name; not a reusable helper." + } + ], + "allowlistNote": "The allowlist is a baseline of copies that existed when the lint was added. It is not approval to add more: new entries need a specific reason, and count must match the occurrences exactly." +} diff --git a/package.json b/package.json index 2897a66..cd96f8c 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "packageManager": "pnpm@12.15.0", "scripts": { "prepare": "lefthook install", - "lint": "biome lint --error-on-warnings .", + "lint": "biome lint --error-on-warnings . && pnpm --filter @hypercerts-org/happyview-modules run lint:shared-helpers", "format": "biome format --write .", "format:check": "biome format .", "check": "pnpm lint && pnpm format:check && pnpm --filter @hypercerts-org/happyview-modules check && pnpm --filter hypercerts-api-endpoints test && pnpm --filter @hypercerts-org/api check",