glossarist 0.3.6 → 0.3.7

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",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "JavaScript SDK for Glossarist GCR packages — read, write, validate, and manage terminology concepts",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/index.d.ts CHANGED
@@ -35,8 +35,9 @@ export { conceptUuid, localizedConceptUuid, uuidV5 } from './uuid';
35
35
  export { ReferenceResolver, Reference, referenceResolver } from './reference-resolver';
36
36
 
37
37
  export type MentionParseResult = {
38
- kind: 'cite-ref' | 'numeric' | 'designation' | 'unresolved';
38
+ kind: 'cite-ref' | 'urn-ref' | 'numeric' | 'designation' | 'unresolved';
39
39
  key?: string;
40
+ uri?: string;
40
41
  label?: string | null;
41
42
  id?: string;
42
43
  raw: string;
@@ -7,15 +7,20 @@
7
7
  * Convention: the ID always comes first, the display (render) text
8
8
  * always comes last. Every comma-separated form follows this:
9
9
  *
10
- * {{id}} bare ID
11
- * {{id, display text}} ID + display text
12
10
  * {{cite:key}} cite-key (source id)
13
- * {{cite:key, display text}} cite-key + display text
11
+ * {{cite:key, render term}} cite-key + render term
12
+ * {{urn:...}} URN reference
13
+ * {{urn:..., render term}} URN + render term
14
+ * {{numeric_id}} local concept ID
15
+ * {{numeric_id, render term}} local concept ID + render term
16
+ * {{designation}} designation matching
17
+ * {{designation, render term}} designation + render term
14
18
  *
15
19
  * @typedef {Object} MentionParseResult
16
- * @property {'cite-ref' | 'numeric' | 'designation' | 'unresolved'} kind
20
+ * @property {'cite-ref' | 'urn-ref' | 'numeric' | 'designation' | 'unresolved'} kind
17
21
  * @property {string} [key] — for 'cite-ref': the local key
18
- * @property {string} [label] display text (always last)
22
+ * @property {string} [uri] for 'urn-ref': the URN
23
+ * @property {string} [label] — render text (always last)
19
24
  * @property {string} [id] — for 'numeric' / 'designation': the id
20
25
  * @property {string} raw — the original mention body
21
26
  */
@@ -34,8 +39,7 @@ const NUMERIC_RE = /^\d+(?:[.-]\d+)+$/;
34
39
  export function parseMention(raw) {
35
40
  const body = raw.trim();
36
41
 
37
- // 1. cite:<key>[,display] — explicit citation reference.
38
- // Key is the source id; display text is optional.
42
+ // 1. cite:<key>[,render] — explicit citation reference.
39
43
  const citeMatch = body.match(/^cite:([^,}]+)(?:,(.*))?$/);
40
44
  if (citeMatch) {
41
45
  const label = citeMatch[2] !== undefined ? unquoteLabel(citeMatch[2].trim()) : null;
@@ -47,8 +51,20 @@ export function parseMention(raw) {
47
51
  };
48
52
  }
49
53
 
50
- // 2. Comma-separated form: {{id, display}}.
51
- // ID always comes first, display text always comes last.
54
+ // 2. urn:...[,render] URN reference.
55
+ const urnMatch = body.match(/^(urn:[^,}]+)(?:,(.*))?$/);
56
+ if (urnMatch) {
57
+ const label = urnMatch[2] !== undefined ? unquoteLabel(urnMatch[2].trim()) : null;
58
+ return {
59
+ kind: 'urn-ref',
60
+ uri: urnMatch[1].trim(),
61
+ label,
62
+ raw: body,
63
+ };
64
+ }
65
+
66
+ // 3. Comma-separated form: {{id, render}}.
67
+ // ID always comes first, render text always comes last.
52
68
  const commaIdx = body.indexOf(',');
53
69
  if (commaIdx !== -1) {
54
70
  const id = body.slice(0, commaIdx).trim();
@@ -60,12 +76,12 @@ export function parseMention(raw) {
60
76
  return { kind: 'designation', id, label, raw: body };
61
77
  }
62
78
 
63
- // 3. Bare numeric id.
79
+ // 4. Bare numeric id.
64
80
  if (NUMERIC_RE.test(body)) {
65
81
  return { kind: 'numeric', id: body, label: null, raw: body };
66
82
  }
67
83
 
68
- // 4. Anything else is unresolved at the parse layer.
84
+ // 5. Anything else is unresolved at the parse layer.
69
85
  return { kind: 'unresolved', raw: body };
70
86
  }
71
87
 
@@ -150,6 +150,12 @@ export class ReferenceResolver {
150
150
  case 'cite-ref':
151
151
  refs.push(this._resolveCiteRef(parsed, source, concept));
152
152
  break;
153
+ case 'urn-ref':
154
+ refs.push(new Reference('concept', parsed.label ?? parsed.uri, 'embedded', source, {
155
+ uri: parsed.uri,
156
+ resolution: null,
157
+ }));
158
+ break;
153
159
  case 'numeric':
154
160
  refs.push(new Reference('concept', parsed.label ?? parsed.id, 'embedded', source, {
155
161
  lookupKey: { id: parsed.id },