@omkar-sonawane-05/routemap-ir 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +33 -2
- package/dist/index.cjs +561 -0
- package/dist/index.d.cts +621 -0
- package/dist/index.d.ts +621 -0
- package/dist/index.js +504 -0
- package/package.json +47 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RouteMap contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @omkar-sonawane-05/routemap-ir
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Type definitions and builders for the **RouteMap Intermediate Representation**: the JSON metadata
|
|
4
|
+
model that describes an Express application's full request lifecycle.
|
|
5
|
+
|
|
6
|
+
**Zero dependencies.** Install this if you're writing a RouteMap plugin or consuming `ir.json`.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install --save-dev @omkar-sonawane-05/routemap-ir
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import type { RouteMapIR, Route, FieldDef } from "@omkar-sonawane-05/routemap-ir";
|
|
15
|
+
import { stableStringify, mergeField, routeId } from "@omkar-sonawane-05/routemap-ir";
|
|
16
|
+
|
|
17
|
+
const ir: RouteMapIR = JSON.parse(fs.readFileSync(".routemap/ir.json", "utf8"));
|
|
18
|
+
|
|
19
|
+
for (const route of ir.routes) {
|
|
20
|
+
console.log(route.method, route.path, route.handler.name);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## What's in the IR
|
|
25
|
+
|
|
26
|
+
Each resolved route carries its path, mount chain, ordered lifecycle and security heuristic,
|
|
27
|
+
and the model has room for request fields, responses and call-graph data as analyzers fill them in;
|
|
28
|
+
each fact tagged with `confidence` and `evidence` pointing back at the source.
|
|
29
|
+
|
|
30
|
+
See the [IR specification](https://github.com/Omkar-Sonawane-23/routemap/blob/main/docs/04-ir-spec.md).
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
DIAGNOSTICS: () => DIAGNOSTICS,
|
|
24
|
+
DOCS_BASE: () => DOCS_BASE,
|
|
25
|
+
HTTP_METHODS: () => HTTP_METHODS,
|
|
26
|
+
IR_VERSION: () => IR_VERSION,
|
|
27
|
+
T: () => T,
|
|
28
|
+
compareRoutes: () => compareRoutes,
|
|
29
|
+
confidenceRank: () => confidenceRank,
|
|
30
|
+
diagnostic: () => diagnostic,
|
|
31
|
+
emptyCallNode: () => emptyCallNode,
|
|
32
|
+
emptyCoverage: () => emptyCoverage,
|
|
33
|
+
emptyGraphIndex: () => emptyGraphIndex,
|
|
34
|
+
emptyIR: () => emptyIR,
|
|
35
|
+
evidence: () => evidence,
|
|
36
|
+
field: () => field,
|
|
37
|
+
fingerprint: () => fingerprint,
|
|
38
|
+
hash12: () => hash12,
|
|
39
|
+
isCompatible: () => isCompatible,
|
|
40
|
+
isUnknownType: () => isUnknownType,
|
|
41
|
+
meetsMinConfidence: () => meetsMinConfidence,
|
|
42
|
+
mergeField: () => mergeField,
|
|
43
|
+
mergeType: () => mergeType,
|
|
44
|
+
migrateIR: () => migrateIR,
|
|
45
|
+
migrations: () => migrations,
|
|
46
|
+
responseKindFor: () => responseKindFor,
|
|
47
|
+
routeId: () => routeId,
|
|
48
|
+
sameType: () => sameType,
|
|
49
|
+
stableStringify: () => stableStringify,
|
|
50
|
+
strongerConfidence: () => strongerConfidence,
|
|
51
|
+
typeToString: () => typeToString,
|
|
52
|
+
upsertField: () => upsertField,
|
|
53
|
+
weakestConfidence: () => weakestConfidence
|
|
54
|
+
});
|
|
55
|
+
module.exports = __toCommonJS(index_exports);
|
|
56
|
+
|
|
57
|
+
// src/version.ts
|
|
58
|
+
var IR_VERSION = "1.0.0";
|
|
59
|
+
var migrations = {};
|
|
60
|
+
function migrateIR(ir) {
|
|
61
|
+
let current = ir;
|
|
62
|
+
let guard = 0;
|
|
63
|
+
while (current?.irVersion !== IR_VERSION && guard++ < 20) {
|
|
64
|
+
const migrate = migrations[current?.irVersion];
|
|
65
|
+
if (!migrate) break;
|
|
66
|
+
current = migrate(current);
|
|
67
|
+
}
|
|
68
|
+
return current;
|
|
69
|
+
}
|
|
70
|
+
function isCompatible(irVersion) {
|
|
71
|
+
const major = (v) => v.split(".")[0];
|
|
72
|
+
return major(irVersion) === major(IR_VERSION);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/builders.ts
|
|
76
|
+
var CONFIDENCE_RANK = {
|
|
77
|
+
heuristic: 0,
|
|
78
|
+
inferred: 1,
|
|
79
|
+
certain: 2
|
|
80
|
+
};
|
|
81
|
+
function confidenceRank(c) {
|
|
82
|
+
return CONFIDENCE_RANK[c];
|
|
83
|
+
}
|
|
84
|
+
function strongerConfidence(a, b) {
|
|
85
|
+
return CONFIDENCE_RANK[b] > CONFIDENCE_RANK[a] ? b : a;
|
|
86
|
+
}
|
|
87
|
+
function weakestConfidence(values) {
|
|
88
|
+
let out = "certain";
|
|
89
|
+
for (const v of values) {
|
|
90
|
+
if (CONFIDENCE_RANK[v] < CONFIDENCE_RANK[out]) out = v;
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
function meetsMinConfidence(c, min) {
|
|
95
|
+
return CONFIDENCE_RANK[c] >= CONFIDENCE_RANK[min];
|
|
96
|
+
}
|
|
97
|
+
function evidence(analyzer, reason, confidence, source) {
|
|
98
|
+
const e = { analyzer, reason, confidence };
|
|
99
|
+
if (source) e.source = source;
|
|
100
|
+
return e;
|
|
101
|
+
}
|
|
102
|
+
var T = {
|
|
103
|
+
string: () => ({ kind: "primitive", name: "string" }),
|
|
104
|
+
number: () => ({ kind: "primitive", name: "number" }),
|
|
105
|
+
boolean: () => ({ kind: "primitive", name: "boolean" }),
|
|
106
|
+
date: () => ({ kind: "primitive", name: "date" }),
|
|
107
|
+
file: () => ({ kind: "primitive", name: "file" }),
|
|
108
|
+
any: () => ({ kind: "primitive", name: "any" }),
|
|
109
|
+
unknown: (reason) => reason ? { kind: "unknown", reason } : { kind: "unknown" },
|
|
110
|
+
array: (items) => ({ kind: "array", items }),
|
|
111
|
+
object: (fields, additionalProperties) => additionalProperties === void 0 ? { kind: "object", fields } : { kind: "object", fields, additionalProperties },
|
|
112
|
+
literal: (value) => ({ kind: "literal", value }),
|
|
113
|
+
union: (options) => ({ kind: "union", options }),
|
|
114
|
+
ref: (schemaId) => ({ kind: "ref", schema: { schemaId } })
|
|
115
|
+
};
|
|
116
|
+
function isUnknownType(t) {
|
|
117
|
+
return !t || t.kind === "unknown" || t.kind === "primitive" && t.name === "any";
|
|
118
|
+
}
|
|
119
|
+
function typeToString(t) {
|
|
120
|
+
switch (t.kind) {
|
|
121
|
+
case "primitive":
|
|
122
|
+
return t.name;
|
|
123
|
+
case "array":
|
|
124
|
+
return `${typeToString(t.items)}[]`;
|
|
125
|
+
case "object":
|
|
126
|
+
return t.fields.length ? `{ ${t.fields.map((f) => f.name).join(", ")} }` : "object";
|
|
127
|
+
case "union":
|
|
128
|
+
return t.options.map(typeToString).join(" | ");
|
|
129
|
+
case "literal":
|
|
130
|
+
return typeof t.value === "string" ? `"${t.value}"` : String(t.value);
|
|
131
|
+
case "ref":
|
|
132
|
+
return t.schema.schemaId;
|
|
133
|
+
case "unknown":
|
|
134
|
+
return "unknown";
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function mergeType(a, b) {
|
|
138
|
+
if (!a) return b ?? T.unknown();
|
|
139
|
+
if (!b) return a;
|
|
140
|
+
if (isUnknownType(a)) return b;
|
|
141
|
+
if (isUnknownType(b)) return a;
|
|
142
|
+
if (sameType(a, b)) return a;
|
|
143
|
+
if (a.kind === "literal" && b.kind === "primitive" && literalPrimitive(a.value) === b.name) {
|
|
144
|
+
return b;
|
|
145
|
+
}
|
|
146
|
+
if (b.kind === "literal" && a.kind === "primitive" && literalPrimitive(b.value) === a.name) {
|
|
147
|
+
return a;
|
|
148
|
+
}
|
|
149
|
+
const options = [...flattenUnion(a), ...flattenUnion(b)];
|
|
150
|
+
const deduped = [];
|
|
151
|
+
for (const o of options) {
|
|
152
|
+
if (!deduped.some((d) => sameType(d, o))) deduped.push(o);
|
|
153
|
+
}
|
|
154
|
+
return deduped.length === 1 ? deduped[0] : { kind: "union", options: deduped };
|
|
155
|
+
}
|
|
156
|
+
function literalPrimitive(v) {
|
|
157
|
+
return typeof v;
|
|
158
|
+
}
|
|
159
|
+
function flattenUnion(t) {
|
|
160
|
+
return t.kind === "union" ? t.options.flatMap(flattenUnion) : [t];
|
|
161
|
+
}
|
|
162
|
+
function sameType(a, b) {
|
|
163
|
+
if (a.kind !== b.kind) return false;
|
|
164
|
+
switch (a.kind) {
|
|
165
|
+
case "primitive":
|
|
166
|
+
return a.name === b.name;
|
|
167
|
+
case "literal":
|
|
168
|
+
return a.value === b.value;
|
|
169
|
+
case "array":
|
|
170
|
+
return sameType(a.items, b.items);
|
|
171
|
+
case "ref":
|
|
172
|
+
return a.schema.schemaId === b.schema.schemaId;
|
|
173
|
+
case "object": {
|
|
174
|
+
const bb = b;
|
|
175
|
+
if (a.fields.length !== bb.fields.length) return false;
|
|
176
|
+
return a.fields.every((f, i) => f.name === bb.fields[i]?.name);
|
|
177
|
+
}
|
|
178
|
+
case "union": {
|
|
179
|
+
const bb = b;
|
|
180
|
+
if (a.options.length !== bb.options.length) return false;
|
|
181
|
+
return a.options.every((o, i) => sameType(o, bb.options[i]));
|
|
182
|
+
}
|
|
183
|
+
case "unknown":
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function field(name, type, init = {}) {
|
|
188
|
+
return {
|
|
189
|
+
name,
|
|
190
|
+
type,
|
|
191
|
+
required: init.required ?? false,
|
|
192
|
+
usedAt: init.usedAt ?? [],
|
|
193
|
+
confidence: init.confidence ?? "inferred",
|
|
194
|
+
evidence: init.evidence ?? [],
|
|
195
|
+
...init
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function mergeField(existing, incoming) {
|
|
199
|
+
const incomingWins = CONFIDENCE_RANK[incoming.confidence] >= CONFIDENCE_RANK[existing.confidence];
|
|
200
|
+
const typeConflict = !isUnknownType(existing.type) && !isUnknownType(incoming.type) && !sameType(existing.type, incoming.type);
|
|
201
|
+
if (incomingWins) {
|
|
202
|
+
if (!isUnknownType(incoming.type)) existing.type = incoming.type;
|
|
203
|
+
existing.confidence = incoming.confidence;
|
|
204
|
+
if (incoming.required) existing.required = true;
|
|
205
|
+
if (incoming.optional !== void 0) existing.optional = incoming.optional;
|
|
206
|
+
if (incoming.nullable !== void 0) existing.nullable = incoming.nullable;
|
|
207
|
+
if (incoming.default !== void 0) existing.default = incoming.default;
|
|
208
|
+
if (incoming.enum) existing.enum = incoming.enum;
|
|
209
|
+
if (incoming.description) existing.description = incoming.description;
|
|
210
|
+
if (incoming.wireType) existing.wireType = incoming.wireType;
|
|
211
|
+
if (incoming.constraints) {
|
|
212
|
+
existing.constraints = { ...existing.constraints, ...incoming.constraints };
|
|
213
|
+
}
|
|
214
|
+
} else if (isUnknownType(existing.type) && !isUnknownType(incoming.type)) {
|
|
215
|
+
existing.type = incoming.type;
|
|
216
|
+
}
|
|
217
|
+
existing.evidence.push(...incoming.evidence);
|
|
218
|
+
for (const loc of incoming.usedAt) {
|
|
219
|
+
if (!existing.usedAt.some((u) => u.file === loc.file && u.line === loc.line)) {
|
|
220
|
+
existing.usedAt.push(loc);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return typeConflict;
|
|
224
|
+
}
|
|
225
|
+
function upsertField(list, incoming) {
|
|
226
|
+
const existing = list.find((f) => f.name === incoming.name);
|
|
227
|
+
if (!existing) {
|
|
228
|
+
list.push(incoming);
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
return mergeField(existing, incoming);
|
|
232
|
+
}
|
|
233
|
+
function routeId(method, path, handlerRef = "") {
|
|
234
|
+
return hash12(`${method}:${path}:${handlerRef}`);
|
|
235
|
+
}
|
|
236
|
+
function hash12(input) {
|
|
237
|
+
let h = 0xcbf29ce484222325n;
|
|
238
|
+
const prime = 0x100000001b3n;
|
|
239
|
+
const mask = 0xffffffffffffffffn;
|
|
240
|
+
for (let i = 0; i < input.length; i++) {
|
|
241
|
+
h ^= BigInt(input.charCodeAt(i));
|
|
242
|
+
h = h * prime & mask;
|
|
243
|
+
}
|
|
244
|
+
return h.toString(16).padStart(16, "0").slice(0, 12);
|
|
245
|
+
}
|
|
246
|
+
function responseKindFor(status) {
|
|
247
|
+
if (status === "unknown") return "success";
|
|
248
|
+
if (status >= 300 && status < 400) return "redirect";
|
|
249
|
+
if (status >= 400 && status < 500) return "client-error";
|
|
250
|
+
if (status >= 500) return "server-error";
|
|
251
|
+
return "success";
|
|
252
|
+
}
|
|
253
|
+
var HTTP_METHODS = [
|
|
254
|
+
"GET",
|
|
255
|
+
"POST",
|
|
256
|
+
"PUT",
|
|
257
|
+
"PATCH",
|
|
258
|
+
"DELETE",
|
|
259
|
+
"HEAD",
|
|
260
|
+
"OPTIONS"
|
|
261
|
+
];
|
|
262
|
+
var METHOD_ORDER = {
|
|
263
|
+
GET: 0,
|
|
264
|
+
POST: 1,
|
|
265
|
+
PUT: 2,
|
|
266
|
+
PATCH: 3,
|
|
267
|
+
DELETE: 4,
|
|
268
|
+
HEAD: 5,
|
|
269
|
+
OPTIONS: 6,
|
|
270
|
+
ALL: 7,
|
|
271
|
+
UNKNOWN: 8
|
|
272
|
+
};
|
|
273
|
+
function compareRoutes(a, b) {
|
|
274
|
+
if (a.path !== b.path) return a.path < b.path ? -1 : 1;
|
|
275
|
+
const ma = METHOD_ORDER[a.method] ?? 99;
|
|
276
|
+
const mb = METHOD_ORDER[b.method] ?? 99;
|
|
277
|
+
if (ma !== mb) return ma - mb;
|
|
278
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
279
|
+
}
|
|
280
|
+
function emptyCallNode(name, id) {
|
|
281
|
+
return {
|
|
282
|
+
id: id ?? hash12(`cg:${name}`),
|
|
283
|
+
name,
|
|
284
|
+
layer: "unknown",
|
|
285
|
+
kind: "unknown",
|
|
286
|
+
depth: 0,
|
|
287
|
+
children: []
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function emptyGraphIndex() {
|
|
291
|
+
return {
|
|
292
|
+
byTag: {},
|
|
293
|
+
byModel: {},
|
|
294
|
+
byMiddleware: {},
|
|
295
|
+
byFile: {},
|
|
296
|
+
bySymbol: {},
|
|
297
|
+
unauthenticated: [],
|
|
298
|
+
unvalidated: [],
|
|
299
|
+
duplicates: [],
|
|
300
|
+
orphanFiles: []
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function emptyCoverage() {
|
|
304
|
+
return {
|
|
305
|
+
routesTotal: 0,
|
|
306
|
+
routesFullyResolved: 0,
|
|
307
|
+
routesPartial: 0,
|
|
308
|
+
handlersResolved: 0,
|
|
309
|
+
routesWithValidation: 0,
|
|
310
|
+
routesWithResponses: 0,
|
|
311
|
+
routesWithAuth: 0,
|
|
312
|
+
fieldsTyped: 0,
|
|
313
|
+
fieldsUnknown: 0,
|
|
314
|
+
unresolved: [],
|
|
315
|
+
score: 0
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function emptyIR(meta = {}) {
|
|
319
|
+
return {
|
|
320
|
+
irVersion: IR_VERSION,
|
|
321
|
+
meta: {
|
|
322
|
+
name: "unknown",
|
|
323
|
+
root: ".",
|
|
324
|
+
framework: { name: "express" },
|
|
325
|
+
entrypoints: [],
|
|
326
|
+
analyzedFiles: 0,
|
|
327
|
+
totalRoutes: 0,
|
|
328
|
+
toolVersion: "0.0.0",
|
|
329
|
+
analysisDepth: "syntactic",
|
|
330
|
+
...meta
|
|
331
|
+
},
|
|
332
|
+
routes: [],
|
|
333
|
+
models: [],
|
|
334
|
+
middlewares: [],
|
|
335
|
+
schemas: [],
|
|
336
|
+
graph: emptyGraphIndex(),
|
|
337
|
+
diagnostics: [],
|
|
338
|
+
coverage: emptyCoverage()
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/stable-json.ts
|
|
343
|
+
var VOLATILE_META_KEYS = /* @__PURE__ */ new Set(["generatedAt", "durationMs"]);
|
|
344
|
+
function stableStringify(value, options = {}) {
|
|
345
|
+
const { indent = 2, deterministic = false } = options;
|
|
346
|
+
const normalized = normalize(value, deterministic, "");
|
|
347
|
+
return JSON.stringify(normalized, null, indent);
|
|
348
|
+
}
|
|
349
|
+
function normalize(value, deterministic, path) {
|
|
350
|
+
if (value === null || typeof value !== "object") return value;
|
|
351
|
+
if (Array.isArray(value)) return value.map((v, i) => normalize(v, deterministic, `${path}[${i}]`));
|
|
352
|
+
const source = value;
|
|
353
|
+
const out = {};
|
|
354
|
+
for (const key of Object.keys(source).sort()) {
|
|
355
|
+
if (source[key] === void 0) continue;
|
|
356
|
+
if (deterministic && VOLATILE_META_KEYS.has(key)) continue;
|
|
357
|
+
out[key] = normalize(source[key], deterministic, `${path}.${key}`);
|
|
358
|
+
}
|
|
359
|
+
return out;
|
|
360
|
+
}
|
|
361
|
+
function fingerprint(value) {
|
|
362
|
+
const json = stableStringify(value, { indent: 0, deterministic: true });
|
|
363
|
+
let h = 2166136261;
|
|
364
|
+
for (let i = 0; i < json.length; i++) {
|
|
365
|
+
h ^= json.charCodeAt(i);
|
|
366
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
367
|
+
}
|
|
368
|
+
return h.toString(16).padStart(8, "0");
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/diagnostics.ts
|
|
372
|
+
var DOCS_BASE = "https://routemap.dev/diagnostics";
|
|
373
|
+
var DIAGNOSTICS = {
|
|
374
|
+
// RM1xxx — scan / parse
|
|
375
|
+
RM1001: {
|
|
376
|
+
code: "RM1001",
|
|
377
|
+
severity: "warning",
|
|
378
|
+
title: "Failed to parse file",
|
|
379
|
+
hint: "The file is excluded from analysis. Check for syntax errors or unsupported syntax."
|
|
380
|
+
},
|
|
381
|
+
RM1002: {
|
|
382
|
+
code: "RM1002",
|
|
383
|
+
severity: "info",
|
|
384
|
+
title: "No tsconfig.json found",
|
|
385
|
+
hint: "Using a permissive synthesised config. Add a tsconfig.json for better resolution."
|
|
386
|
+
},
|
|
387
|
+
RM1003: {
|
|
388
|
+
code: "RM1003",
|
|
389
|
+
severity: "warning",
|
|
390
|
+
title: "No source files matched",
|
|
391
|
+
hint: "Check `include`/`exclude` in routemap.config.ts, or pass --include."
|
|
392
|
+
},
|
|
393
|
+
RM1101: {
|
|
394
|
+
code: "RM1101",
|
|
395
|
+
severity: "info",
|
|
396
|
+
title: "Could not resolve import",
|
|
397
|
+
hint: "If this uses a path alias, ensure tsconfig `paths` and `baseUrl` are set."
|
|
398
|
+
},
|
|
399
|
+
RM1102: {
|
|
400
|
+
code: "RM1102",
|
|
401
|
+
severity: "info",
|
|
402
|
+
title: "No entrypoint detected",
|
|
403
|
+
hint: "Set `entry` in routemap.config.ts or pass --entry src/app.ts."
|
|
404
|
+
},
|
|
405
|
+
// RM2xxx — route discovery
|
|
406
|
+
RM2001: {
|
|
407
|
+
code: "RM2001",
|
|
408
|
+
severity: "warning",
|
|
409
|
+
title: "Dynamic HTTP method could not be resolved",
|
|
410
|
+
hint: "Use an explicit method call, or annotate the route with @routemap-method GET."
|
|
411
|
+
},
|
|
412
|
+
RM2002: {
|
|
413
|
+
code: "RM2002",
|
|
414
|
+
severity: "warning",
|
|
415
|
+
title: "Could not resolve route handler",
|
|
416
|
+
hint: "Annotate with @routemap-handler <name>, or add an override in routemap.config.ts."
|
|
417
|
+
},
|
|
418
|
+
RM2003: {
|
|
419
|
+
code: "RM2003",
|
|
420
|
+
severity: "warning",
|
|
421
|
+
title: "Dynamic route path could not be fully resolved",
|
|
422
|
+
hint: "Annotate with @routemap-path /your/path to pin it."
|
|
423
|
+
},
|
|
424
|
+
RM2004: {
|
|
425
|
+
code: "RM2004",
|
|
426
|
+
severity: "info",
|
|
427
|
+
title: "Router created by a factory function",
|
|
428
|
+
hint: "RouteMap followed one level. Deeper indirection needs an override."
|
|
429
|
+
},
|
|
430
|
+
RM2005: {
|
|
431
|
+
code: "RM2005",
|
|
432
|
+
severity: "info",
|
|
433
|
+
title: "Duplicate route: two handlers share the same method and path",
|
|
434
|
+
hint: "The later route is unreachable in Express. Remove or reorder it."
|
|
435
|
+
},
|
|
436
|
+
// RM3xxx — analysis
|
|
437
|
+
RM3001: {
|
|
438
|
+
code: "RM3001",
|
|
439
|
+
severity: "info",
|
|
440
|
+
title: "Conflicting field types reported by two analyzers",
|
|
441
|
+
hint: "Both observations are kept in evidence. Add a validation schema to disambiguate."
|
|
442
|
+
},
|
|
443
|
+
RM3002: {
|
|
444
|
+
code: "RM3002",
|
|
445
|
+
severity: "info",
|
|
446
|
+
title: "Validation middleware found but the library is not recognised",
|
|
447
|
+
hint: "Install the matching analyzer plugin, or describe the shape with @routemap-body."
|
|
448
|
+
},
|
|
449
|
+
RM3003: {
|
|
450
|
+
code: "RM3003",
|
|
451
|
+
severity: "info",
|
|
452
|
+
title: "Call graph depth limit reached",
|
|
453
|
+
hint: "Increase with --depth <n> if you need deeper resolution."
|
|
454
|
+
},
|
|
455
|
+
RM3004: {
|
|
456
|
+
code: "RM3004",
|
|
457
|
+
severity: "info",
|
|
458
|
+
title: "Dynamic property access on req",
|
|
459
|
+
hint: "Field names are not statically known. Use @routemap-body to declare them."
|
|
460
|
+
},
|
|
461
|
+
// RM4xxx — plugins
|
|
462
|
+
RM4001: {
|
|
463
|
+
code: "RM4001",
|
|
464
|
+
severity: "error",
|
|
465
|
+
title: "Plugin threw an error and was disabled for this run",
|
|
466
|
+
hint: "Report this to the plugin author with --debug output."
|
|
467
|
+
},
|
|
468
|
+
RM4002: {
|
|
469
|
+
code: "RM4002",
|
|
470
|
+
severity: "warning",
|
|
471
|
+
title: "Plugin exceeded its time budget and was cancelled",
|
|
472
|
+
hint: "Raise the budget with `plugins.timeout`, or narrow `include`."
|
|
473
|
+
},
|
|
474
|
+
RM4003: {
|
|
475
|
+
code: "RM4003",
|
|
476
|
+
severity: "error",
|
|
477
|
+
title: "Plugin API version mismatch",
|
|
478
|
+
hint: "Update the plugin, or pin an older @omkar-sonawane-05/routemap-core."
|
|
479
|
+
},
|
|
480
|
+
// RM5xxx — generators
|
|
481
|
+
RM5001: {
|
|
482
|
+
code: "RM5001",
|
|
483
|
+
severity: "error",
|
|
484
|
+
title: "Generated OpenAPI document failed validation",
|
|
485
|
+
hint: "The document was written with a .invalid.json suffix for inspection."
|
|
486
|
+
},
|
|
487
|
+
RM5002: {
|
|
488
|
+
code: "RM5002",
|
|
489
|
+
severity: "error",
|
|
490
|
+
title: "Failed to write output file",
|
|
491
|
+
hint: "Check directory permissions and the --out path."
|
|
492
|
+
},
|
|
493
|
+
// RM6xxx — check rules
|
|
494
|
+
RM6001: {
|
|
495
|
+
code: "RM6001",
|
|
496
|
+
severity: "error",
|
|
497
|
+
title: "Route has no authentication",
|
|
498
|
+
hint: "Add auth middleware, or mark it intentional with @routemap-public."
|
|
499
|
+
},
|
|
500
|
+
RM6002: {
|
|
501
|
+
code: "RM6002",
|
|
502
|
+
severity: "warning",
|
|
503
|
+
title: "Route accepts a body but has no validation",
|
|
504
|
+
hint: "Add a validation schema, or allow it in check.rules."
|
|
505
|
+
},
|
|
506
|
+
RM6003: {
|
|
507
|
+
code: "RM6003",
|
|
508
|
+
severity: "error",
|
|
509
|
+
title: "Duplicate route definition",
|
|
510
|
+
hint: "Two routes share a method and path; the second never runs."
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
function diagnostic(code, init = {}) {
|
|
514
|
+
const spec = DIAGNOSTICS[code];
|
|
515
|
+
const d = {
|
|
516
|
+
code,
|
|
517
|
+
severity: init.severity ?? spec.severity,
|
|
518
|
+
message: init.message ?? spec.title,
|
|
519
|
+
docsUrl: `${DOCS_BASE}/${code}`
|
|
520
|
+
};
|
|
521
|
+
const hint = init.hint ?? ("hint" in spec ? spec.hint : void 0);
|
|
522
|
+
if (hint) d.hint = hint;
|
|
523
|
+
if (init.file) d.file = init.file;
|
|
524
|
+
if (init.line !== void 0) d.line = init.line;
|
|
525
|
+
if (init.routeId) d.routeId = init.routeId;
|
|
526
|
+
return d;
|
|
527
|
+
}
|
|
528
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
529
|
+
0 && (module.exports = {
|
|
530
|
+
DIAGNOSTICS,
|
|
531
|
+
DOCS_BASE,
|
|
532
|
+
HTTP_METHODS,
|
|
533
|
+
IR_VERSION,
|
|
534
|
+
T,
|
|
535
|
+
compareRoutes,
|
|
536
|
+
confidenceRank,
|
|
537
|
+
diagnostic,
|
|
538
|
+
emptyCallNode,
|
|
539
|
+
emptyCoverage,
|
|
540
|
+
emptyGraphIndex,
|
|
541
|
+
emptyIR,
|
|
542
|
+
evidence,
|
|
543
|
+
field,
|
|
544
|
+
fingerprint,
|
|
545
|
+
hash12,
|
|
546
|
+
isCompatible,
|
|
547
|
+
isUnknownType,
|
|
548
|
+
meetsMinConfidence,
|
|
549
|
+
mergeField,
|
|
550
|
+
mergeType,
|
|
551
|
+
migrateIR,
|
|
552
|
+
migrations,
|
|
553
|
+
responseKindFor,
|
|
554
|
+
routeId,
|
|
555
|
+
sameType,
|
|
556
|
+
stableStringify,
|
|
557
|
+
strongerConfidence,
|
|
558
|
+
typeToString,
|
|
559
|
+
upsertField,
|
|
560
|
+
weakestConfidence
|
|
561
|
+
});
|