openapi-usage 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +136 -11
- package/README.md +141 -11
- package/dist/analyzer.d.ts +11 -3
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +10 -6
- package/dist/analyzer.js.map +1 -1
- package/dist/cli.d.ts +4 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +4 -1
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +45 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +92 -20
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/locations.d.ts +40 -0
- package/dist/locations.d.ts.map +1 -0
- package/dist/locations.js +100 -0
- package/dist/locations.js.map +1 -0
- package/dist/output.d.ts +31 -2
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +82 -10
- package/dist/output.js.map +1 -1
- package/dist/runner.d.ts +18 -0
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +103 -47
- package/dist/runner.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +9 -8
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,MAAM,WAAW,MAAM;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACx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AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACxB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,WAAW,EAAE,GAC1B,OAAO,CAIT"}
|
package/dist/config.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { parse } from "yaml";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
export const severityLevelSchema = z.enum(["error", "warn"], {
|
|
6
|
+
error: (issue) => `invalid level ${JSON.stringify(issue.input)} (expected "error" or "warn")`,
|
|
7
|
+
});
|
|
8
|
+
const ignoreEntrySchema = z.union([
|
|
9
|
+
z.string(),
|
|
10
|
+
z.object({
|
|
11
|
+
pattern: z.string(),
|
|
12
|
+
reason: z.string().optional(),
|
|
13
|
+
}),
|
|
14
|
+
]);
|
|
15
|
+
const configSchema = z.object({
|
|
16
|
+
openapi: z.string().optional(),
|
|
17
|
+
src: z.union([z.string(), z.array(z.string()).min(1)]).optional(),
|
|
18
|
+
output: z.string().optional(),
|
|
19
|
+
level: severityLevelSchema.optional(),
|
|
20
|
+
ignore: z.array(ignoreEntrySchema).optional(),
|
|
21
|
+
locations: z.record(z.string(), z.array(z.string()).min(1)).optional(),
|
|
22
|
+
});
|
|
23
|
+
const KNOWN_CONFIG_KEYS = new Set(Object.keys(configSchema.shape));
|
|
4
24
|
const DEFAULT_CONFIG_FILES = [
|
|
5
25
|
"openapi-usage.yaml",
|
|
6
26
|
"openapi-usage.yml",
|
|
@@ -8,9 +28,30 @@ const DEFAULT_CONFIG_FILES = [
|
|
|
8
28
|
".openapi-usage.yml",
|
|
9
29
|
];
|
|
10
30
|
/**
|
|
11
|
-
*
|
|
31
|
+
* 正規表現のメタ文字をエスケープする
|
|
32
|
+
* @param str - エスケープ対象の文字列
|
|
33
|
+
* @returns リテラルとしてマッチする正規表現ソース
|
|
34
|
+
*/
|
|
35
|
+
export function escapeRegex(str) {
|
|
36
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
37
|
+
}
|
|
38
|
+
function formatIssues(issues) {
|
|
39
|
+
return issues
|
|
40
|
+
.map((issue) => {
|
|
41
|
+
const path = issue.path.join(".");
|
|
42
|
+
return path ? `${path}: ${issue.message}` : issue.message;
|
|
43
|
+
})
|
|
44
|
+
.join(", ");
|
|
45
|
+
}
|
|
46
|
+
function collectUnknownKeys(parsed, source) {
|
|
47
|
+
return Object.keys(parsed)
|
|
48
|
+
.filter((key) => !KNOWN_CONFIG_KEYS.has(key))
|
|
49
|
+
.map((key) => `unknown config key "${key}" in ${source} (ignored)`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 設定ファイルを探して読み込み、スキーマ検証する
|
|
12
53
|
* @param configPath - 明示的に指定された設定ファイルパス(省略時はデフォルトファイルを探索)
|
|
13
|
-
* @returns
|
|
54
|
+
* @returns 検証済みの設定オブジェクト(+警告)またはエラー
|
|
14
55
|
*/
|
|
15
56
|
export function loadConfig(configPath) {
|
|
16
57
|
let resolvedPath;
|
|
@@ -33,36 +74,67 @@ export function loadConfig(configPath) {
|
|
|
33
74
|
}
|
|
34
75
|
}
|
|
35
76
|
if (!resolvedPath) {
|
|
36
|
-
return { success: true, config: {} };
|
|
77
|
+
return { success: true, config: {}, warnings: [] };
|
|
37
78
|
}
|
|
79
|
+
let raw;
|
|
38
80
|
try {
|
|
39
|
-
|
|
40
|
-
const parsed = parse(content);
|
|
41
|
-
return { success: true, config: parsed ?? {} };
|
|
81
|
+
raw = parse(readFileSync(resolvedPath, "utf-8"));
|
|
42
82
|
}
|
|
43
83
|
catch (e) {
|
|
44
84
|
const message = e instanceof Error ? e.message : String(e);
|
|
45
85
|
return { success: false, error: `Failed to parse config file: ${message}` };
|
|
46
86
|
}
|
|
87
|
+
if (raw == null) {
|
|
88
|
+
return { success: true, config: {}, warnings: [] };
|
|
89
|
+
}
|
|
90
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: `Invalid config file ${resolvedPath}: expected a mapping of options`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const result = configSchema.safeParse(raw);
|
|
97
|
+
if (!result.success) {
|
|
98
|
+
return {
|
|
99
|
+
success: false,
|
|
100
|
+
error: `Invalid config file ${resolvedPath}: ${formatIssues(result.error.issues)}`,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
success: true,
|
|
105
|
+
config: result.data,
|
|
106
|
+
warnings: collectUnknownKeys(raw, resolvedPath),
|
|
107
|
+
};
|
|
47
108
|
}
|
|
48
109
|
/**
|
|
49
|
-
*
|
|
110
|
+
* ignoreエントリを正規化する(文字列/object の混在を IgnoreRule[] に揃える)
|
|
111
|
+
* @param entries - 設定ファイルのignoreエントリ
|
|
112
|
+
* @returns 正規化済みルールの配列
|
|
113
|
+
*/
|
|
114
|
+
export function normalizeIgnoreRules(entries) {
|
|
115
|
+
return entries.map((entry) => typeof entry === "string" ? { pattern: entry } : entry);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* "METHOD /path" 形式のキーがパターンにマッチするか判定する
|
|
119
|
+
* `*` は任意の文字列にマッチし、それ以外の文字はリテラルとして扱う
|
|
50
120
|
* @param endpoint - "METHOD /path" 形式のエンドポイント
|
|
51
|
-
* @param
|
|
121
|
+
* @param pattern - マッチ対象のパターン
|
|
52
122
|
* @returns マッチした場合はtrue
|
|
53
123
|
*/
|
|
54
|
-
export function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const regex = new RegExp(`^${pattern.replace(/\*/g, ".*").replace(/\//g, "\\/")}$`);
|
|
58
|
-
if (regex.test(endpoint)) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else if (endpoint === pattern) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
124
|
+
export function matchEndpointPattern(endpoint, pattern) {
|
|
125
|
+
if (!pattern.includes("*")) {
|
|
126
|
+
return endpoint === pattern;
|
|
65
127
|
}
|
|
66
|
-
|
|
128
|
+
const regex = new RegExp(`^${pattern.split("*").map(escapeRegex).join(".*")}$`);
|
|
129
|
+
return regex.test(endpoint);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* エンドポイントがignoreリストにマッチするか判定
|
|
133
|
+
* @param endpoint - "METHOD /path" 形式のエンドポイント
|
|
134
|
+
* @param ignoreEntries - ignoreパターンの配列(文字列または理由付きobject)
|
|
135
|
+
* @returns マッチした場合はtrue
|
|
136
|
+
*/
|
|
137
|
+
export function isIgnored(endpoint, ignoreEntries) {
|
|
138
|
+
return normalizeIgnoreRules(ignoreEntries).some((rule) => matchEndpointPattern(endpoint, rule.pattern));
|
|
67
139
|
}
|
|
68
140
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAkCxB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;IAC5D,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAChB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int, findOpenApiFetchClients, } from "./analyzer.js";
|
|
2
2
|
export { type CliOptions, createProgram, parseArgs, type SeverityLevel, } from "./cli.js";
|
|
3
|
-
export { type Config, isIgnored, loadConfig } from "./config.js";
|
|
3
|
+
export { type Config, type IgnoreEntry, type IgnoreRule, isIgnored, loadConfig, matchEndpointPattern, normalizeIgnoreRules, severityLevelSchema, } from "./config.js";
|
|
4
|
+
export { findLocationRule, findLocationViolations, type LocationRule, type LocationViolation, matchPathGlob, } from "./locations.js";
|
|
4
5
|
export { type LoadResult, loadOpenAPISpec, parseOpenAPISpec, } from "./openapi-parser.js";
|
|
5
|
-
export { formatSummary, formatTree, generateJsonOutput, getUnusedEndpoints, } from "./output.js";
|
|
6
|
-
export { type RunResult, run } from "./runner.js";
|
|
6
|
+
export { formatIgnoredEndpoints, formatLocationViolations, formatSourceSummary, formatSummary, formatTree, formatUnmatchedIgnoreWarnings, generateJsonOutput, getUnusedEndpoints, } from "./output.js";
|
|
7
|
+
export { applyIgnoreRules, type RunResult, run } from "./runner.js";
|
|
7
8
|
export type { ApiDependencies, Endpoint, HttpMethod, OpenAPIOperation, OpenAPIPathItem, OpenAPISpec, Usage, } from "./types.js";
|
|
8
9
|
export { HTTP_METHODS } from "./types.js";
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,cAAc,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,GACvB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACN,KAAK,UAAU,EACf,aAAa,EACb,SAAS,EACT,KAAK,aAAa,GAClB,MAAM,UAAU,CAAC;AAElB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,KAAK,cAAc,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,GACvB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACN,KAAK,UAAU,EACf,aAAa,EACb,SAAS,EACT,KAAK,aAAa,GAClB,MAAM,UAAU,CAAC;AAElB,OAAO,EACN,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,SAAS,EACT,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,gBAAgB,EAChB,sBAAsB,EACtB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,aAAa,GACb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,KAAK,UAAU,EACf,eAAe,EACf,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACN,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,EACb,UAAU,EACV,6BAA6B,EAC7B,kBAAkB,EAClB,kBAAkB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,gBAAgB,EAAE,KAAK,SAAS,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGpE,YAAY,EACX,eAAe,EACf,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,KAAK,GACL,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,12 +4,14 @@ export { analyzeSourceFile, analyzeTypeScriptFiles, extractStringLiterals, findM
|
|
|
4
4
|
// CLI
|
|
5
5
|
export { createProgram, parseArgs, } from "./cli.js";
|
|
6
6
|
// Config
|
|
7
|
-
export { isIgnored, loadConfig } from "./config.js";
|
|
7
|
+
export { isIgnored, loadConfig, matchEndpointPattern, normalizeIgnoreRules, severityLevelSchema, } from "./config.js";
|
|
8
|
+
// Locations
|
|
9
|
+
export { findLocationRule, findLocationViolations, matchPathGlob, } from "./locations.js";
|
|
8
10
|
// OpenAPI Parser
|
|
9
11
|
export { loadOpenAPISpec, parseOpenAPISpec, } from "./openapi-parser.js";
|
|
10
12
|
// Output
|
|
11
|
-
export { formatSummary, formatTree, generateJsonOutput, getUnusedEndpoints, } from "./output.js";
|
|
13
|
+
export { formatIgnoredEndpoints, formatLocationViolations, formatSourceSummary, formatSummary, formatTree, formatUnmatchedIgnoreWarnings, generateJsonOutput, getUnusedEndpoints, } from "./output.js";
|
|
12
14
|
// Runner
|
|
13
|
-
export { run } from "./runner.js";
|
|
15
|
+
export { applyIgnoreRules, run } from "./runner.js";
|
|
14
16
|
export { HTTP_METHODS } from "./types.js";
|
|
15
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AAEd,WAAW;AACX,OAAO,EAEN,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,GACvB,MAAM,eAAe,CAAC;AAEvB,MAAM;AACN,OAAO,EAEN,aAAa,EACb,SAAS,GAET,MAAM,UAAU,CAAC;AAClB,SAAS;AACT,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AAEd,WAAW;AACX,OAAO,EAEN,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,GACvB,MAAM,eAAe,CAAC;AAEvB,MAAM;AACN,OAAO,EAEN,aAAa,EACb,SAAS,GAET,MAAM,UAAU,CAAC;AAClB,SAAS;AACT,OAAO,EAIN,SAAS,EACT,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,GACnB,MAAM,aAAa,CAAC;AACrB,YAAY;AACZ,OAAO,EACN,gBAAgB,EAChB,sBAAsB,EAGtB,aAAa,GACb,MAAM,gBAAgB,CAAC;AACxB,iBAAiB;AACjB,OAAO,EAEN,eAAe,EACf,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAC7B,SAAS;AACT,OAAO,EACN,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,EACb,UAAU,EACV,6BAA6B,EAC7B,kBAAkB,EAClB,kBAAkB,GAClB,MAAM,aAAa,CAAC;AACrB,SAAS;AACT,OAAO,EAAE,gBAAgB,EAAkB,GAAG,EAAE,MAAM,aAAa,CAAC;AAapE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Usage } from "./types.js";
|
|
2
|
+
/** 呼び出し位置ルール違反 */
|
|
3
|
+
export interface LocationViolation {
|
|
4
|
+
endpoint: string;
|
|
5
|
+
file: string;
|
|
6
|
+
line: number;
|
|
7
|
+
/** マッチしたendpointパターン */
|
|
8
|
+
pattern: string;
|
|
9
|
+
/** 許可されているディレクトリglob */
|
|
10
|
+
allowed: string[];
|
|
11
|
+
}
|
|
12
|
+
/** endpointパターンと許可ディレクトリglobの組 */
|
|
13
|
+
export interface LocationRule {
|
|
14
|
+
pattern: string;
|
|
15
|
+
allowed: string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* ファイルパスがディレクトリglobにマッチするか判定する
|
|
19
|
+
* ワイルドカードを含まないglobと `/` 終わりのglobはディレクトリとみなし、配下の全ファイルにマッチする
|
|
20
|
+
* @param filePath - 判定対象のファイルパス(cwd相対)
|
|
21
|
+
* @param glob - ディレクトリglob(例: "src/hooks/api/**"、"src/hooks/api")
|
|
22
|
+
* @returns マッチした場合はtrue
|
|
23
|
+
*/
|
|
24
|
+
export declare function matchPathGlob(filePath: string, glob: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* endpointに適用される位置ルールを検索する
|
|
27
|
+
* 複数マッチする場合は最も具体的なパターンが優先される
|
|
28
|
+
* @param endpoint - "METHOD /path" 形式のエンドポイント
|
|
29
|
+
* @param locations - endpointパターン → 許可ディレクトリglobのマップ
|
|
30
|
+
* @returns 適用されるルール、なければnull
|
|
31
|
+
*/
|
|
32
|
+
export declare function findLocationRule(endpoint: string, locations: Record<string, string[]>): LocationRule | null;
|
|
33
|
+
/**
|
|
34
|
+
* 呼び出し位置が許可ディレクトリの外にあるものを検出する
|
|
35
|
+
* @param usages - エンドポイントごとの使用箇所マップ
|
|
36
|
+
* @param locations - endpointパターン → 許可ディレクトリglobのマップ
|
|
37
|
+
* @returns 違反の配列
|
|
38
|
+
*/
|
|
39
|
+
export declare function findLocationViolations(usages: Map<string, Usage[]>, locations: Record<string, string[]>): LocationViolation[];
|
|
40
|
+
//# sourceMappingURL=locations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locations.d.ts","sourceRoot":"","sources":["../src/locations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,kBAAkB;AAClB,MAAM,WAAW,iBAAiB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,wBAAwB;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,kCAAkC;AAClC,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB;AAiCD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAgBrE;AAUD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC/B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GACjC,YAAY,GAAG,IAAI,CAOrB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACrC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,EAC5B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GACjC,iBAAiB,EAAE,CAwBrB"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { escapeRegex, matchEndpointPattern } from "./config.js";
|
|
2
|
+
function normalizePath(path) {
|
|
3
|
+
return path.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* ディレクトリglobを正規表現に変換する
|
|
7
|
+
* `**` はディレクトリ境界を越えてマッチし、`*` は越えない
|
|
8
|
+
*/
|
|
9
|
+
function globToRegex(glob) {
|
|
10
|
+
let pattern = "";
|
|
11
|
+
let i = 0;
|
|
12
|
+
while (i < glob.length) {
|
|
13
|
+
if (glob.startsWith("**/", i)) {
|
|
14
|
+
pattern += "(?:.*/)?";
|
|
15
|
+
i += 3;
|
|
16
|
+
}
|
|
17
|
+
else if (glob.startsWith("**", i)) {
|
|
18
|
+
pattern += ".*";
|
|
19
|
+
i += 2;
|
|
20
|
+
}
|
|
21
|
+
else if (glob[i] === "*") {
|
|
22
|
+
pattern += "[^/]*";
|
|
23
|
+
i += 1;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
pattern += escapeRegex(glob[i]);
|
|
27
|
+
i += 1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return new RegExp(`^${pattern}$`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* ファイルパスがディレクトリglobにマッチするか判定する
|
|
34
|
+
* ワイルドカードを含まないglobと `/` 終わりのglobはディレクトリとみなし、配下の全ファイルにマッチする
|
|
35
|
+
* @param filePath - 判定対象のファイルパス(cwd相対)
|
|
36
|
+
* @param glob - ディレクトリglob(例: "src/hooks/api/**"、"src/hooks/api")
|
|
37
|
+
* @returns マッチした場合はtrue
|
|
38
|
+
*/
|
|
39
|
+
export function matchPathGlob(filePath, glob) {
|
|
40
|
+
const normalizedGlob = normalizePath(glob);
|
|
41
|
+
const normalizedFile = normalizePath(filePath);
|
|
42
|
+
if (globToRegex(normalizedGlob).test(normalizedFile)) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
const isDirectory = normalizedGlob.endsWith("/") || !normalizedGlob.includes("*");
|
|
46
|
+
if (!isDirectory) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const directory = normalizedGlob.replace(/\/+$/, "");
|
|
50
|
+
return globToRegex(`${directory}/**`).test(normalizedFile);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* パターンの具体度(ワイルドカードを除いた文字数)
|
|
54
|
+
* 具体度が高いルールを優先して適用する
|
|
55
|
+
*/
|
|
56
|
+
function specificity(pattern) {
|
|
57
|
+
return pattern.replace(/\*/g, "").length;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* endpointに適用される位置ルールを検索する
|
|
61
|
+
* 複数マッチする場合は最も具体的なパターンが優先される
|
|
62
|
+
* @param endpoint - "METHOD /path" 形式のエンドポイント
|
|
63
|
+
* @param locations - endpointパターン → 許可ディレクトリglobのマップ
|
|
64
|
+
* @returns 適用されるルール、なければnull
|
|
65
|
+
*/
|
|
66
|
+
export function findLocationRule(endpoint, locations) {
|
|
67
|
+
const matched = Object.entries(locations)
|
|
68
|
+
.filter(([pattern]) => matchEndpointPattern(endpoint, pattern))
|
|
69
|
+
.sort(([a], [b]) => specificity(b) - specificity(a) || b.length - a.length);
|
|
70
|
+
const rule = matched[0];
|
|
71
|
+
return rule ? { pattern: rule[0], allowed: rule[1] } : null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 呼び出し位置が許可ディレクトリの外にあるものを検出する
|
|
75
|
+
* @param usages - エンドポイントごとの使用箇所マップ
|
|
76
|
+
* @param locations - endpointパターン → 許可ディレクトリglobのマップ
|
|
77
|
+
* @returns 違反の配列
|
|
78
|
+
*/
|
|
79
|
+
export function findLocationViolations(usages, locations) {
|
|
80
|
+
const violations = [];
|
|
81
|
+
for (const [endpoint, usageList] of usages) {
|
|
82
|
+
const rule = findLocationRule(endpoint, locations);
|
|
83
|
+
if (!rule)
|
|
84
|
+
continue;
|
|
85
|
+
for (const usage of usageList) {
|
|
86
|
+
const allowed = rule.allowed.some((glob) => matchPathGlob(usage.file, glob));
|
|
87
|
+
if (!allowed) {
|
|
88
|
+
violations.push({
|
|
89
|
+
endpoint,
|
|
90
|
+
file: usage.file,
|
|
91
|
+
line: usage.line,
|
|
92
|
+
pattern: rule.pattern,
|
|
93
|
+
allowed: rule.allowed,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return violations;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=locations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locations.js","sourceRoot":"","sources":["../src/locations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAoBhE,SAAS,aAAa,CAAC,IAAY;IAClC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,IAAY;IAChC,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,UAAU,CAAC;YACtB,CAAC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AAO,EAAE,CAAC;gBACd,UAAU,CAAC,IAAI,CAAC;oBACf,QAAQ;oBACR,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,OAAO,EAAE,IAAI,CAAC,OAAO;iBACrB,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
|
package/dist/output.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { IgnoreRule } from "./config.js";
|
|
2
|
+
import type { LocationViolation } from "./locations.js";
|
|
1
3
|
import type { ApiDependencies, Usage } from "./types.js";
|
|
2
4
|
/**
|
|
3
5
|
* API使用状況をツリー形式の文字列配列に変換する
|
|
@@ -18,9 +20,36 @@ export declare const getUnusedEndpoints: (usages: Map<string, Usage[]>) => strin
|
|
|
18
20
|
*/
|
|
19
21
|
export declare const formatSummary: (usages: Map<string, Usage[]>) => string[];
|
|
20
22
|
/**
|
|
21
|
-
* API
|
|
23
|
+
* ソースディレクトリごとの未使用API数を文字列配列に変換する
|
|
24
|
+
* 複数の src を指定したときに「どのソースからは未使用か」を示す
|
|
22
25
|
* @param usages - エンドポイントごとの使用箇所マップ
|
|
26
|
+
* @param srcPaths - ソースディレクトリのパス(使用箇所のfileと同じ基準の相対パス)
|
|
27
|
+
* @returns サマリー出力行配列(srcが1つ以下なら空配列)
|
|
28
|
+
*/
|
|
29
|
+
export declare const formatSourceSummary: (usages: Map<string, Usage[]>, srcPaths: string[]) => string[];
|
|
30
|
+
/**
|
|
31
|
+
* ignore済みエンドポイントを理由付きで文字列配列に変換する
|
|
32
|
+
* @param ignored - エンドポイント → 適用されたignoreルールのマップ
|
|
33
|
+
* @returns 出力行配列(ignoreが無ければ空配列)
|
|
34
|
+
*/
|
|
35
|
+
export declare const formatIgnoredEndpoints: (ignored: Map<string, IgnoreRule>) => string[];
|
|
36
|
+
/**
|
|
37
|
+
* どのエンドポイントにもマッチしなかったignoreパターンの警告を生成する
|
|
38
|
+
* @param unmatched - マッチ数0だったignoreルール
|
|
39
|
+
* @returns 警告行配列
|
|
40
|
+
*/
|
|
41
|
+
export declare const formatUnmatchedIgnoreWarnings: (unmatched: IgnoreRule[]) => string[];
|
|
42
|
+
/**
|
|
43
|
+
* 呼び出し位置ルール違反を文字列配列に変換する
|
|
44
|
+
* @param violations - 違反の配列
|
|
45
|
+
* @returns 出力行配列(違反が無ければ空配列)
|
|
46
|
+
*/
|
|
47
|
+
export declare const formatLocationViolations: (violations: LocationViolation[]) => string[];
|
|
48
|
+
/**
|
|
49
|
+
* API使用状況をJSON出力用のオブジェクトに変換する
|
|
50
|
+
* @param usages - エンドポイントごとの使用箇所マップ(ignore済みを含めてよい)
|
|
51
|
+
* @param ignored - ignoreされたエンドポイント → 適用されたignoreルールのマップ
|
|
23
52
|
* @returns JSON出力用のApiDependenciesオブジェクト
|
|
24
53
|
*/
|
|
25
|
-
export declare const generateJsonOutput: (usages: Map<string, Usage[]>) => ApiDependencies;
|
|
54
|
+
export declare const generateJsonOutput: (usages: Map<string, Usage[]>, ignored?: Map<string, IgnoreRule>) => ApiDependencies;
|
|
26
55
|
//# sourceMappingURL=output.d.ts.map
|
package/dist/output.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAY,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAY,KAAK,EAAE,MAAM,YAAY,CAAC;AAsBnE;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,KAAG,MAAM,EAG9D,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,KAAG,MAAM,EAGlD,CAAC;AAEvB;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,KAAG,MAAM,EAYlE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC/B,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,EAC5B,UAAU,MAAM,EAAE,KAChB,MAAM,EAiBR,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAClC,SAAS,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,KAC9B,MAAM,EAUR,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,GACzC,WAAW,UAAU,EAAE,KACrB,MAAM,EAGP,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GACpC,YAAY,iBAAiB,EAAE,KAC7B,MAAM,EAWR,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAC9B,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,EAC5B,UAAS,GAAG,CAAC,MAAM,EAAE,UAAU,CAAa,KAC1C,eAqCF,CAAC"}
|
package/dist/output.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const SEPARATOR = "─".repeat(35);
|
|
2
|
+
const toPosixPath = (path) => path.replace(/\\/g, "/");
|
|
1
3
|
const sortByKey = (entries) => entries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
2
4
|
const formatUsageLines = (key, usages) => {
|
|
3
5
|
if (usages.length === 0) {
|
|
@@ -30,34 +32,104 @@ export const getUnusedEndpoints = (usages) => [...usages.entries()]
|
|
|
30
32
|
*/
|
|
31
33
|
export const formatSummary = (usages) => {
|
|
32
34
|
const unused = getUnusedEndpoints(usages);
|
|
33
|
-
const separator = "─".repeat(35);
|
|
34
35
|
if (unused.length === 0) {
|
|
35
|
-
return [
|
|
36
|
+
return [SEPARATOR, "Unused APIs: 0"];
|
|
36
37
|
}
|
|
37
38
|
return [
|
|
38
|
-
|
|
39
|
+
SEPARATOR,
|
|
39
40
|
`Unused APIs: ${unused.length}`,
|
|
40
41
|
...unused.map((endpoint) => ` - ${endpoint}`),
|
|
41
42
|
];
|
|
42
43
|
};
|
|
43
44
|
/**
|
|
44
|
-
* API
|
|
45
|
+
* ソースディレクトリごとの未使用API数を文字列配列に変換する
|
|
46
|
+
* 複数の src を指定したときに「どのソースからは未使用か」を示す
|
|
45
47
|
* @param usages - エンドポイントごとの使用箇所マップ
|
|
48
|
+
* @param srcPaths - ソースディレクトリのパス(使用箇所のfileと同じ基準の相対パス)
|
|
49
|
+
* @returns サマリー出力行配列(srcが1つ以下なら空配列)
|
|
50
|
+
*/
|
|
51
|
+
export const formatSourceSummary = (usages, srcPaths) => {
|
|
52
|
+
if (srcPaths.length <= 1) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
const lines = srcPaths.map((srcPath) => {
|
|
56
|
+
const root = toPosixPath(srcPath).replace(/\/+$/, "");
|
|
57
|
+
// srcがカレントディレクトリ自身("" または ".")の場合は全ファイルが対象
|
|
58
|
+
const prefix = root === "" || root === "." ? "" : `${root}/`;
|
|
59
|
+
const unused = [...usages.values()].filter((list) => !list.some((usage) => toPosixPath(usage.file).startsWith(prefix))).length;
|
|
60
|
+
return ` ${srcPath || "."}: ${unused}`;
|
|
61
|
+
});
|
|
62
|
+
return ["Unused APIs per source:", ...lines];
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* ignore済みエンドポイントを理由付きで文字列配列に変換する
|
|
66
|
+
* @param ignored - エンドポイント → 適用されたignoreルールのマップ
|
|
67
|
+
* @returns 出力行配列(ignoreが無ければ空配列)
|
|
68
|
+
*/
|
|
69
|
+
export const formatIgnoredEndpoints = (ignored) => {
|
|
70
|
+
if (ignored.size === 0) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
const lines = sortByKey([...ignored.entries()]).map(([endpoint, rule]) => rule.reason ? ` - ${endpoint} (${rule.reason})` : ` - ${endpoint}`);
|
|
74
|
+
return [`Ignored APIs: ${ignored.size}`, ...lines];
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* どのエンドポイントにもマッチしなかったignoreパターンの警告を生成する
|
|
78
|
+
* @param unmatched - マッチ数0だったignoreルール
|
|
79
|
+
* @returns 警告行配列
|
|
80
|
+
*/
|
|
81
|
+
export const formatUnmatchedIgnoreWarnings = (unmatched) => unmatched.map((rule) => `warning: ignore pattern "${rule.pattern}" matched no endpoint`);
|
|
82
|
+
/**
|
|
83
|
+
* 呼び出し位置ルール違反を文字列配列に変換する
|
|
84
|
+
* @param violations - 違反の配列
|
|
85
|
+
* @returns 出力行配列(違反が無ければ空配列)
|
|
86
|
+
*/
|
|
87
|
+
export const formatLocationViolations = (violations) => {
|
|
88
|
+
if (violations.length === 0) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
const lines = violations.flatMap((violation) => [
|
|
92
|
+
` - ${violation.endpoint} at ${violation.file}:${violation.line}`,
|
|
93
|
+
` allowed: ${violation.allowed.join(", ")} (rule: "${violation.pattern}")`,
|
|
94
|
+
]);
|
|
95
|
+
return [SEPARATOR, `Location violations: ${violations.length}`, ...lines];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* API使用状況をJSON出力用のオブジェクトに変換する
|
|
99
|
+
* @param usages - エンドポイントごとの使用箇所マップ(ignore済みを含めてよい)
|
|
100
|
+
* @param ignored - ignoreされたエンドポイント → 適用されたignoreルールのマップ
|
|
46
101
|
* @returns JSON出力用のApiDependenciesオブジェクト
|
|
47
102
|
*/
|
|
48
|
-
export const generateJsonOutput = (usages) => {
|
|
49
|
-
|
|
50
|
-
const
|
|
103
|
+
export const generateJsonOutput = (usages, ignored = new Map()) => {
|
|
104
|
+
// usagesに含まれないignore済みエンドポイントは使用箇所なしとして補う
|
|
105
|
+
const all = new Map(usages);
|
|
106
|
+
for (const key of ignored.keys()) {
|
|
107
|
+
if (!all.has(key)) {
|
|
108
|
+
all.set(key, []);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const endpoints = sortByKey([...all.entries()]).map(([key, usageList]) => {
|
|
51
112
|
const [method, path] = key.split(" ", 2);
|
|
52
|
-
|
|
113
|
+
const endpoint = { method, path, usages: usageList };
|
|
114
|
+
const rule = ignored.get(key);
|
|
115
|
+
if (!rule) {
|
|
116
|
+
return endpoint;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
...endpoint,
|
|
120
|
+
ignored: true,
|
|
121
|
+
...(rule.reason ? { reason: rule.reason } : {}),
|
|
122
|
+
};
|
|
53
123
|
});
|
|
54
|
-
const
|
|
124
|
+
const active = endpoints.filter((endpoint) => !endpoint.ignored);
|
|
125
|
+
const used = active.filter((endpoint) => endpoint.usages.length > 0).length;
|
|
55
126
|
return {
|
|
56
127
|
endpoints,
|
|
57
128
|
summary: {
|
|
58
129
|
total: endpoints.length,
|
|
59
130
|
used,
|
|
60
|
-
unused:
|
|
131
|
+
unused: active.length - used,
|
|
132
|
+
ignored: endpoints.length - active.length,
|
|
61
133
|
},
|
|
62
134
|
};
|
|
63
135
|
};
|
package/dist/output.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAIA,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC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AAG,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,EAAE,CAAC;YACX,OAAO,QAAQ,CAAC;QACjB,CAAC;QACD,OAAO;YACN,GAAG,QAAQ;YACX,OAAO,EAAE,IAAI;YACb,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/C,CAAC;IACH,CAAC,CACD,CAAC;IAEF,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjE,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;IAE5E,OAAO;QACN,SAAS;QACT,OAAO,EAAE;YACR,KAAK,EAAE,SAAS,CAAC,MAAM;YACvB,IAAI;YACJ,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,IAAI;YAC5B,OAAO,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM;SACzC;KACD,CAAC;AACH,CAAC,CAAC"}
|
package/dist/runner.d.ts
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
import type { CliOptions } from "./cli.js";
|
|
2
|
+
import { type IgnoreRule } from "./config.js";
|
|
3
|
+
import type { Usage } from "./types.js";
|
|
2
4
|
export interface RunResult {
|
|
3
5
|
success: boolean;
|
|
4
6
|
exitCode: number;
|
|
5
7
|
error?: string;
|
|
6
8
|
}
|
|
9
|
+
interface IgnoreResult {
|
|
10
|
+
/** ignoreされなかったエンドポイント */
|
|
11
|
+
kept: Map<string, Usage[]>;
|
|
12
|
+
/** ignoreされたエンドポイント → 適用されたルール */
|
|
13
|
+
ignored: Map<string, IgnoreRule>;
|
|
14
|
+
/** どのエンドポイントにもマッチしなかったルール */
|
|
15
|
+
unmatched: IgnoreRule[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* ignoreルールを適用し、マッチ数0のルールを検出する
|
|
19
|
+
* @param usages - エンドポイントごとの使用箇所マップ
|
|
20
|
+
* @param rules - 正規化済みignoreルール
|
|
21
|
+
* @returns 残ったエンドポイント、ignore済みエンドポイント、未マッチルール
|
|
22
|
+
*/
|
|
23
|
+
export declare function applyIgnoreRules(usages: Map<string, Usage[]>, rules: IgnoreRule[]): IgnoreResult;
|
|
7
24
|
/**
|
|
8
25
|
* API使用状況解析を実行する
|
|
9
26
|
* @param options - CLIオプション(OpenAPIパス、ソースパス等)
|
|
10
27
|
* @returns 実行結果(成功/失敗、終了コード、エラーメッセージ)
|
|
11
28
|
*/
|
|
12
29
|
export declare function run(options: CliOptions): RunResult;
|
|
30
|
+
export {};
|
|
13
31
|
//# sourceMappingURL=runner.d.ts.map
|
package/dist/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,UAAU,CAAC;AAC1D,OAAO,EAEN,KAAK,UAAU,EAKf,MAAM,aAAa,CAAC;AAarB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,WAAW,SAAS;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAyGD,UAAU,YAAY;IACrB,0BAA0B;IAC1B,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3B,kCAAkC;IAClC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjC,6BAA6B;IAC7B,SAAS,EAAE,UAAU,EAAE,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,EAC5B,KAAK,EAAE,UAAU,EAAE,GACjB,YAAY,CA0Bd;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAgGlD"}
|