Skip to content

Commit ac2dca2

Browse files
committed
feat: add back logs
1 parent a9677bc commit ac2dca2

20 files changed

+123
-32
lines changed

packages/country-extra/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default defineConfig({
5252
dataDir: resolve('../../data/country'),
5353
tmpDataDir: resolve('../../tmp/country'),
5454
fields: ['country'],
55+
silent: true,
5556
}
5657
await update(settings)
5758
await createBrowserIndex('country', settings, resolve('./indexes'))

packages/country/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default defineConfig({
5252
dataDir: resolve('../../data/country'),
5353
tmpDataDir: resolve('../../tmp/country'),
5454
fields: ['country'],
55+
silent: true,
5556
}
5657
await update(settings)
5758
await createBrowserIndex('country', settings, resolve('./indexes'))

packages/geocode-extra/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default defineConfig({
5252
dataDir: resolve('../../data/geocode'),
5353
tmpDataDir: resolve('../../tmp/geocode'),
5454
fields: ['latitude', 'longitude'],
55+
silent: true,
5556
}
5657
await update(settings)
5758
await createBrowserIndex('geocode', settings, resolve('./indexes'))

packages/geocode/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default defineConfig({
5252
dataDir: resolve('../../data/geocode'),
5353
tmpDataDir: resolve('../../tmp/geocode'),
5454
fields: ['latitude', 'longitude'],
55+
silent: true,
5556
}
5657
await update(settings)
5758
await createBrowserIndex('geocode', settings, resolve('./indexes'))

packages/ip-location-api/src/functions/lookup.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Buffer } from 'node:buffer'
22
import { open } from 'node:fs/promises'
33
import { join } from 'node:path'
4-
import { binarySearch, getSmallMemoryFile, type IpLocationApiSettings, type LocalDatabase, number37ToString, parseIp, SAVED_SETTINGS } from '@iplookup/util'
4+
import { binarySearch, getSmallMemoryFile, type IpLocationApiSettings, type LocalDatabase, log, number37ToString, parseIp, SAVED_SETTINGS } from '@iplookup/util'
55
import { LOADED_DATA } from './reload.js'
66

77
/**
@@ -193,7 +193,7 @@ async function lineToFile(line: number, db: LocalDatabase, settings: IpLocationA
193193
const buffer = Buffer.alloc(db.recordSize)
194194
await fd.read(buffer, 0, db.recordSize, offset)
195195
fd.close().catch(() => {
196-
// TODO console.warn
196+
log('warn', 'Failed to close file descriptor')
197197
})
198198
return buffer
199199
}
@@ -375,8 +375,7 @@ async function setCountryInfo(geodata: GeoData, settings: IpLocationApiSettings)
375375
/* c8 ignore next 5 */ //* We don't check the try-catch as it's an optional peer dependency
376376
}
377377
catch (error) {
378-
// TODO add correct debug message
379-
console.error('Error importing countries-list', error)
378+
log('warn', 'Error importing countries-list', error)
380379
}
381380
}
382381
return geodata

packages/ip-location-api/src/index.all.smallMemory.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ describe('lookup (all, smallMemory)', () => {
1414
fields: 'all',
1515
smallMemory: true,
1616
addCountryInfo: true,
17+
// silent: true,
1718
})
18-
}, 15 * 60_000)
19+
}, 25 * 60_000)
1920

2021
afterAll(async () => {
2122
clear()

packages/ip-location-api/src/index.city.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ describe('lookup (city)', () => {
1212
dataDir: resolve(__dirname, '../data', id),
1313
tmpDataDir: resolve(__dirname, '../tmp', id),
1414
fields: ['city', 'country'],
15+
silent: true,
1516
})
16-
}, 15 * 60_000)
17+
}, 25 * 60_000)
1718

1819
afterAll(async () => {
1920
clear()

packages/ip-location-api/src/index.country.smallMemory.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('lookup (country, smallMemory)', () => {
1313
tmpDataDir: resolve(__dirname, '../tmp', id),
1414
fields: ['country'],
1515
smallMemory: true,
16+
silent: true,
1617
})
1718
}, 5 * 60_000)
1819

packages/ip-location-api/src/index.country.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('lookup (country)', () => {
1212
dataDir: resolve(__dirname, '../data', id),
1313
tmpDataDir: resolve(__dirname, '../tmp', id),
1414
fields: ['country'],
15+
silent: true,
1516
})
1617
}, 5 * 60_000)
1718

packages/util/src/browser.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { binarySearch } from './functions/binarySearch.js'
22
import { fetchArrayBuffer } from './functions/fetchArrayBuffer.js'
3+
import { log } from './functions/log.js'
34
import { numberToCountryCode } from './functions/numberToCountryCode.js'
45
import { numberToDir } from './functions/numberToDir.js'
56
import { parseIp } from './functions/parseIp.js'
@@ -32,13 +33,15 @@ export function setup<T extends 'country' | 'geocode'>(): (ipInput: string) => P
3233
//* Get the index for the IP version
3334
const index = INDEXES[version] ?? (await loadIndex(version))
3435
if (!index) {
35-
// TODO add debug log
36+
log('warn', 'No index found')
3637
return null
3738
}
3839

3940
//* If the IP is less than the first index, return null
40-
if (!(ip >= index[0]!))
41+
if (!(ip >= index[0]!)) {
42+
log('warn', `IP ${ipInput} is out of range`)
4143
return null
44+
}
4245

4346
//* Binary search to find the correct line in the index
4447
const lineIndex = binarySearch(index, ip)
@@ -51,7 +54,7 @@ export function setup<T extends 'country' | 'geocode'>(): (ipInput: string) => P
5154
new URL(`${DATA_URL[version]}/indexes/${version}/${numberToDir(lineIndex)}`),
5255
)
5356
if (!dataResponse) {
54-
// TODO Add debug log
57+
log('warn', 'Index file not found, is it corrupted?')
5558
return null
5659
}
5760

@@ -115,8 +118,10 @@ export function setup<T extends 'country' | 'geocode'>(): (ipInput: string) => P
115118
const result = await fetchArrayBuffer(
116119
new URL(`${baseUrl}/indexes/${version}.idx`),
117120
)
118-
if (!result)
119-
return // TODO add debug log
121+
if (!result) {
122+
log('warn', 'Index file not found, is it corrupted?')
123+
return null
124+
}
120125

121126
const { versionHeader, buffer } = result
122127
if (versionHeader)

0 commit comments

Comments
 (0)