Extract ASSET_TYPE_MAP into its own module; add Vitest + parser test suite#10
Open
ArneshBanerjee wants to merge 2 commits into
Open
Extract ASSET_TYPE_MAP into its own module; add Vitest + parser test suite#10ArneshBanerjee wants to merge 2 commits into
ArneshBanerjee wants to merge 2 commits into
Conversation
…/asset-types `lib/types.ts` was 1079 lines, the vast majority of which was the ASSET_TYPE_MAP data table and the OPERATOR_ALIASES dictionary. Move both constants (and introduce a shared `AssetTypeConfig` type alias) into a new `lib/asset-types.ts`, leaving `lib/types.ts` to hold only TS interfaces. Re-export the constants from `lib/types.ts` so existing imports continue to work; internal consumers (`lib/parser.ts`, `lib/overpass.ts`) are updated to import from the new module directly. No behavior change. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Wire up Vitest as the test runner (`npm test`, `npm run test:watch`) and add 23 unit tests covering `lib/parser.ts`: structured-query parsing (type/operator/region/country/near/radius, underscore decoding, radius clamping), natural-language extraction (type, near, in, radius via "within"), operator-alias normalization, empty/ whitespace input, and `validateQuery` error paths. These lock in current parser behavior so a future refactor (e.g. the substring-collision bug where "virginia" matches the `vi` alias of vodafone, or the broad `\btowers?\b` pattern shadowing more specific ones) can be done with confidence. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
|
Someone is attempting to deploy a commit to the ni5arga's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two structural improvements, no behavior change to the running app:
ASSET_TYPE_MAPandOPERATOR_ALIASES(~1000 lines of data) out oflib/types.tsinto a newlib/asset-types.ts, with a sharedAssetTypeConfiginterface.lib/types.tsshrinks from 1079 → 54 lines and is now a pure types module. The constants are re-exported fromlib/types.tsso existing imports still work; internal callers (parser.ts,overpass.ts) are updated to import from the new module directly.npm test,npm run test:watch) and a 23-test suite forlib/parser.tscovering both structured (type:/operator:/region:/country:/near:/radius:) and natural-language queries, plusvalidateQueryerror paths. Pins down current parser behavior so future refactors can be done safely.Why
lib/types.tshad grown into a giant data file; navigating types or adding a new asset type required scrolling past a thousand-line table. Splitting makes both files reviewable and lets the type-shape change independently of the data.Notes for review
npm test) should be appended to the workflow. Happy to follow up with a tiny PR or rebase, whichever you prefer.aws data centers in virginiaas thevodafoneoperator because "virginia" contains "vi" (a vodafone alias); (b) the broad\btowers?\bregex can shadow more specific patterns depending on order. Both are out of scope here.lib/search-index.ts: it is not dead — it powers the autocomplete suggestions inSearchBar.tsx. It does maintain its own parallel asset-type list, which is a duplication worth consolidating later but is out of scope for this PR.Test plan
npm run lint— cleannpx tsc --noEmit— cleannpm test— 23/23 passingnpm run build— cleanlib/types.tsstill exportsASSET_TYPE_MAP,OPERATOR_ALIASES, andAssetTypeConfigfor backward compatibility.🤖 Generated with Claude Code