@mrtdown/core 2.0.0-alpha.3 → 2.0.0-alpha.4
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/dist/cli/commands/create.d.ts +30 -0
- package/dist/cli/commands/create.js +189 -0
- package/dist/cli/commands/create.js.map +1 -0
- package/dist/cli/commands/list.d.ts +6 -0
- package/dist/cli/commands/list.js +106 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/show.d.ts +6 -0
- package/dist/cli/commands/show.js +156 -0
- package/dist/cli/commands/show.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +6 -0
- package/dist/cli/commands/validate.js +19 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +162 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/llm/client.d.ts +2 -0
- package/dist/llm/client.js +5 -0
- package/dist/llm/client.js.map +1 -0
- package/dist/llm/common/MemoryStore.d.ts +21 -0
- package/dist/llm/common/MemoryStore.js +100 -0
- package/dist/llm/common/MemoryStore.js.map +1 -0
- package/dist/llm/common/MemoryStore.test.d.ts +1 -0
- package/dist/llm/common/MemoryStore.test.js +225 -0
- package/dist/llm/common/MemoryStore.test.js.map +1 -0
- package/dist/llm/common/formatCurrentState.d.ts +10 -0
- package/dist/llm/common/formatCurrentState.js +342 -0
- package/dist/llm/common/formatCurrentState.js.map +1 -0
- package/dist/llm/common/tool.d.ts +32 -0
- package/dist/llm/common/tool.js +6 -0
- package/dist/llm/common/tool.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/eval.test.d.ts +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/eval.test.js +433 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/eval.test.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/index.d.ts +18 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/index.js +153 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/index.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/prompt.d.ts +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/prompt.js +168 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/prompt.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindLinesTool.d.ts +19 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindLinesTool.js +65 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindLinesTool.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindServicesTool.d.ts +21 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindServicesTool.js +115 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindServicesTool.js.map +1 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindStationsTool.d.ts +24 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindStationsTool.js +110 -0
- package/dist/llm/functions/extractClaimsFromNewEvidence/tools/FindStationsTool.js.map +1 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/index.d.ts +14 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/index.js +38 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/index.js.map +1 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/prompt.d.ts +1 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/prompt.js +23 -0
- package/dist/llm/functions/generateIssueTitleAndSlug/prompt.js.map +1 -0
- package/dist/llm/functions/translate/index.d.ts +1 -0
- package/dist/llm/functions/translate/index.js +59 -0
- package/dist/llm/functions/translate/index.js.map +1 -0
- package/dist/llm/functions/triageNewEvidence/eval.test.d.ts +1 -0
- package/dist/llm/functions/triageNewEvidence/eval.test.js +139 -0
- package/dist/llm/functions/triageNewEvidence/eval.test.js.map +1 -0
- package/dist/llm/functions/triageNewEvidence/index.d.ts +37 -0
- package/dist/llm/functions/triageNewEvidence/index.js +121 -0
- package/dist/llm/functions/triageNewEvidence/index.js.map +1 -0
- package/dist/llm/functions/triageNewEvidence/prompt.d.ts +1 -0
- package/dist/llm/functions/triageNewEvidence/prompt.js +60 -0
- package/dist/llm/functions/triageNewEvidence/prompt.js.map +1 -0
- package/dist/llm/functions/triageNewEvidence/tools/FindIssuesTool.d.ts +19 -0
- package/dist/llm/functions/triageNewEvidence/tools/FindIssuesTool.js +65 -0
- package/dist/llm/functions/triageNewEvidence/tools/FindIssuesTool.js.map +1 -0
- package/dist/llm/functions/triageNewEvidence/tools/GetIssueTool.d.ts +19 -0
- package/dist/llm/functions/triageNewEvidence/tools/GetIssueTool.js +37 -0
- package/dist/llm/functions/triageNewEvidence/tools/GetIssueTool.js.map +1 -0
- package/dist/scripts/ingestViaWebhook.d.ts +1 -0
- package/dist/scripts/ingestViaWebhook.js +9 -0
- package/dist/scripts/ingestViaWebhook.js.map +1 -0
- package/dist/validators/buildContext.d.ts +7 -0
- package/dist/validators/buildContext.js +164 -0
- package/dist/validators/buildContext.js.map +1 -0
- package/dist/validators/index.d.ts +17 -0
- package/dist/validators/index.js +58 -0
- package/dist/validators/index.js.map +1 -0
- package/dist/validators/issue.d.ts +13 -0
- package/dist/validators/issue.js +220 -0
- package/dist/validators/issue.js.map +1 -0
- package/dist/validators/landmark.d.ts +7 -0
- package/dist/validators/landmark.js +43 -0
- package/dist/validators/landmark.js.map +1 -0
- package/dist/validators/line.d.ts +8 -0
- package/dist/validators/line.js +87 -0
- package/dist/validators/line.js.map +1 -0
- package/dist/validators/operator.d.ts +7 -0
- package/dist/validators/operator.js +43 -0
- package/dist/validators/operator.js.map +1 -0
- package/dist/validators/service.d.ts +8 -0
- package/dist/validators/service.js +87 -0
- package/dist/validators/service.js.map +1 -0
- package/dist/validators/station.d.ts +8 -0
- package/dist/validators/station.js +93 -0
- package/dist/validators/station.js.map +1 -0
- package/dist/validators/town.d.ts +7 -0
- package/dist/validators/town.js +43 -0
- package/dist/validators/town.js.map +1 -0
- package/dist/validators/types.d.ts +19 -0
- package/dist/validators/types.js +2 -0
- package/dist/validators/types.js.map +1 -0
- package/dist/validators/utils.d.ts +2 -0
- package/dist/validators/utils.js +9 -0
- package/dist/validators/utils.js.map +1 -0
- package/package.json +11 -7
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { DIR_STATION } from '../constants.js';
|
|
3
|
+
import { StationSchema } from '../schema/Station.js';
|
|
4
|
+
import { loadJson } from './utils.js';
|
|
5
|
+
export function validateStationSchema(data) {
|
|
6
|
+
const result = StationSchema.safeParse(data);
|
|
7
|
+
if (result.success)
|
|
8
|
+
return [];
|
|
9
|
+
return result.error.issues.map((i) => ({
|
|
10
|
+
file: '',
|
|
11
|
+
message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
export function validateStationRelationships(data, ctx, file) {
|
|
15
|
+
const errors = [];
|
|
16
|
+
if (!ctx.townIds.has(data.townId)) {
|
|
17
|
+
errors.push({
|
|
18
|
+
file,
|
|
19
|
+
message: `townId "${data.townId}" does not exist`,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
for (const landmarkId of data.landmarkIds) {
|
|
23
|
+
if (!ctx.landmarkIds.has(landmarkId)) {
|
|
24
|
+
errors.push({
|
|
25
|
+
file,
|
|
26
|
+
message: `landmarkIds: "${landmarkId}" does not exist`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for (const sc of data.stationCodes) {
|
|
31
|
+
if (!ctx.lineIds.has(sc.lineId)) {
|
|
32
|
+
errors.push({
|
|
33
|
+
file,
|
|
34
|
+
message: `stationCodes[].lineId "${sc.lineId}" does not exist`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return errors;
|
|
39
|
+
}
|
|
40
|
+
export function validateStations(store) {
|
|
41
|
+
const errors = [];
|
|
42
|
+
try {
|
|
43
|
+
const files = store.listDir(DIR_STATION);
|
|
44
|
+
for (const file of files) {
|
|
45
|
+
if (!file.endsWith('.json'))
|
|
46
|
+
continue;
|
|
47
|
+
const relPath = join(DIR_STATION, file);
|
|
48
|
+
const raw = loadJson(store, relPath);
|
|
49
|
+
if (raw === null) {
|
|
50
|
+
errors.push({ file: relPath, message: 'Failed to parse JSON' });
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const schemaErrs = validateStationSchema(raw);
|
|
54
|
+
for (const e of schemaErrs) {
|
|
55
|
+
errors.push({ ...e, file: e.file || relPath });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
if (err.code !== 'ENOENT') {
|
|
61
|
+
errors.push({
|
|
62
|
+
file: DIR_STATION,
|
|
63
|
+
message: err instanceof Error ? err.message : String(err),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return errors;
|
|
68
|
+
}
|
|
69
|
+
export function validateStationsRelationships(store, ctx) {
|
|
70
|
+
if (!ctx)
|
|
71
|
+
return [];
|
|
72
|
+
const errors = [];
|
|
73
|
+
try {
|
|
74
|
+
const files = store.listDir(DIR_STATION);
|
|
75
|
+
for (const file of files) {
|
|
76
|
+
if (!file.endsWith('.json'))
|
|
77
|
+
continue;
|
|
78
|
+
const relPath = join(DIR_STATION, file);
|
|
79
|
+
const raw = loadJson(store, relPath);
|
|
80
|
+
if (raw === null)
|
|
81
|
+
continue;
|
|
82
|
+
const parsed = StationSchema.safeParse(raw);
|
|
83
|
+
if (parsed.success) {
|
|
84
|
+
errors.push(...validateStationRelationships(parsed.data, ctx, relPath));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// ignore
|
|
90
|
+
}
|
|
91
|
+
return errors;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=station.js.map
|
|
@@ -0,0 +1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":["import { join } from 'node:path';\nimport type z from 'zod';\nimport { DIR_STATION } from '../constants.js';\nimport type { IStore } from '../repo/common/store.js';\nimport { StationSchema } from '../schema/Station.js';\nimport type { ValidationContext, ValidationError } from './types.js';\nimport { loadJson } from './utils.js';\n\nexport function validateStationSchema(data: unknown): ValidationError[] {\n const result = StationSchema.safeParse(data);\n if (result.success) return [];\n return result.error.issues.map((i) => ({\n file: '',\n message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,\n }));\n}\n\nexport function validateStationRelationships(\n data: z.infer<typeof StationSchema>,\n ctx: ValidationContext,\n file: string,\n): ValidationError[] {\n const errors: ValidationError[] = [];\n\n if (!ctx.townIds.has(data.townId)) {\n errors.push({\n file,\n message: `townId \"${data.townId}\" does not exist`,\n });\n }\n\n for (const landmarkId of data.landmarkIds) {\n if (!ctx.landmarkIds.has(landmarkId)) {\n errors.push({\n file,\n message: `landmarkIds: \"${landmarkId}\" does not exist`,\n });\n }\n }\n\n for (const sc of data.stationCodes) {\n if (!ctx.lineIds.has(sc.lineId)) {\n errors.push({\n file,\n message: `stationCodes[].lineId \"${sc.lineId}\" does not exist`,\n });\n }\n }\n\n return errors;\n}\n\nexport function validateStations(store: IStore): ValidationError[] {\n const errors: ValidationError[] = [];\n try {\n const files = store.listDir(DIR_STATION);\n for (const file of files) {\n if (!file.endsWith('.json')) continue;\n const relPath = join(DIR_STATION, file);\n const raw = loadJson<unknown>(store, relPath);\n if (raw === null) {\n errors.push({ file: relPath, message: 'Failed to parse JSON' });\n continue;\n }\n const schemaErrs = validateStationSchema(raw);\n for (const e of schemaErrs) {\n errors.push({ ...e, file: e.file || relPath });\n }\n }\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {\n errors.push({\n file: DIR_STATION,\n message: err instanceof Error ? err.message : String(err),\n });\n }\n }\n return errors;\n}\n\nexport function validateStationsRelationships(\n store: IStore,\n ctx?: ValidationContext,\n): ValidationError[] {\n if (!ctx) return [];\n const errors: ValidationError[] = [];\n try {\n const files = store.listDir(DIR_STATION);\n for (const file of files) {\n if (!file.endsWith('.json')) continue;\n const relPath = join(DIR_STATION, file);\n const raw = loadJson<unknown>(store, relPath);\n if (raw === null) continue;\n const parsed = StationSchema.safeParse(raw);\n if (parsed.success) {\n errors.push(...validateStationRelationships(parsed.data, ctx, relPath));\n }\n }\n } catch {\n // ignore\n }\n return errors;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IStore } from '#repo/common/store.js';
|
|
2
|
+
import type { ValidationError } from './types.js';
|
|
3
|
+
export declare function validateTownSchema(data: unknown): {
|
|
4
|
+
file: string;
|
|
5
|
+
message: string;
|
|
6
|
+
}[];
|
|
7
|
+
export declare function validateTowns(store: IStore): ValidationError[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { TownSchema } from '#schema/Town.js';
|
|
3
|
+
import { DIR_TOWN } from '../constants.js';
|
|
4
|
+
import { loadJson } from './utils.js';
|
|
5
|
+
export function validateTownSchema(data) {
|
|
6
|
+
const result = TownSchema.safeParse(data);
|
|
7
|
+
if (result.success)
|
|
8
|
+
return [];
|
|
9
|
+
return result.error.issues.map((i) => ({
|
|
10
|
+
file: '',
|
|
11
|
+
message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
export function validateTowns(store) {
|
|
15
|
+
const errors = [];
|
|
16
|
+
try {
|
|
17
|
+
const files = store.listDir(DIR_TOWN);
|
|
18
|
+
for (const file of files) {
|
|
19
|
+
if (!file.endsWith('.json'))
|
|
20
|
+
continue;
|
|
21
|
+
const relPath = join(DIR_TOWN, file);
|
|
22
|
+
const raw = loadJson(store, relPath);
|
|
23
|
+
if (raw === null) {
|
|
24
|
+
errors.push({ file: relPath, message: 'Failed to parse JSON' });
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const schemaErrs = validateTownSchema(raw);
|
|
28
|
+
for (const e of schemaErrs) {
|
|
29
|
+
errors.push({ ...e, file: e.file || relPath });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (err.code !== 'ENOENT') {
|
|
35
|
+
errors.push({
|
|
36
|
+
file: DIR_TOWN,
|
|
37
|
+
message: err instanceof Error ? err.message : String(err),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return errors;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=town.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"town.js","sourceRoot":"/","sources":["validators/town.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,UAAU,kBAAkB,CAChC,IAAa;IAEb,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACrC,IAAI,EAAE,EAAE;QACR,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,EAAE;KAC1E,CAAC,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;gBAAE,SAAS;YACtC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACrC,MAAM,GAAG,GAAG,QAAQ,CAAU,KAAK,EAAE,OAAO,CAAC,CAAC;YAC9C,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;gBACjB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC,CAAC;gBAChE,SAAS;YACX,CAAC;YACD,MAAM,UAAU,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;YAC3C,KAAK,MAAM,CAAC,IAAI,UAAU,EAAE,CAAC;gBAC3B,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAK,GAA6B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACrD,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aAC1D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { join } from 'node:path';\nimport type { IStore } from '#repo/common/store.js';\nimport { TownSchema } from '#schema/Town.js';\nimport { DIR_TOWN } from '../constants.js';\nimport type { ValidationError } from './types.js';\nimport { loadJson } from './utils.js';\n\nexport function validateTownSchema(\n data: unknown,\n): { file: string; message: string }[] {\n const result = TownSchema.safeParse(data);\n if (result.success) return [];\n return result.error.issues.map((i) => ({\n file: '',\n message: `${i.path.length > 0 ? i.path.join('.') : 'root'}: ${i.message}`,\n }));\n}\n\nexport function validateTowns(store: IStore): ValidationError[] {\n const errors: ValidationError[] = [];\n try {\n const files = store.listDir(DIR_TOWN);\n for (const file of files) {\n if (!file.endsWith('.json')) continue;\n const relPath = join(DIR_TOWN, file);\n const raw = loadJson<unknown>(store, relPath);\n if (raw === null) {\n errors.push({ file: relPath, message: 'Failed to parse JSON' });\n continue;\n }\n const schemaErrs = validateTownSchema(raw);\n for (const e of schemaErrs) {\n errors.push({ ...e, file: e.file || relPath });\n }\n }\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {\n errors.push({\n file: DIR_TOWN,\n message: err instanceof Error ? err.message : String(err),\n });\n }\n }\n return errors;\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ValidationError {
|
|
2
|
+
file: string;
|
|
3
|
+
line?: number;
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Set of entity IDs loaded from data. Used for relationship validation.
|
|
8
|
+
* When omitted, validators run schema validation only (no relationship checks).
|
|
9
|
+
*/
|
|
10
|
+
export interface ValidationContext {
|
|
11
|
+
townIds: Set<string>;
|
|
12
|
+
landmarkIds: Set<string>;
|
|
13
|
+
operatorIds: Set<string>;
|
|
14
|
+
lineIds: Set<string>;
|
|
15
|
+
serviceIds: Set<string>;
|
|
16
|
+
stationIds: Set<string>;
|
|
17
|
+
/** evidence IDs per issue path (e.g. "issue/2025/03/2025-03-11-x") */
|
|
18
|
+
evidenceIdsByIssue: Map<string, Set<string>>;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["validators/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface ValidationError {\n file: string;\n line?: number;\n message: string;\n}\n\n/**\n * Set of entity IDs loaded from data. Used for relationship validation.\n * When omitted, validators run schema validation only (no relationship checks).\n */\nexport interface ValidationContext {\n townIds: Set<string>;\n landmarkIds: Set<string>;\n operatorIds: Set<string>;\n lineIds: Set<string>;\n serviceIds: Set<string>;\n stationIds: Set<string>;\n /** evidence IDs per issue path (e.g. \"issue/2025/03/2025-03-11-x\") */\n evidenceIdsByIssue: Map<string, Set<string>>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"/","sources":["validators/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAI,KAAa,EAAE,IAAY;IACrD,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,QAAQ,CAAI,IAAI,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { IStore } from '../repo/common/store.js';\n\nexport function loadJson<T>(store: IStore, path: string): T | null {\n try {\n return store.readJson<T>(path);\n } catch {\n return null;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrtdown/core",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.4",
|
|
4
4
|
"description": "Data repository",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,12 +29,7 @@
|
|
|
29
29
|
"vitest-evals": "^0.5.0"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
|
-
"dist"
|
|
33
|
-
"!dist/cli",
|
|
34
|
-
"!dist/legacy",
|
|
35
|
-
"!dist/llm",
|
|
36
|
-
"!dist/scripts",
|
|
37
|
-
"!dist/validators"
|
|
32
|
+
"dist"
|
|
38
33
|
],
|
|
39
34
|
"exports": {
|
|
40
35
|
".": {
|
|
@@ -63,5 +58,14 @@
|
|
|
63
58
|
},
|
|
64
59
|
"publishConfig": {
|
|
65
60
|
"access": "public"
|
|
61
|
+
},
|
|
62
|
+
"imports": {
|
|
63
|
+
"#repo/*": "./src/repo/*",
|
|
64
|
+
"#schema/*": "./src/schema/*",
|
|
65
|
+
"#write/*": "./src/write/*",
|
|
66
|
+
"#helpers/*": "./src/helpers/*",
|
|
67
|
+
"#util/*": "./src/util/*",
|
|
68
|
+
"#validators/*": "./src/validators/*",
|
|
69
|
+
"#llm/*": "./src/llm/*"
|
|
66
70
|
}
|
|
67
71
|
}
|