@pubid/pubid 0.1.24 → 0.1.25

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.
Binary file
@@ -506,12 +506,25 @@ function parseIsoUrn(urn) {
506
506
  else
507
507
  supp.number = parts.shift();
508
508
  }
509
- if ((parts[0] ?? "").startsWith("v")) {
510
- const version = parts.shift().slice(1);
511
- supp.number = version.split(".")[0];
512
- }
509
+ // The legacy year-overloaded wire ("amd:2007:v2" -- the number rode
510
+ // the version slot): a v-token with no preceding number carries the
511
+ // NUMBER. The RFC 5141-bis order ("amd:1:2007:v2") keeps the number
512
+ // in its own slot, so a v-token after a number is the true
513
+ // <supplversion>.
514
+ const consumeV = () => {
515
+ if ((parts[0] ?? "").startsWith("v")) {
516
+ const value = parts.shift().slice(1).split(".")[0];
517
+ if (supp.number === undefined)
518
+ supp.number = value;
519
+ else
520
+ supp.version = value;
521
+ }
522
+ };
523
+ consumeV();
513
524
  if (supp.year === undefined && /^\d{4}$/.test(parts[0] ?? ""))
514
525
  supp.year = parts.shift();
526
+ // a v-token after the year would otherwise start a type-less wrap
527
+ consumeV();
515
528
  if (parts[0] !== undefined && !/^\d+$/.test(parts[0]) &&
516
529
  !/^(amd|cor|sup|add|v\d+|stage-)/i.test(parts[0])) {
517
530
  supp.languages = parts.shift().split(",").map((l) => l.toUpperCase()).join("/");
@@ -577,10 +590,16 @@ function parseIsoUrn(urn) {
577
590
  }
578
591
  const suppTree = {};
579
592
  if (supp.stage !== undefined) {
580
- const stage = ISO_TYPED_STAGES.find((s) => s.stageCode === supp.stage);
593
+ // A harmonized code resolves within the supplement's own type
594
+ // family -- the IS-family default would turn a staged Corrigendum
595
+ // into a plain IS (mirrors the gem's build_identifier).
596
+ const stage = /^\d\d\.\d\d$/.test(supp.stage)
597
+ ? ISO_TYPED_STAGES.find((st) => st.harmonized?.includes(supp.stage) && st.typeKey === supp.type) ??
598
+ ISO_TYPED_STAGES.find((st) => st.harmonized?.includes(supp.stage) && st.typeKey === "is")
599
+ : ISO_TYPED_STAGES.find((st) => st.stageCode === supp.stage);
581
600
  suppTree["type_with_stage"] = stage !== undefined
582
601
  ? stage.abbr[0] ?? ""
583
- : supp.stage.toUpperCase();
602
+ : supp.type?.toUpperCase() ?? supp.stage.toUpperCase();
584
603
  }
585
604
  if (supp.type !== undefined && suppTree["type_with_stage"] === undefined) {
586
605
  suppTree["type_with_stage"] = supp.type.toUpperCase();
@@ -589,6 +608,8 @@ function parseIsoUrn(urn) {
589
608
  suppTree["number"] = supp.number;
590
609
  if (supp.year !== undefined)
591
610
  suppTree["date"] = supp.year;
611
+ if (supp.version !== undefined)
612
+ suppTree["supplement_version"] = supp.version;
592
613
  if (supp.languages !== undefined)
593
614
  suppTree["languages"] = supp.languages;
594
615
  tree = { base: tree, ...suppTree };
@@ -465,14 +465,9 @@ class IsoUrnGenerator extends BaseUrnGenerator {
465
465
  const stageCode = ts.entry.stageCode;
466
466
  if (stageCode === "published")
467
467
  return undefined;
468
- const typeKey = id.typeKey();
469
- const combinedKey = typeKey !== "is" ? `${stageCode}${typeKey}` : stageCode;
470
- const stageAbbrUrn = TYPED_STAGE_MAP[combinedKey] ?? TYPED_STAGE_MAP[stageCode];
471
- if (stageAbbrUrn !== undefined) {
472
- if (id.stage_iteration !== undefined)
473
- return `${stageAbbrUrn}.${id.stage_iteration.render() ?? ""}`;
474
- return stageAbbrUrn;
475
- }
468
+ // RFC 5141 carries the stage as the harmonized code only; the typed
469
+ // abbreviations live in the human face. Legacy abbreviation URNs are
470
+ // accepted on ingestion and re-canonicalized here.
476
471
  const harmonized = ts.entry.harmonized;
477
472
  if (harmonized === undefined || harmonized.length === 0)
478
473
  return undefined;
@@ -558,17 +553,15 @@ class IsoUrnGenerator extends BaseUrnGenerator {
558
553
  parts.push(stageComp);
559
554
  parts.push(supp.typeKey() === "suppl" || supp.typeKey() === "add" ? "sup" : supp.typeKey());
560
555
  const iter = supp.typeKey() === "suppl" || supp.stage_iteration === undefined ? undefined : supp.stage_iteration.render();
556
+ // RFC 5141 supplement slots in order: number, year (the bis
557
+ // additive extension), then the published version.
558
+ if (supp.number !== undefined)
559
+ parts.push(supp.number);
561
560
  const d = urnDate(supp);
562
- if (d !== undefined) {
561
+ if (d !== undefined)
563
562
  parts.push(d);
564
- if (supp.number !== undefined)
565
- parts.push(iter !== undefined ? `v${supp.number}.${iter}` : `v${supp.number}`);
566
- }
567
- else {
568
- if (supp.number !== undefined)
569
- parts.push(supp.number);
570
- parts.push(iter !== undefined ? `v1.${iter}` : "v1");
571
- }
563
+ const version = supp.supplement_version ?? 1;
564
+ parts.push(iter !== undefined ? `v${version}.${iter}` : `v${version}`);
572
565
  if (supp.languages !== undefined && supp.languages.length > 0) {
573
566
  parts.push(supp.languages.map((l) => l.code).join(","));
574
567
  }
@@ -616,10 +609,14 @@ const supplementPublisherMappings = () => [
616
609
  },
617
610
  },
618
611
  ];
619
- const SUPPLEMENT_MAPPINGS = keyValue(...ISO_MAPPINGS, ...supplementPublisherMappings(), stageMapping(), { wire: "base", to: "base" });
612
+ const SUPPLEMENT_MAPPINGS = keyValue(...ISO_MAPPINGS, ...supplementPublisherMappings(), stageMapping(), { wire: "base", to: "base" },
613
+ // omitted when unset, so parsed human faces keep their hashes
614
+ { wire: "supplement_version", to: "supplement_version" });
620
615
  export class IsoSupplementIdentifier extends IsoSingleIdentifier {
621
616
  static attributes = extendAttributes(IsoSingleIdentifier, {
622
617
  base: { type: IsoIdentifier },
618
+ // The RFC 5141 <supplversion> (corrected version of the supplement).
619
+ supplement_version: { type: "string" },
623
620
  });
624
621
  static mappings = SUPPLEMENT_MAPPINGS;
625
622
  render() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubid/pubid",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "TypeScript PubID identifiers: resolution, normalization and canonical hashes for every identifier in the pubid-testsuite corpus (41 standards bodies), with a conformance runner mirroring the Ruby reference",
5
5
  "type": "module",
6
6
  "license": "MIT",