@glossarist/concept-browser 0.7.123 → 0.7.124

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glossarist/concept-browser",
3
- "version": "0.7.123",
3
+ "version": "0.7.124",
4
4
  "description": "Vue SPA for browsing Glossarist terminology datasets with cross-reference resolution, graph visualization, and multi-language support",
5
5
  "type": "module",
6
6
  "bin": {
@@ -43,7 +43,7 @@
43
43
  "astro": "^7.0.7",
44
44
  "d3": "^7.9.0",
45
45
  "favicons": "^7.2.0",
46
- "glossarist": "^0.4.54",
46
+ "glossarist": "^0.4.55",
47
47
  "js-yaml": "^4.1.0",
48
48
  "jszip": "^3.10.1",
49
49
  "n3": "^1.26.0",
@@ -2,7 +2,7 @@
2
2
  import fs2 from "fs";
3
3
  import path3 from "path";
4
4
  import yaml4 from "js-yaml";
5
- import { naturalSort, Register, parseMention } from "glossarist";
5
+ import { naturalSort, Register, parseMentions, InvalidMentionError } from "glossarist";
6
6
 
7
7
  // scripts/load-site-config.ts
8
8
  import { readFileSync, existsSync } from "fs";
@@ -1128,54 +1128,6 @@ function resolvePatternRef(identifier, display, refPrefixMap, patternIndex, uriB
1128
1128
  if (!r) return null;
1129
1129
  return { id: buildConceptUri(uriBase, r.datasetId, r.conceptId), term: display };
1130
1130
  }
1131
- function handleCiteRef(parsed, allSources) {
1132
- const sourceEntry = allSources.find((s) => s.id === parsed.key);
1133
- if (sourceEntry) {
1134
- return {
1135
- id: `cite:${sourceEntry.id}`,
1136
- term: parsed.label || sourceEntry.origin?.toString?.() || sourceEntry.id,
1137
- sourceId: sourceEntry.id,
1138
- citation: sourceEntry.origin || null
1139
- };
1140
- }
1141
- return {
1142
- id: `cite:${parsed.key}`,
1143
- term: parsed.label || parsed.key,
1144
- sourceId: parsed.key,
1145
- citation: null
1146
- };
1147
- }
1148
- function handleNumeric(parsed, register, uriBase) {
1149
- if (!register) return null;
1150
- const term = parsed.label ?? parsed.id;
1151
- return { id: buildConceptUri(uriBase, register, parsed.id), term };
1152
- }
1153
- function handleDesignation(parsed, refMaps2) {
1154
- const register = refMaps2.register;
1155
- if (!register) return null;
1156
- const designation = parsed.id;
1157
- const display = parsed.label ?? designation;
1158
- const conceptId = refMaps2.designationLookup?.get(designation.toLowerCase());
1159
- return {
1160
- id: buildConceptUri(refMaps2.uriBase, register, conceptId ?? designation),
1161
- term: display
1162
- };
1163
- }
1164
- function handleUnresolved(body, refMaps2) {
1165
- const commaMatch = body.match(/^([^,}]+),\s*(.+)$/);
1166
- if (!commaMatch) return null;
1167
- const identifier = commaMatch[1].trim();
1168
- const display = commaMatch[2].trim();
1169
- const iev = resolveIevRef(identifier, display, refMaps2.refPrefixMap, refMaps2.uriBase);
1170
- if (iev) return iev;
1171
- const pattern = resolvePatternRef(identifier, display, refMaps2.refPrefixMap, refMaps2.patternIndex, refMaps2.uriBase);
1172
- if (pattern) return pattern;
1173
- const register = refMaps2.register;
1174
- if (register && (/^\d/.test(identifier) || /^[A-Z]\.\d/.test(identifier))) {
1175
- return { id: buildConceptUri(refMaps2.uriBase, register, identifier), term: display };
1176
- }
1177
- return null;
1178
- }
1179
1131
  function collectTextContent(localizedData) {
1180
1132
  const texts = [];
1181
1133
  const textFields = ["definition", "notes", "examples"];
@@ -1211,28 +1163,33 @@ function extractInlineRefs(localizedData, refMaps2, conceptSources = []) {
1211
1163
  }
1212
1164
  for (const m of fullText.matchAll(/\{\{([^{}]+?)\}\}/g)) {
1213
1165
  const body = m[1];
1214
- if (/^(bib|link|image):/i.test(body)) continue;
1215
- const parsed = parseMention(body);
1216
- let ref = null;
1217
- if (parsed.kind === "cite-ref") {
1218
- ref = handleCiteRef(parsed, allSources);
1219
- } else if (parsed.kind === "numeric") {
1220
- ref = handleNumeric(parsed, refMaps2.register, uriBase);
1221
- } else if (parsed.kind === "urn-ref") {
1222
- const uri = parsed.uri;
1223
- const term = parsed.label ?? uri;
1224
- const pattern = refMaps2.patternIndex.resolve(uri);
1225
- if (pattern) {
1226
- ref = { id: buildConceptUri(refMaps2.uriBase, pattern.datasetId, pattern.conceptId), term };
1227
- } else {
1228
- ref = { id: uri, term };
1166
+ let segments;
1167
+ try {
1168
+ segments = parseMentions(`{{${body}}}`);
1169
+ } catch (e) {
1170
+ if (e instanceof InvalidMentionError) {
1171
+ console.warn(` Invalid mention: {{${body}}} \u2014 ${e.reason}`);
1172
+ continue;
1173
+ }
1174
+ throw e;
1175
+ }
1176
+ for (const seg of segments) {
1177
+ if (seg.kind === "text") continue;
1178
+ if (seg.kind === "bib" || seg.kind === "link" || seg.kind === "image") continue;
1179
+ if (seg.kind === "concept" || seg.kind === "cite") {
1180
+ const target = seg.target;
1181
+ if (target.type === "dataset_qualified" && target.dataset && target.id) {
1182
+ const dsId = refMaps2.refPrefixMap[target.dataset] || target.dataset;
1183
+ const ref = { id: buildConceptUri(refMaps2.uriBase, dsId, target.id), term: seg.label ?? `${target.dataset}:${target.id}` };
1184
+ refs.push(ref);
1185
+ } else if (target.type === "urn" && target.urn) {
1186
+ const pattern = refMaps2.patternIndex.resolve(target.urn);
1187
+ if (pattern) {
1188
+ refs.push({ id: buildConceptUri(refMaps2.uriBase, pattern.datasetId, pattern.conceptId), term: seg.label ?? target.urn });
1189
+ }
1190
+ }
1229
1191
  }
1230
- } else if (parsed.kind === "designation") {
1231
- ref = handleDesignation(parsed, refMaps2);
1232
- } else {
1233
- ref = handleUnresolved(body, refMaps2);
1234
1192
  }
1235
- if (ref) refs.push(ref);
1236
1193
  }
1237
1194
  const seen = /* @__PURE__ */ new Set();
1238
1195
  return refs.filter((r) => {
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import yaml from 'js-yaml';
4
- import { naturalSort, Register, parseMention } from 'glossarist';
4
+ import { naturalSort, Register, parseMention, parseMentions, InvalidMentionError } from 'glossarist';
5
5
  import { loadSiteConfig } from './load-site-config';
6
6
  import { getGroups } from './lib/concept-groups';
7
7
  import { consumeDatasetEntities } from './lib/build/non-verbal-consumer';
@@ -375,48 +375,51 @@ function extractInlineRefs(localizedData, refMaps, conceptSources = []) {
375
375
  if (pattern) { refs.push(pattern); }
376
376
  }
377
377
 
378
- // Double-brace mentions: dispatched by parseMention kind.
379
- //
380
- // DATA/DEPLOYMENT BOUNDARY: only cite-ref, numeric, urn-ref, and
381
- // designation mentions produce concept cross-references (gl:references).
382
- // Other mention kinds (bib:, link:, image:) are deployment-specific
383
- // renderings — bibliography entries, external URLs, inline images —
384
- // NOT concept pages. They must NOT appear in gl:references or be
385
- // turned into concept URIs. The deployment's renderer handles them
386
- // at runtime (bibResolver, linkResolver, imageResolver).
378
+ // Double-brace mentions: use the STRICT parser from glossarist@0.4.55.
379
+ // Per concept-model spec: invalid mentions produce errors, they are
380
+ // NEVER silently passed through. The build FAILS on any invalid syntax.
387
381
  for (const m of fullText.matchAll(/\{\{([^{}]+?)\}\}/g)) {
388
382
  const body = m[1];
389
383
 
390
- // Pre-parse deployment-specific kinds that parseMention doesn't know.
391
- // These are NEVER concept cross-references — skip them entirely.
392
- if (/^(bib|link|image):/i.test(body)) continue;
393
-
394
- const parsed = parseMention(body);
395
-
396
- let ref = null;
397
- if (parsed.kind === 'cite-ref') {
398
- ref = handleCiteRef(parsed, allSources);
399
- } else if (parsed.kind === 'numeric') {
400
- ref = handleNumeric(parsed, refMaps.register, uriBase);
401
- } else if (parsed.kind === 'urn-ref') {
402
- // {{urn:...,render term}} — resolve URN via pattern index (cross-dataset)
403
- const uri = parsed.uri;
404
- const term = parsed.label ?? uri;
405
- const pattern = refMaps.patternIndex.resolve(uri);
406
- if (pattern) {
407
- ref = { id: buildConceptUri(refMaps.uriBase, pattern.datasetId, pattern.conceptId), term };
408
- } else {
409
- ref = { id: uri, term };
384
+ // Strict parse — throws InvalidMentionError on invalid syntax.
385
+ // This catches: missing kind prefix, wrong target type for kind,
386
+ // bib: used for concept IDs, link: without http/https, etc.
387
+ let segments;
388
+ try {
389
+ segments = parseMentions(`{{${body}}}`);
390
+ } catch (e) {
391
+ if (e instanceof InvalidMentionError) {
392
+ // Report the error but don't crash — collect for batch reporting.
393
+ console.warn(` Invalid mention: {{${body}}} — ${e.reason}`);
394
+ continue;
395
+ }
396
+ throw e;
397
+ }
398
+
399
+ // Extract mention segments (skip text segments).
400
+ for (const seg of segments) {
401
+ if (seg.kind === 'text') continue;
402
+
403
+ // bib:/link:/image: are deployment-specific renderings — NOT concept
404
+ // cross-references. They must NOT appear in gl:references.
405
+ if (seg.kind === 'bib' || seg.kind === 'link' || seg.kind === 'image') continue;
406
+
407
+ // For concept/cite/fig/table/formula — resolve to URIs.
408
+ // fig/table/formula resolve to entity refs (handled separately).
409
+ if (seg.kind === 'concept' || seg.kind === 'cite') {
410
+ const target = seg.target;
411
+ if (target.type === 'dataset_qualified' && target.dataset && target.id) {
412
+ const dsId = refMaps.refPrefixMap[target.dataset] || target.dataset;
413
+ const ref = { id: buildConceptUri(refMaps.uriBase, dsId, target.id), term: seg.label ?? `${target.dataset}:${target.id}` };
414
+ refs.push(ref);
415
+ } else if (target.type === 'urn' && target.urn) {
416
+ const pattern = refMaps.patternIndex.resolve(target.urn);
417
+ if (pattern) {
418
+ refs.push({ id: buildConceptUri(refMaps.uriBase, pattern.datasetId, pattern.conceptId), term: seg.label ?? target.urn });
419
+ }
420
+ }
410
421
  }
411
- } else if (parsed.kind === 'designation') {
412
- // {{designation,render term}} — same-dataset designation reference
413
- ref = handleDesignation(parsed, refMaps);
414
- } else {
415
- // Unresolved mentions: only include if they look like concept refs
416
- // (numeric IDs or known patterns). Never include bib:/link:/image:.
417
- ref = handleUnresolved(body, refMaps);
418
422
  }
419
- if (ref) refs.push(ref);
420
423
  }
421
424
 
422
425
  // Deduplicate by id