Skip to content

Commit 0905564

Browse files
perf: keep D3 out of shared route imports
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 543f740 commit 0905564

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

‎src/routes/stats/npm/-utils.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import * as v from 'valibot'
22
import { MAX_NPM_STATS_GROUPS } from '~/utils/npm-stats-limits'
33

4-
// Re-export shared types from chart utils
5-
export {
6-
binTypeSchema,
7-
type BinType,
8-
binningOptions,
9-
getBinFunction,
10-
} from '~/utils/chart'
4+
// Re-export shared types and schema without importing chart utilities.
5+
export { binTypeSchema, type BinType } from '~/components/npm-stats/shared'
116
export {
127
chartTypeSchema,
138
type ChartType,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference types="node" />
2+
3+
import assert from 'node:assert/strict'
4+
import test from 'node:test'
5+
import { Route } from '../src/routes/stats/npm/$packages'
6+
7+
const schema = Route.options.validateSearch
8+
assert.ok(schema && typeof schema === 'object' && '~standard' in schema)
9+
const standardSchema = schema['~standard']
10+
11+
test('npm comparison route preserves binType search validation', async () => {
12+
const defaultResult = await standardSchema.validate({})
13+
assert.equal(defaultResult.issues, undefined)
14+
assert.equal(defaultResult.value.binType, 'weekly')
15+
16+
for (const binType of ['yearly', 'monthly', 'weekly', 'daily']) {
17+
const result = await standardSchema.validate({ binType })
18+
assert.equal(result.issues, undefined)
19+
assert.equal(result.value.binType, binType)
20+
}
21+
})
22+
23+
test('npm comparison route defaults invalid binType search values', async () => {
24+
const result = await standardSchema.validate({ binType: 'hourly' })
25+
assert.equal(result.issues, undefined)
26+
assert.equal(result.value.binType, 'weekly')
27+
})

0 commit comments

Comments
 (0)