Skip to content

Commit f8158fd

Browse files
committed
Revert "chore(build): Ignore dist directory and untrack files"
This reverts commit fd62904.
1 parent fd62904 commit f8158fd

20 files changed

+6356
-2
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
# production
1212
/build
13-
/dist
1413

1514
# misc
1615
.DS_Store
@@ -46,4 +45,4 @@ example/data/organisms.csv
4645
example/data/resistance_ars_2023_germany_all.csv
4746
example/data/resistance_ars_2023_germany_icu.csvexample/data/
4847
example/data/organism_groups.csv
49-
example/data/resistance_ars_2023_germany_icu.csv
48+
example/data/resistance_ars_2023_germany_icu.csv

dist/chunk-M23YCPVN.mjs

Lines changed: 363 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,363 @@
1+
var __create = Object.create;
2+
var __defProp = Object.defineProperty;
3+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4+
var __getOwnPropNames = Object.getOwnPropertyNames;
5+
var __getProtoOf = Object.getPrototypeOf;
6+
var __hasOwnProp = Object.prototype.hasOwnProperty;
7+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9+
}) : x)(function(x) {
10+
if (typeof require !== "undefined") return require.apply(this, arguments);
11+
throw Error('Dynamic require of "' + x + '" is not supported');
12+
});
13+
var __commonJS = (cb, mod) => function __require2() {
14+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15+
};
16+
var __copyProps = (to, from, except, desc) => {
17+
if (from && typeof from === "object" || typeof from === "function") {
18+
for (let key of __getOwnPropNames(from))
19+
if (!__hasOwnProp.call(to, key) && key !== except)
20+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21+
}
22+
return to;
23+
};
24+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25+
// If the importer is in node compatibility mode or this is not an ESM
26+
// file that has been converted to a CommonJS file using a Babel-
27+
// compatible transform (i.e. "__esModule" has not been set), then set
28+
// "default" to the CommonJS "module.exports" for node compatibility.
29+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30+
mod
31+
));
32+
33+
// src/data/index.ts
34+
import { readFile } from "fs/promises";
35+
import { join } from "path";
36+
import { parse } from "csv-parse/sync";
37+
var CSV = (txt) => parse(txt, {
38+
columns: true,
39+
skip_empty_lines: true,
40+
trim: true,
41+
bom: true,
42+
cast: (value, context) => {
43+
if (context.header) return value;
44+
if (["resistance_pct", "n_isolates"].includes(context.column)) {
45+
const num = parseFloat(value);
46+
return isNaN(num) ? null : num;
47+
}
48+
return value;
49+
}
50+
});
51+
var csvCache = /* @__PURE__ */ new Map();
52+
var loadCsv = (dir, file) => {
53+
const path = join(dir, file);
54+
if (!csvCache.has(path)) {
55+
const promise = readFile(path, "utf8").then(CSV).catch((err) => {
56+
console.error(`Error loading CSV file: ${file} in ${dir}`, err);
57+
return [];
58+
});
59+
csvCache.set(path, promise);
60+
}
61+
return csvCache.get(path);
62+
};
63+
var sharedDataPromise = null;
64+
var collectSynonyms = (row) => {
65+
const synonyms = /* @__PURE__ */ new Set();
66+
const add = (s) => {
67+
if (!s) return;
68+
s.split(/[;,]/).forEach((part) => {
69+
const trimmed = part.trim();
70+
if (trimmed) {
71+
synonyms.add(trimmed);
72+
const noDots = trimmed.replace(/\./g, "");
73+
if (noDots !== trimmed) synonyms.add(noDots);
74+
}
75+
});
76+
};
77+
add(row.amr_code || row.id);
78+
for (const key in row) {
79+
if (key.startsWith("synonyms_") || key.startsWith("full_name_") || key.startsWith("short_name_") || key.startsWith("name_")) {
80+
add(row[key]);
81+
}
82+
}
83+
return Array.from(synonyms);
84+
};
85+
function getSharedData(dir, files) {
86+
if (!sharedDataPromise) {
87+
sharedDataPromise = Promise.all([
88+
loadCsv(dir, files.antibiotics),
89+
loadCsv(dir, files.organisms),
90+
loadCsv(dir, files.sources),
91+
loadCsv(dir, files.abxClasses),
92+
loadCsv(dir, files.orgClasses)
93+
]).then(([abx, org, rawSources, abxClasses, orgClasses]) => {
94+
const sources = rawSources.map((s) => ({
95+
...s,
96+
url: s.source_url
97+
}));
98+
const abxSyn2Id = mkSynMap(abx);
99+
const orgSyn2Id = mkSynMap(org);
100+
const orgClassesById = new Map(orgClasses.map((c) => [c.id, c]));
101+
const orgClassChildren = /* @__PURE__ */ new Map();
102+
for (const c of orgClasses) {
103+
const parentId = c.parent_id || "";
104+
if (!orgClassChildren.has(parentId)) {
105+
orgClassChildren.set(parentId, []);
106+
}
107+
orgClassChildren.get(parentId).push(c);
108+
}
109+
const classIdToRank = /* @__PURE__ */ new Map();
110+
const traverse = (parentId, prefix) => {
111+
const children = orgClassChildren.get(parentId) ?? [];
112+
children.sort((a, b) => orgClasses.indexOf(a) - orgClasses.indexOf(b));
113+
children.forEach((child, index) => {
114+
const rank = prefix ? `${prefix}.${(index + 1).toString().padStart(2, "0")}` : (index + 1).toString().padStart(2, "0");
115+
classIdToRank.set(child.id, rank);
116+
traverse(child.id, rank);
117+
});
118+
};
119+
traverse("", "");
120+
const orgIdToRank = /* @__PURE__ */ new Map();
121+
for (const organism of org) {
122+
const rank = classIdToRank.get(organism.class_id) || "99";
123+
orgIdToRank.set(organism.amr_code, rank);
124+
}
125+
const synonymToAllMembers = /* @__PURE__ */ new Map();
126+
for (const abxClass of abxClasses) {
127+
const classId = abxClass.id;
128+
const members = abx.filter((a) => a.class === classId).map((a) => a.amr_code);
129+
if (members.length > 0) {
130+
const synonyms = collectSynonyms(abxClass);
131+
for (const syn of synonyms) {
132+
if (!synonymToAllMembers.has(syn)) {
133+
synonymToAllMembers.set(syn, []);
134+
}
135+
synonymToAllMembers.get(syn).push(...members);
136+
}
137+
}
138+
}
139+
for (const [syn, members] of synonymToAllMembers.entries()) {
140+
const existingIds = abxSyn2Id.has(syn) ? abxSyn2Id.get(syn).split(",") : [];
141+
const allIds = [.../* @__PURE__ */ new Set([...existingIds, ...members])];
142+
abxSyn2Id.set(syn, allIds.join(","));
143+
}
144+
const classToAllDescendantOrgs = /* @__PURE__ */ new Map();
145+
const getDescendantOrgs = (classId) => {
146+
if (classToAllDescendantOrgs.has(classId)) return classToAllDescendantOrgs.get(classId);
147+
const directOrgs = org.filter((o) => o.class_id === classId).map((o) => o.amr_code);
148+
const childClasses = orgClassChildren.get(classId) ?? [];
149+
const descendantOrgs = childClasses.flatMap((child) => getDescendantOrgs(child.id));
150+
const allOrgs = [.../* @__PURE__ */ new Set([...directOrgs, ...descendantOrgs])];
151+
classToAllDescendantOrgs.set(classId, allOrgs);
152+
return allOrgs;
153+
};
154+
for (const classId of orgClassesById.keys()) {
155+
getDescendantOrgs(classId);
156+
}
157+
for (const orgClass of orgClasses) {
158+
const members = classToAllDescendantOrgs.get(orgClass.id);
159+
if (members && members.length > 0) {
160+
const synonyms = collectSynonyms(orgClass);
161+
for (const syn of synonyms) {
162+
orgSyn2Id.set(syn, members.join(","));
163+
}
164+
}
165+
}
166+
const allAbxIds = abx.filter((r) => r.class).map((r) => r.amr_code);
167+
const allOrgIds = org.filter((r) => r.class_id).map((r) => r.amr_code);
168+
const sourcesById = new Map(
169+
sources.map((s) => [s.id, { ...s, children: [] }])
170+
);
171+
const hierarchicalSources = [];
172+
for (const source of sourcesById.values()) {
173+
if (source.parent_id && sourcesById.has(source.parent_id)) {
174+
const parent = sourcesById.get(source.parent_id);
175+
parent.children.push(source);
176+
} else {
177+
hierarchicalSources.push(source);
178+
}
179+
}
180+
return {
181+
abx,
182+
org,
183+
sources,
184+
hierarchicalSources,
185+
abxSyn2Id,
186+
orgSyn2Id,
187+
allAbxIds,
188+
allOrgIds,
189+
orgClasses,
190+
orgIdToRank: Object.fromEntries(orgIdToRank)
191+
};
192+
});
193+
}
194+
return sharedDataPromise;
195+
}
196+
var getPathToSource = (sources, targetId) => {
197+
const sourcesById = new Map(sources.map((s) => [s.id, s]));
198+
const path = [];
199+
let currentId = targetId;
200+
while (currentId && sourcesById.has(currentId)) {
201+
const source = sourcesById.get(currentId);
202+
path.unshift(source);
203+
currentId = source.parent_id;
204+
}
205+
return path;
206+
};
207+
var loadResistanceDataForSource = async (source, allSources, dataDir) => {
208+
const path = getPathToSource(allSources, source.id);
209+
if (path.length === 0) return [];
210+
const csvDataFrames = await Promise.all(
211+
path.map((s) => loadCsv(dataDir, s.source_file))
212+
);
213+
const allDataFrames = csvDataFrames.map(
214+
(rows, idx) => rows.map((row) => ({ ...row, source_id: path[idx].id }))
215+
);
216+
const mergedData = /* @__PURE__ */ new Map();
217+
for (const df of allDataFrames) {
218+
for (const row of df) {
219+
const key = `${row.antibiotic_id}-${row.organism_id}`;
220+
mergedData.set(key, row);
221+
}
222+
}
223+
return Array.from(mergedData.values());
224+
};
225+
var stripMarkdownLight = (s) => s.replace(/`{1,3}[\s\S]*?`{1,3}/g, " ").replace(/!\\\[[^\\]*\]\([^)]*\)/g, " ").replace(/\\[^\\]+\]\([^)]*\)/g, "$1").replace(/[*_~#>\/.,]+/g, " ").replace(/\s+/g, " ").trim();
226+
var makeTokenRegex = (synRaw) => {
227+
const syn = synRaw.trim();
228+
if (!syn) return null;
229+
let core = syn.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\./g, "\\.?").replace(/\s+/g, "\\s+");
230+
const W = "\\p{L}\\p{N}";
231+
const pattern = `(?<![${W}])${core}(?![${W}])`;
232+
try {
233+
return new RegExp(pattern, "iu");
234+
} catch {
235+
return new RegExp(`(^|[^${W}])(${core})(?=$|[^${W}])`, "iu");
236+
}
237+
};
238+
var selectDataSource = (src, sources) => {
239+
const getParentCount = (source, allSources) => {
240+
let count = 0;
241+
let current = source;
242+
const sourceMap = new Map(allSources.map((s) => [s.id, s]));
243+
while (current.parent_id && sourceMap.has(current.parent_id)) {
244+
count++;
245+
current = sourceMap.get(current.parent_id);
246+
}
247+
return count;
248+
};
249+
const sort = (sourcesToSort, priority) => {
250+
return sourcesToSort.sort((a, b) => {
251+
const parentCountA = getParentCount(a, sources);
252+
const parentCountB = getParentCount(b, sources);
253+
const yearA = a.year;
254+
const yearB = b.year;
255+
if (priority === "parents") {
256+
if (parentCountA !== parentCountB) return parentCountB - parentCountA;
257+
if (yearA !== yearB) return yearB - yearA;
258+
} else {
259+
if (yearA !== yearB) return yearB - yearA;
260+
if (parentCountA !== parentCountB) return parentCountB - parentCountA;
261+
}
262+
return sources.indexOf(a) - sources.indexOf(b);
263+
});
264+
};
265+
if (!src) {
266+
return sort([...sources], "year")[0];
267+
}
268+
const filteredSources = sources.filter(
269+
(s) => s.id.toLowerCase().includes(src.toLowerCase()) || s.name_de.toLowerCase().includes(src.toLowerCase()) || s.year.toString().includes(src)
270+
);
271+
if (filteredSources.length === 0) {
272+
return sort([...sources], "year")[0];
273+
}
274+
return sort(filteredSources, "parents")[0];
275+
};
276+
var mkSynMap = (rows) => rows.reduce((m, r) => {
277+
const id = r.amr_code || r.id;
278+
if (!id) return m;
279+
const synonyms = collectSynonyms(r);
280+
for (const syn of synonyms) {
281+
m.set(syn, id);
282+
}
283+
return m;
284+
}, /* @__PURE__ */ new Map());
285+
var getLowerCaseSynMap = /* @__PURE__ */ (() => {
286+
let cache = null;
287+
let originalMap = null;
288+
return (synMap) => {
289+
if (cache && originalMap === synMap) {
290+
return cache;
291+
}
292+
const lowerCaseMap = /* @__PURE__ */ new Map();
293+
synMap.forEach((value, key) => {
294+
lowerCaseMap.set(key.toLowerCase(), value);
295+
});
296+
cache = lowerCaseMap;
297+
originalMap = synMap;
298+
return lowerCaseMap;
299+
};
300+
})();
301+
var resolveIds = (param, allIds, synMap, pageText) => {
302+
if (!param) return { resolved: [], unresolved: [] };
303+
const resolved = /* @__PURE__ */ new Set();
304+
const requestedTokens = param.split(",").map((t) => t.trim()).filter(Boolean);
305+
const lowerCaseSynMap = getLowerCaseSynMap(synMap);
306+
for (const token of requestedTokens) {
307+
if (token === "auto") {
308+
const text = stripMarkdownLight(pageText);
309+
for (const [syn, idOrIds] of synMap.entries()) {
310+
const strippedSyn = stripMarkdownLight(syn);
311+
const rx = makeTokenRegex(strippedSyn);
312+
if (!rx) continue;
313+
if (rx.test(text)) {
314+
idOrIds.split(",").forEach((id) => resolved.add(id));
315+
} else {
316+
const synNoDots = syn.replace(/\./g, "");
317+
if (synNoDots !== syn) {
318+
const strippedSynNoDots = stripMarkdownLight(synNoDots);
319+
const rx2 = makeTokenRegex(strippedSynNoDots);
320+
if (rx2 && rx2.test(text)) {
321+
idOrIds.split(",").forEach((id) => resolved.add(id));
322+
}
323+
}
324+
}
325+
}
326+
} else if (token === "all") {
327+
allIds.forEach((id) => resolved.add(id));
328+
} else {
329+
const lowerToken = token.toLowerCase();
330+
const idOrIds = lowerCaseSynMap.get(lowerToken) ?? token.toUpperCase();
331+
idOrIds.split(",").forEach((id) => {
332+
if (allIds.includes(id)) {
333+
resolved.add(id);
334+
}
335+
});
336+
}
337+
}
338+
if (resolved.size === 0) {
339+
const unresolved2 = requestedTokens.filter((t) => t !== "all" && t !== "auto");
340+
if (unresolved2.length === 0 && requestedTokens.includes("auto")) {
341+
unresolved2.push("auto");
342+
}
343+
return { resolved: [], unresolved: unresolved2 };
344+
}
345+
const finalResolved = Array.from(resolved);
346+
const unresolved = requestedTokens.filter((token) => {
347+
if (token === "auto" || token === "all") return false;
348+
const lowerToken = token.toLowerCase();
349+
const idOrIds = lowerCaseSynMap.get(lowerToken) ?? token.toUpperCase();
350+
return !idOrIds.split(",").some((id) => finalResolved.includes(id));
351+
});
352+
return { resolved: finalResolved, unresolved };
353+
};
354+
355+
export {
356+
__require,
357+
__commonJS,
358+
__toESM,
359+
getSharedData,
360+
loadResistanceDataForSource,
361+
selectDataSource,
362+
resolveIds
363+
};

0 commit comments

Comments
 (0)