@pubid/pubid 0.1.61 → 0.1.62

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
@@ -27,5 +27,7 @@ export interface Identifier {
27
27
  /** Ruby ==: canonical equality skipping equalityIgnored attributes
28
28
  * (the (E) position is spelling, the language itself is not). */
29
29
  equals?(other: Identifier): boolean;
30
+ /** The pubid-scheme URN (urn:pubid:...) from the flavor schema table; BaseIdentifier provides it. */
31
+ toPubidUrn?(): string;
30
32
  }
31
33
  export type ImplementationRegistry = Map<string, FlavorImplementation>;
@@ -24,8 +24,12 @@ function buildRules() {
24
24
  const seriesLetter = str("S").or(str("P"), str("M"), str("B"), str("C"));
25
25
  const year4 = str("19").or(str("20")).then(match("[0-9]").repeat(2));
26
26
  rule("series", () => seriesLetter.as("type"));
27
- rule("number_suffix", () => str(":").then(digits));
28
- rule("number", () => digits.then(rules["number_suffix"].maybe()).as("number"));
27
+ // The colon member captures SEPARATELY ("S-158:102" → number "158" +
28
+ // colon_suffix "102"): the builder re-keys the S-158 member into
29
+ // checks_for and re-glues every other series' member into the number
30
+ // (the C-16:2 opaque face, pubid#637).
31
+ rule("number_suffix", () => str(":").then(digits.as("colon_suffix")));
32
+ rule("number", () => digits.as("number").then(rules["number_suffix"].maybe()));
29
33
  // The compact part face, hyphenated onto the code: S-5-B (lettered),
30
34
  // S-100-1 (numbered) and S-158-S-102 (series reference).
31
35
  rule("compact_part", () => dash.then(seriesLetter
@@ -119,12 +123,76 @@ function padEditionShorthand(value) {
119
123
  segments.push("0");
120
124
  return segments.join(".");
121
125
  }
126
+ /**
127
+ * The S-158 alias unification on the deserialization path (the gem's
128
+ * Builder.normalize_checks_alias, pubid#774). A hash carrying the
129
+ * draft-era part model on the standard family — a series reference
130
+ * ("S-102") or the bare member number ("102") riding number 158 with
131
+ * no checks_for — rebinding onto checks_for; the edition/year that
132
+ * followed the part face are the BASE ones. Pure function: returns the
133
+ * hash untouched when it carries no draft-era part face, a normalized
134
+ * copy otherwise. The face is not restored (the canonical colon form).
135
+ */
136
+ function normalizeChecksAlias(data) {
137
+ const part = data["part"];
138
+ const number = data["number"];
139
+ const typeKey = data["_type"];
140
+ if (typeof part !== "string" ||
141
+ number !== "158" ||
142
+ data["checks_for"] !== undefined ||
143
+ (typeKey !== undefined && !String(typeKey).endsWith("standard"))) {
144
+ return data;
145
+ }
146
+ const seriesRef = /^([SPMBC])-(\d+)$/.exec(part);
147
+ const digits = seriesRef !== null ? seriesRef[2] : /^\d+$/.test(part) ? part : undefined;
148
+ if (digits === undefined)
149
+ return data;
150
+ const out = { ...data };
151
+ const edition = out["part_edition"];
152
+ const year = out["part_year"];
153
+ if (out["edition"] !== undefined && edition !== undefined) {
154
+ throw new ParseFailed(`IHO: duplicate edition: the base edition and the member edition ${String(edition)} cannot both ride S-158:${digits}`, 0);
155
+ }
156
+ delete out["part"];
157
+ delete out["part_edition"];
158
+ delete out["part_year"];
159
+ out["checks_for"] = digits;
160
+ if (out["edition"] === undefined && edition !== undefined)
161
+ out["edition"] = edition;
162
+ if (out["year"] === undefined && year !== undefined)
163
+ out["year"] = year;
164
+ return out;
165
+ }
122
166
  function ihoClass(kind) {
123
167
  const letter = KIND_LETTERS[kind];
124
168
  class IhoKindIdentifier extends BaseIdentifier {
125
169
  static polymorphicName = `pubid:iho:${kind}`;
170
+ /** The deserialization path applies the same S-158 alias unification
171
+ * the parse path applies (the gem's Builder.normalize_checks_alias):
172
+ * a stored row or a legacy URN carrying the draft-era part model
173
+ * (part: "S-102", part_edition: "0.2.0") decodes to the checks_for
174
+ * identity, so no construction path yields the two-identity disease
175
+ * of issue #775. The spelling face is NOT restored — a deserialized
176
+ * identifier renders the canonical colon designator. */
177
+ static fromHash(hash) {
178
+ return super.fromHash(normalizeChecksAlias(hash));
179
+ }
126
180
  static attributes = extendAttributes(BaseIdentifier, {
127
181
  number: { type: "string" },
182
+ // The S-158 family facet (pubid#774): the S-100 product number
183
+ // whose validation checks this publication specifies. The colon
184
+ // designator form "S-158:102" is the primary face; the legacy
185
+ // draft-era part spellings bind the SAME identity.
186
+ checks_for: { type: "string" },
187
+ // The face the input spelled checks_for with: undefined = the
188
+ // primary colon face ("S-158:102"), otherwise the draft-era part
189
+ // value as written ("S-102" of "Part S-102"/"S-158-S-102", "102"
190
+ // of "Part 102") — it prints in the Part slot verbatim.
191
+ // Spelling-only: outside the mappings whitelist it never
192
+ // serializes, and equality skips it — render keeps the input
193
+ // spelling, equality/URN use the canonical shape. URN
194
+ // deserialization restores no face (the canonical colon form).
195
+ checks_face: { type: "string", equalityIgnored: true },
128
196
  part: { type: "string" },
129
197
  part_edition: { type: "string" },
130
198
  part_year: { type: "string" },
@@ -152,9 +220,16 @@ function ihoClass(kind) {
152
220
  spec_sub: { type: "string" },
153
221
  spec_variant: { type: "string" },
154
222
  });
155
- static mappings = keyValue({ wire: "number", to: "number" }, { wire: "part", to: "part" }, { wire: "part_edition", to: "part_edition" }, { wire: "part_year", to: "part_year" }, { wire: "annex", to: "annex" }, { wire: "annex_edition", to: "annex_edition" }, { wire: "annex_year", to: "annex_year" }, { wire: "appendix", to: "appendix" }, { wire: "appendix_subnumber", to: "appendix_subnumber" }, { wire: "appendix_edition", to: "appendix_edition" }, { wire: "appendix_year", to: "appendix_year" }, { wire: "supplement", to: "supplement" }, { wire: "supplement_edition", to: "supplement_edition" }, { wire: "supplement_year", to: "supplement_year" }, { wire: "edition", to: "edition" }, { wire: "year", to: "year" }, { wire: "volume", to: "volume" }, { wire: "volume_edition", to: "volume_edition" }, { wire: "volume_year", to: "volume_year" }, { wire: "issue", to: "issue" }, { wire: "spec", to: "spec" }, { wire: "spec_sub", to: "spec_sub" }, { wire: "spec_variant", to: "spec_variant" });
223
+ static mappings = keyValue({ wire: "number", to: "number" }, { wire: "checks_for", to: "checks_for" }, { wire: "part", to: "part" }, { wire: "part_edition", to: "part_edition" }, { wire: "part_year", to: "part_year" }, { wire: "annex", to: "annex" }, { wire: "annex_edition", to: "annex_edition" }, { wire: "annex_year", to: "annex_year" }, { wire: "appendix", to: "appendix" }, { wire: "appendix_subnumber", to: "appendix_subnumber" }, { wire: "appendix_edition", to: "appendix_edition" }, { wire: "appendix_year", to: "appendix_year" }, { wire: "supplement", to: "supplement" }, { wire: "supplement_edition", to: "supplement_edition" }, { wire: "supplement_year", to: "supplement_year" }, { wire: "edition", to: "edition" }, { wire: "year", to: "year" }, { wire: "volume", to: "volume" }, { wire: "volume_edition", to: "volume_edition" }, { wire: "volume_year", to: "volume_year" }, { wire: "issue", to: "issue" }, { wire: "spec", to: "spec" }, { wire: "spec_sub", to: "spec_sub" }, { wire: "spec_variant", to: "spec_variant" });
156
224
  render() {
157
225
  let result = `IHO ${letter}-${this.number}`;
226
+ // The S-158 checks face: the primary colon form rides the code
227
+ // ("S-158:102"); the draft-era part face keeps its spelling and
228
+ // prints in the Part slot — after the edition ("S-158 0.2.0
229
+ // Part S-102"). The compact face renders expanded (the S-5A law).
230
+ if (this.checks_for !== undefined && this.checks_face === undefined) {
231
+ result += `:${this.checks_for}`;
232
+ }
158
233
  if (this.edition !== undefined)
159
234
  result += ` ${this.edition}`;
160
235
  if (this.supplement !== undefined) {
@@ -174,6 +249,11 @@ function ihoClass(kind) {
174
249
  if (this.spec_variant !== undefined)
175
250
  result += `(${this.spec_variant})`;
176
251
  }
252
+ else if (this.checks_face !== undefined) {
253
+ // The draft-era member face prints in the Part slot, the part
254
+ // value as written ("Part S-102", "Part 102").
255
+ result += ` Part ${this.checks_face}`;
256
+ }
177
257
  else if (this.part !== undefined) {
178
258
  result += ` Part ${this.part}`;
179
259
  if (this.part_edition !== undefined)
@@ -214,12 +294,94 @@ function ihoClass(kind) {
214
294
  }
215
295
  }
216
296
  class IhoUrnGenerator extends BaseUrnGenerator {
297
+ // The guidance publication type per series letter (the gem's
298
+ // MRN_TYPES): S = Standards and Specifications -> spec, P = the
299
+ // periodic publications -> per, M = Miscellaneous (Base Regulatory
300
+ // Publications) -> reg. B and C have no guidance type code — they
301
+ // keep the legacy positional emission until IHO assigns one.
302
+ static MRN_TYPES = { S: "spec", P: "per", M: "reg" };
217
303
  generate() {
304
+ const mrnType = IhoUrnGenerator.MRN_TYPES[letter];
305
+ if (mrnType === undefined)
306
+ return this.generateLegacy();
307
+ const id = this.identifier;
308
+ // The IHO MRN guidance (S-100WG4, the gem's generate_mrn): the
309
+ // publications namespace urn:mrn:iho:pub:, the type token, the
310
+ // name segment, the bare dotted edition, then the trailing
311
+ // marker atoms in containment order.
312
+ const parts = ["urn:mrn:iho:pub", mrnType, this.mrnName(id)];
313
+ if (id.edition !== undefined)
314
+ parts.push(id.edition);
315
+ if (id.year !== undefined)
316
+ parts.push(`year-${id.year}`);
317
+ if (id.supplement !== undefined) {
318
+ parts.push(`sup-${id.supplement}`);
319
+ if (id.supplement_edition !== undefined)
320
+ parts.push(`ed-${id.supplement_edition}`);
321
+ if (id.supplement_year !== undefined)
322
+ parts.push(`year-${id.supplement_year}`);
323
+ }
324
+ if (id.part !== undefined) {
325
+ parts.push(`part-${id.part}`);
326
+ if (id.part_edition !== undefined)
327
+ parts.push(`ed-${id.part_edition}`);
328
+ if (id.part_year !== undefined)
329
+ parts.push(`year-${id.part_year}`);
330
+ }
331
+ // The S-4 spec citation: a child of its part (the citation letter
332
+ // rides the part- atom); the SECTION is NOT emitted — derivable
333
+ // from the spec's hundreds digit.
334
+ if (id.spec !== undefined) {
335
+ parts.push(`spec-${id.spec}`);
336
+ if (id.spec_sub !== undefined)
337
+ parts.push(`specsub-${id.spec_sub}`);
338
+ if (id.spec_variant !== undefined)
339
+ parts.push(`specvar-${id.spec_variant}`);
340
+ }
341
+ if (id.annex !== undefined) {
342
+ parts.push(`annex-${id.annex}`);
343
+ if (id.annex_edition !== undefined)
344
+ parts.push(`ed-${id.annex_edition}`);
345
+ if (id.annex_year !== undefined)
346
+ parts.push(`year-${id.annex_year}`);
347
+ }
348
+ if (id.appendix !== undefined) {
349
+ // The subnumber hyphen-joins its appendix (one compound
350
+ // segment, RFC 3986-safe).
351
+ let segment = `appendix-${id.appendix}`;
352
+ if (id.appendix_subnumber !== undefined)
353
+ segment += `-${id.appendix_subnumber}`;
354
+ parts.push(segment);
355
+ if (id.appendix_edition !== undefined)
356
+ parts.push(`ed-${id.appendix_edition}`);
357
+ if (id.appendix_year !== undefined)
358
+ parts.push(`year-${id.appendix_year}`);
359
+ }
360
+ if (id.volume !== undefined) {
361
+ parts.push(`vol-${id.volume}`);
362
+ if (id.issue !== undefined)
363
+ parts.push(`issue-${id.issue}`);
364
+ if (id.volume_edition !== undefined)
365
+ parts.push(`ed-${id.volume_edition}`);
366
+ if (id.volume_year !== undefined)
367
+ parts.push(`year-${id.volume_year}`);
368
+ }
369
+ return parts.join(":");
370
+ }
371
+ /** The lowercase name form: sNNN, the S-158 member joining
372
+ * hyphenated (s158-102) so the edition stays in its canonical 4th
373
+ * position. */
374
+ mrnName(id) {
375
+ let name = `${letter.toLowerCase()}${id.number}`;
376
+ if (id.checks_for !== undefined)
377
+ name += `-${id.checks_for}`;
378
+ return name;
379
+ }
380
+ /** The legacy positional form (the B/C emission today; the shape
381
+ * every legacy urn:iho: URN decodes from). */
382
+ generateLegacy() {
218
383
  const id = this.identifier;
219
384
  const parts = ["urn", "iho", letter.toLowerCase(), id.number];
220
- // Each component is a marker-prefixed segment; its own edition
221
- // (ed-) and year (year-) follow it directly. The base edition
222
- // and year come first (they attach to the base node).
223
385
  if (id.edition !== undefined)
224
386
  parts.push(`ed-${id.edition}`);
225
387
  if (id.year !== undefined)
@@ -238,10 +400,6 @@ function ihoClass(kind) {
238
400
  if (id.part_year !== undefined)
239
401
  parts.push(`year-${id.part_year}`);
240
402
  }
241
- // The S-4 spec citation: a child of its part (the citation letter
242
- // rides the part- atom), the dotted sub and the parenthesized
243
- // variant its own children. The spelled SECTION is NOT emitted —
244
- // derivable from the spec's hundreds digit.
245
403
  if (id.spec !== undefined) {
246
404
  parts.push(`spec-${id.spec}`);
247
405
  if (id.spec_sub !== undefined)
@@ -259,7 +417,7 @@ function ihoClass(kind) {
259
417
  if (id.appendix !== undefined) {
260
418
  parts.push(`appendix-${id.appendix}`);
261
419
  // The subnumber is a bare child segment directly after the
262
- // appendix ("appendix-D:2").
420
+ // appendix (the legacy emission's only bare atom).
263
421
  if (id.appendix_subnumber !== undefined)
264
422
  parts.push(id.appendix_subnumber);
265
423
  if (id.appendix_edition !== undefined)
@@ -296,6 +454,20 @@ class IhoBuilder extends BaseBuilder {
296
454
  // resolves through (bare "B-401" carries it implicitly).
297
455
  static S4_TYPE = "S";
298
456
  static S4_NUMBER = "4";
457
+ // The S-158 framework publication: its series members (the colon
458
+ // designator and the series-reference part faces) re-key into
459
+ // checks_for (pubid#774).
460
+ static S158_NUMBER = "158";
461
+ // The two publication modes are mutually exclusive (the gem's
462
+ // assert_edition_mode!): a base edition and any component edition
463
+ // cannot ride together.
464
+ static COMPONENT_EDITIONS = [
465
+ "part_edition",
466
+ "supplement_edition",
467
+ "annex_edition",
468
+ "appendix_edition",
469
+ "volume_edition",
470
+ ];
299
471
  // A citation letter is one of S-4's lettered Parts; the section
300
472
  // vocabulary (100-600, Part C 100-500) is theirs.
301
473
  static SPEC_LETTERS = ["A", "B", "C"];
@@ -333,6 +505,67 @@ class IhoBuilder extends BaseBuilder {
333
505
  delete flat[yearKey];
334
506
  }
335
507
  }
508
+ // The S-158 family re-key (pubid#774, the gem's Builder). The colon
509
+ // designator "S-158:<NNN>" is the PRIMARY face: number stays 158,
510
+ // the member binds checks_for. The member designator is the S-158
511
+ // series device — a colon form on any other anchor rejects
512
+ // ("S-44:5", "C-16:2"). A draft-era part face on the S-158 family —
513
+ // a series reference ("Part S-102"), the compact face
514
+ // ("S-158-S-102") or the bare member number ("Part 102") — rebinds
515
+ // onto checks_for while checks_for is UNBOUND (a bound member keeps
516
+ // a genuine part: "S-158:100 Part 2"); a lettered or compound part
517
+ // value ("Part A", "Part 4a") never rebinds. The edition/year that
518
+ // follow the draft-era part face are the BASE ones (the pubid#775
519
+ // mis-bind fix), and the spelling face records the part value as
520
+ // written so the render keeps the input's spelling (equality/URN
521
+ // canonical). The two publication modes are mutually exclusive: a
522
+ // base edition and any component edition cannot ride together.
523
+ const colonSuffix = flat["colon_suffix"];
524
+ delete flat["colon_suffix"];
525
+ if (colonSuffix !== undefined) {
526
+ const type = flat["type"];
527
+ if (flat["number"] === IhoBuilder.S158_NUMBER && (type === undefined || type === "S")) {
528
+ if (flat["checks_for"] !== undefined && flat["checks_for"] !== colonSuffix) {
529
+ throw new ParseFailed(`IHO: checks_for ${String(flat["checks_for"])} conflicts with the colon member ${String(colonSuffix)}`, 0);
530
+ }
531
+ flat["checks_for"] = colonSuffix;
532
+ }
533
+ else {
534
+ throw new ParseFailed(`IHO: the checks_for member designator is the S-158 series device: ${String(type ?? "S")}-${String(flat["number"])}:${String(colonSuffix)} cannot carry it`, 0);
535
+ }
536
+ }
537
+ if (flat["number"] === IhoBuilder.S158_NUMBER &&
538
+ flat["checks_for"] === undefined &&
539
+ typeof flat["part"] === "string") {
540
+ const partValue = flat["part"];
541
+ const seriesRef = /^([SPMBC])-(\d+)$/.exec(partValue);
542
+ const digits = seriesRef !== null ? seriesRef[2] : /^\d+$/.test(partValue) ? partValue : undefined;
543
+ if (digits !== undefined) {
544
+ flat["checks_for"] = digits;
545
+ flat["checks_face"] = partValue;
546
+ delete flat["part"];
547
+ const edition = flat["part_edition"];
548
+ const year = flat["part_year"];
549
+ delete flat["part_edition"];
550
+ delete flat["part_year"];
551
+ if (flat["edition"] !== undefined && edition !== undefined) {
552
+ throw new ParseFailed(`IHO: duplicate edition: the base edition ${String(flat["edition"])} and the member edition ${String(edition)} cannot both ride S-158:${digits}`, 0);
553
+ }
554
+ if (flat["year"] !== undefined && year !== undefined) {
555
+ throw new ParseFailed(`IHO: duplicate year: the base year ${String(flat["year"])} and the member year ${String(year)} cannot both ride S-158:${digits}`, 0);
556
+ }
557
+ if (flat["edition"] === undefined && edition !== undefined)
558
+ flat["edition"] = edition;
559
+ if (flat["year"] === undefined && year !== undefined)
560
+ flat["year"] = year;
561
+ }
562
+ }
563
+ if (flat["edition"] !== undefined) {
564
+ const owned = IhoBuilder.COMPONENT_EDITIONS.filter((k) => flat[k] !== undefined);
565
+ if (owned.length > 0) {
566
+ throw new ParseFailed(`IHO: a base edition and a component edition are mutually exclusive: ${owned.join(", ")} cannot ride edition ${String(flat["edition"])}`, 0);
567
+ }
568
+ }
336
569
  // The S-4 spec citation resolution (ruby resolve_spec_citation!):
337
570
  // the citation letter folds into `part` (a Part-rule capture must
338
571
  // agree), and the long form's spelled section becomes the spec
@@ -18,6 +18,7 @@ export const ialaSchema = define("iala", (s) => {
18
18
  s.type("pubid:iala:letter", "letter");
19
19
  s.type("pubid:iala:manual", "manual");
20
20
  s.type("pubid:iala:model-course", "mc");
21
+ s.type("pubid:iala:publication", "pub");
21
22
  s.type("pubid:iala:recommendation", "rec");
22
23
  s.type("pubid:iala:report", "rpt");
23
24
  s.type("pubid:iala:resolution", "r");
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import { define } from "../index.js";
9
9
  export const ihoSchema = define("iho", (s) => {
10
+ s.atom("checks_for", "checks");
10
11
  s.atom("edition", "ed");
11
12
  s.atom("year", "year");
12
13
  s.atom("supplement", "sup");