Skip to content

Commit a8755ca

Browse files
authored
v2.1.2
いくつか修正できていない問題があるが、メモリリークに関しては改善が見られるのでリリースする。残る問題は今後に引き継ぐ。
2 parents b0a42e0 + caefb6b commit a8755ca

File tree

23 files changed

+277
-579
lines changed

23 files changed

+277
-579
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
name: "tests"
55

66
on:
7-
pull_request:
8-
branches:
9-
- main
10-
- develop
11-
paths:
12-
- 'src/**/*.ts'
13-
- 'e2e/**/*.ts'
14-
- '*.json'
15-
- '*.js'
16-
- '*.mjs'
7+
# pull_request:
8+
# branches:
9+
# - main
10+
# paths:
11+
# - 'src/**/*.ts'
12+
# - 'e2e/**/*.ts'
13+
# - '*.json'
14+
# - '*.js'
15+
# - '*.mjs'
1716
push:
1817
branches:
1918
- main

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ log.txt
1919
./.vscode/*.json
2020
.dockerignore
2121
Dockerfile
22+
./.vscode/rsdt_address.txt

.vscode/schools-output.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57909,7 +57909,7 @@ input,output,others,score,match_level,coordinate_level,lat,lon,lg_code,machiaza_
5790957909
"神奈川県横浜市金沢区瀬戸22-2","神奈川県横浜市金沢区瀬戸22-2","-2",0.94,residential_block,residential_block,35.333985,139.617778,"141089","0004000",1,022,,,,神奈川県,,横浜市,金沢区,瀬戸,,,22,,,,,
5791057910
"神奈川県横須賀市平成町1丁目10番1","神奈川県横須賀市平成町一丁目10-1","-1",0.89,residential_block,residential_block,35.273666,139.680704,"142018","0069001",1,010,,,,神奈川県,,横須賀市,,平成町,一丁目,,10,,,,,
5791157911
"神奈川県川崎市幸区小倉4-30-1","神奈川県川崎市幸区小倉四丁目30-1","-1",0.78,residential_block,residential_block,35.53618,139.669894,"141321","0002004",1,030,,,,神奈川県,,川崎市,幸区,小倉,四丁目,,30,,,,,
57912-
"神奈川県横浜市中区日本大通11番地横浜情報文化センター5F","神奈川県横浜市中区日本大通11 横浜情報文化センタ 5F","横浜情報文化センタ 5F",0.9,parcel,machiaza,35.446371,139.642363,"141046","0096000",0,,,,000110000000000,神奈川県,,横浜市,中区,日本大通,,,,,,11,,
57912+
"神奈川県横浜市中区日本大通11番地横浜情報文化センター5F","神奈川県横浜市中区日本大通11 横浜情報文化センター 5F","横浜情報文化センター 5F",0.9,parcel,machiaza,35.446371,139.642363,"141046","0096000",0,,,,000110000000000,神奈川県,,横浜市,中区,日本大通,,,,,,11,,
5791357913
"神奈川県横浜市神奈川区六角橋3-27-1","神奈川県横浜市神奈川区六角橋三丁目27-1","-1",0.81,residential_block,residential_block,35.484413,139.620771,"141020","0006003",1,027,,,,神奈川県,,横浜市,神奈川区,六角橋,三丁目,,27,,,,,
5791457914
"神奈川県横浜市金沢区六浦東1-50-1","神奈川県横浜市金沢区六浦東一丁目50-1","-1",0.8,residential_block,residential_block,35.324278,139.625927,"141089","0002001",1,050,,,,神奈川県,,横浜市,金沢区,六浦東,一丁目,,50,,,,,
5791557915
"神奈川県横浜市鶴見区鶴見2-1-3","神奈川県横浜市鶴見区鶴見二丁目1-3","-3",0.78,residential_block,residential_block,35.505382,139.674436,"141011","0010002",1,001,,,,神奈川県,,横浜市,鶴見区,鶴見,二丁目,,1,,,,,

e2e/__tests__/common.ts

Lines changed: 94 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect, jest } from '@jest/globals';
22
import fs from 'node:fs';
33
import os from 'node:os';
44
import path from 'node:path';
5-
import { Readable, Writable } from 'node:stream';
5+
import { Readable, Transform, Writable } from 'node:stream';
66
import { pipeline } from 'node:stream/promises';
77
import {
88
AbrGeocoder,
@@ -49,18 +49,100 @@ export type ExecOptions = {
4949

5050
export const runGeocoder = async (options: ExecOptions) => {
5151

52-
if (process.env.USE_CLI) {
53-
// コマンドラインからテストを実行する場合は、CLIから行う
54-
return execaNode(options)(cliPath, [
55-
"-",
56-
"-silient",
57-
`--target ${options.geocode.searchTarget}`,
58-
`-f ${options.geocode.outputFormat}`,
59-
`-d ${dbPath}`,
60-
]);
52+
// 読み込みストリーム
53+
const reader = (() => {
54+
if (options.input) {
55+
return Readable.from([options.input]);
56+
} else if (options.inputFile) {
57+
return fs.createReadStream(options.inputFile);
58+
} else {
59+
throw 'unknown input';
60+
}
61+
})();
62+
63+
// 1行ずつに分解するストリーム
64+
const lineByLine = new LineStream();
65+
66+
// コメントを取り除くストリーム
67+
const commentFilter = new CommentFilterTransform();
68+
69+
if (process.env.USE_HTTP) {
70+
// ===========================================
71+
// E2Eテスト時は、HTTPリクエストで処理を行う
72+
// ===========================================
73+
const format = ((): OutputFormat => {
74+
switch (options.geocode.outputFormat) {
75+
case OutputFormat.JSON: {
76+
return OutputFormat.NDJSON;
77+
}
78+
case OutputFormat.GEOJSON: {
79+
return OutputFormat.NDGEOJSON;
80+
}
81+
default: {
82+
return options.geocode.outputFormat;
83+
}
84+
}
85+
})();
86+
87+
const chunks: string[] = [];
88+
const requester = new Writable({
89+
objectMode: true,
90+
async write(
91+
address: string,
92+
_: BufferEncoding,
93+
callback: (error?: Error | null | undefined) => void,
94+
) {
95+
96+
const query_params = new URLSearchParams({
97+
// 検索対象の住所文字列
98+
address,
99+
100+
// 検索対象
101+
target: options.geocode.searchTarget,
102+
103+
// 出力書式
104+
format,
105+
});
106+
const response = await fetch(`http://localhost:3000/geocode?${query_params}`, {
107+
keepalive: true,
108+
});
109+
110+
if (!response.ok) {
111+
callback(new Error(`${response.status}: ${response.statusText}`));
112+
return;
113+
}
114+
if (format === OutputFormat.CSV || format === OutputFormat.SIMPLIFIED) {
115+
chunks.push(await response.text());
116+
return;
117+
}
118+
chunks.push(JSON.stringify(await response.json()));
119+
callback();
120+
},
121+
})
122+
123+
await pipeline(
124+
reader,
125+
lineByLine,
126+
commentFilter,
127+
requester,
128+
)
129+
130+
if (format === OutputFormat.JSON || format === OutputFormat.GEOJSON) {
131+
return {
132+
stdout: `[${chunks.join(",")}]`,
133+
}
134+
}
135+
return {
136+
stdout: chunks.join("\n")
137+
};
61138
}
62-
// VSCode でデバッグする場合は、geocode-command.ts と同様の処理をすることで
139+
140+
// ===================================================
141+
// VSCodeでデバッグする場合は、同じプロセス上で処理を行う。
142+
//
143+
// geocode-command.ts と同様の処理をすることで
63144
// ビルドしないでもデバッグできる
145+
// ===================================================
64146
const abrgDir = options.useGlobalDB ? resolveHome(EnvProvider.DEFAULT_ABRG_DIR) : dbPath;
65147

66148
const container = new AbrGeocoderDiContainer({
@@ -84,21 +166,12 @@ export const runGeocoder = async (options: ExecOptions) => {
84166
searchTarget: options.geocode.searchTarget,
85167
});
86168

87-
const reader = (() => {
88-
if (options.input) {
89-
return Readable.from([options.input]);
90-
} else if (options.inputFile) {
91-
return fs.createReadStream(options.inputFile);
92-
} else {
93-
throw 'unknown input';
94-
}
95-
})();
96-
97169
const formatter = FormatterProvider.get({
98170
type: options.geocode.outputFormat,
99171
debug: false,
100172
});
101173

174+
// 書き込みストリーム
102175
const chunks: Buffer[] = [];
103176
const dst = new Writable({
104177
write(chunk, _, callback) {
@@ -107,9 +180,6 @@ export const runGeocoder = async (options: ExecOptions) => {
107180
},
108181
});
109182

110-
const lineByLine = new LineStream();
111-
const commentFilter = new CommentFilterTransform();
112-
113183
await pipeline(
114184
reader,
115185
lineByLine,

0 commit comments

Comments
 (0)