Skip to content

Commit

Permalink
Fix ESLint, add to GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
keichan34 committed Jan 9, 2025
1 parent 58c9164 commit c338c26
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"run:99_create_stats": "tsx ./src/99_create_stats.ts",
"create:archive": "rm ./api.7z; 7zz a ./api.7z ./out/api",
"start": "http-server --cors=\"*\" ./out",
"lint": "eslint ./src",
"test": "glob -c \"node --test --import tsx\" \"./src/**/*.test.ts\""
},
"keywords": [],
Expand Down
13 changes: 10 additions & 3 deletions src/lib/ckan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ const CKAN_BASE_REGISTRY_URL = `https://catalog.registries.digital.go.jp/rc`
const USER_AGENT = 'curl/8.7.1';
const CACHE_DIR = path.join(import.meta.dirname, '..', '..', 'cache');

export type CKANResponse<T = any> = {
export type CKANResponse<T = CKANResponseInner> = {
success: false
} | {
success: true
result: T
}

type CKANResponseInner = (
CKANPackageSearchResultList |
CKANPackageSearchResult
);

export type CKANPackageSearchResultList = {
count: number,
sort: string,
Expand Down Expand Up @@ -53,7 +58,8 @@ export async function ckanPackageSearch(query: string): Promise<CKANPackageSearc

let json: CKANResponse<CKANPackageSearchResultList>;
if (fs.existsSync(cacheFile)) {
json = await fs.promises.readFile(cacheFile, 'utf-8').then((data) => JSON.parse(data));
json = await fs.promises.readFile(cacheFile, 'utf-8')
.then((data) => JSON.parse(data) as CKANResponse<CKANPackageSearchResultList>);
} else {
const url = new URL(`${CKAN_BASE_REGISTRY_URL}/api/3/action/package_search`);
url.searchParams.set('q', query);
Expand Down Expand Up @@ -81,7 +87,8 @@ export async function getCkanPackageById(id: string): Promise<CKANPackageSearchR

let json: CKANResponse<CKANPackageSearchResult>;
if (fs.existsSync(cacheFile)) {
json = await fs.promises.readFile(cacheFile, 'utf-8').then((data) => JSON.parse(data));
json = await fs.promises.readFile(cacheFile, 'utf-8')
.then((data) => JSON.parse(data) as CKANResponse<CKANPackageSearchResult>);
} else {
const url = new URL(`${CKAN_BASE_REGISTRY_URL}/api/3/action/package_show`);
url.searchParams.set('id', id);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/zip_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import unzipper, { Entry } from 'unzipper';
*/
export async function *unzipAndExtractZipFile(zipFile: Readable): AsyncGenerator<Entry> {
const files = zipFile.pipe(unzipper.Parse({forceStream: true}));
for await (const entry of files) {
for await (const entry_ of files) {
const entry = entry_ as Entry;
if (entry.type === 'File' && entry.path.endsWith('.zip')) {
yield *unzipAndExtractZipFile(entry);
} else if (entry.type === 'File' && entry.path.endsWith('.csv')) {
Expand Down
3 changes: 2 additions & 1 deletion src/processes/10_refresh_csv_ranges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export async function getRangesFromCSV(path: string): Promise<undefined | Header
const headerData = await readUntilHeaderEnd(path);
const headerStream = csvParse(headerData);
const rows: HeaderRow[] = [];
for await (const line of headerStream) {
for await (const line_ of headerStream) {
const line = line_ as [string, string, string];
if (line[0] === '=END=') {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/processes/99_create_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function getCountForCSVRange(path: string, range?: { start: number, length
});
let count = 0;
let countWithPos = 0;
await pipeline(stream, parser, async (source) => {
await pipeline(stream, parser, async (source: AsyncIterable<{lat?: string, lng?: string}>) => {
for await (const record of source) {
count++;
if (record['lng'] && record['lat']) {
Expand Down

0 comments on commit c338c26

Please sign in to comment.