@konneal/engine 0.2.20 → 0.2.22

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.
@@ -241,7 +241,7 @@ var require_dist = __commonJS({
241
241
  var delay = (ms) => new Promise((r) => setTimeout(r, ms));
242
242
  async function embed(ai, _model, text) {
243
243
  let lastError = null;
244
- for (let attempt = 0; attempt < 3; attempt++) {
244
+ for (let attempt2 = 0; attempt2 < 3; attempt2++) {
245
245
  try {
246
246
  const vecs = await ai.embed([text]);
247
247
  if (vecs?.[0]?.length) return vecs[0];
@@ -249,12 +249,12 @@ async function embed(ai, _model, text) {
249
249
  } catch (e) {
250
250
  lastError = e;
251
251
  }
252
- if (attempt < 2) await delay(250 * (attempt + 1));
252
+ if (attempt2 < 2) await delay(250 * (attempt2 + 1));
253
253
  }
254
254
  throw new Error(`embed failed after retries: ${String(lastError)}`);
255
255
  }
256
256
  async function rerank(ai, model, query, texts) {
257
- for (let attempt = 0; attempt < 2; attempt++) {
257
+ for (let attempt2 = 0; attempt2 < 2; attempt2++) {
258
258
  const scores = await ai.rerank(model, query, texts);
259
259
  if (scores && scores.some((s) => Number.isFinite(s))) return scores;
260
260
  }
@@ -262,7 +262,7 @@ async function rerank(ai, model, query, texts) {
262
262
  return null;
263
263
  }
264
264
  async function generateOnce(env, model, messages, effort) {
265
- for (let attempt = 0; attempt < 2; attempt++) {
265
+ for (let attempt2 = 0; attempt2 < 2; attempt2++) {
266
266
  try {
267
267
  const res = await env.AI.run(model, {
268
268
  messages,
@@ -273,7 +273,7 @@ async function generateOnce(env, model, messages, effort) {
273
273
  });
274
274
  if (typeof res?.response === "string" && res.response.trim()) return res.response;
275
275
  if (typeof res?.choices?.[0]?.message?.content === "string" && res.choices[0].message.content.trim()) return res.choices[0].message.content;
276
- if (attempt === 0) console.error("generate returned empty:", model);
276
+ if (attempt2 === 0) console.error("generate returned empty:", model);
277
277
  } catch (e) {
278
278
  console.error("generate failed:", model, String(e).slice(0, 120));
279
279
  }
@@ -339,8 +339,8 @@ var STOP = /* @__PURE__ */ new Set([
339
339
  "there"
340
340
  ]);
341
341
  async function lexicalPrefilter(env, query, k = LEXICAL_K) {
342
- const match = ftsMatchQuery(query);
343
- if (!match) return [];
342
+ const match2 = ftsMatchQuery(query);
343
+ if (!match2) return [];
344
344
  try {
345
345
  const res = await env.DB.prepare(
346
346
  `SELECT c.id, c.doc_id, c.docidentifier, c.doctype, c.doc_number, c.edition,
@@ -351,7 +351,7 @@ async function lexicalPrefilter(env, query, k = LEXICAL_K) {
351
351
  WHERE chunks_fts MATCH ?1
352
352
  ORDER BY rank
353
353
  LIMIT ?2`
354
- ).bind(match, k).all();
354
+ ).bind(match2, k).all();
355
355
  const rows = res.results ?? [];
356
356
  return rows.map((r, i) => {
357
357
  const meta = {
@@ -389,6 +389,1334 @@ async function lexicalPrefilter(env, query, k = LEXICAL_K) {
389
389
 
390
390
  // workers/worker_public/src/codecs.ts
391
391
  var import_oiml_pubid = __toESM(require_dist());
392
+
393
+ // node_modules/@pubid/pubid/dist/grammar/engine.js
394
+ var ParseFailed = class extends Error {
395
+ pos;
396
+ constructor(message, pos) {
397
+ super(`${message} at line 1 char ${pos + 1}`);
398
+ this.name = "ParseFailed";
399
+ this.pos = pos;
400
+ }
401
+ };
402
+ var Ctx = class {
403
+ input;
404
+ pos = 0;
405
+ constructor(input) {
406
+ this.input = input;
407
+ }
408
+ };
409
+ var Fail = class extends Error {
410
+ };
411
+ function attempt(ctx, fn) {
412
+ const saved = ctx.pos;
413
+ try {
414
+ return fn();
415
+ } catch (e) {
416
+ if (e instanceof Fail) {
417
+ ctx.pos = saved;
418
+ return void 0;
419
+ }
420
+ throw e;
421
+ }
422
+ }
423
+ function applyAtom(atom, ctx, consumeAll) {
424
+ const saved = ctx.pos;
425
+ const result = atom._match(ctx, consumeAll);
426
+ if (consumeAll && ctx.pos < ctx.input.length) {
427
+ ctx.pos = saved;
428
+ throw new Fail(`Don't know what to do with ${JSON.stringify(ctx.input.slice(ctx.pos, ctx.pos + 10))}`);
429
+ }
430
+ return result;
431
+ }
432
+ function combine(a, b) {
433
+ if (a === void 0 || a === null)
434
+ return b;
435
+ if (b === void 0 || b === null)
436
+ return a;
437
+ if (typeof a === "string" && typeof b === "string")
438
+ return a + b;
439
+ if (typeof a === "string" && typeof b === "object")
440
+ return b;
441
+ if (typeof b === "string" && typeof a === "object")
442
+ return a;
443
+ if (typeof a === "object" && typeof b === "object") {
444
+ if (!Array.isArray(a) && !Array.isArray(b)) {
445
+ const out = { ...a };
446
+ for (const [k, v] of Object.entries(b)) {
447
+ if (k in out) {
448
+ console.warn(`Duplicate subtrees while merging result of sequence (keys: :${k}); only the values of the latter will be kept.`);
449
+ }
450
+ out[k] = v;
451
+ }
452
+ return out;
453
+ }
454
+ return [...flatten(a), ...flatten(b)];
455
+ }
456
+ return typeof b === "object" ? b : `${a}${b}`;
457
+ }
458
+ function flatten(t) {
459
+ return Array.isArray(t) ? t : [t];
460
+ }
461
+ var Str = class {
462
+ s;
463
+ constructor(s) {
464
+ this.s = s;
465
+ }
466
+ _match(ctx, _consumeAll) {
467
+ if (ctx.input.startsWith(this.s, ctx.pos)) {
468
+ ctx.pos += this.s.length;
469
+ return this.s;
470
+ }
471
+ throw new Fail(`Expected ${JSON.stringify(this.s)}`);
472
+ }
473
+ };
474
+ var Regex = class {
475
+ re;
476
+ constructor(pattern) {
477
+ this.re = new RegExp(`^(?:${pattern})`);
478
+ }
479
+ _match(ctx, _consumeAll) {
480
+ const m = this.re.exec(ctx.input.slice(ctx.pos));
481
+ if (!m)
482
+ throw new Fail(`Expected match on ${this.re.source}`);
483
+ const matched = m[0];
484
+ ctx.pos += matched.length;
485
+ return matched;
486
+ }
487
+ };
488
+ var Seq = class {
489
+ parts;
490
+ constructor(parts) {
491
+ this.parts = parts;
492
+ }
493
+ _match(ctx, consumeAll) {
494
+ let acc = void 0;
495
+ for (let i = 0; i < this.parts.length; i++) {
496
+ const r = applyAtom(this.parts[i], ctx, consumeAll && i === this.parts.length - 1);
497
+ acc = acc === void 0 && r === void 0 ? void 0 : combine(acc, r);
498
+ }
499
+ return acc;
500
+ }
501
+ };
502
+ var Alt = class {
503
+ options;
504
+ constructor(options) {
505
+ this.options = options;
506
+ }
507
+ _match(ctx, consumeAll) {
508
+ let lastFail = "no alternative matched";
509
+ for (const option of this.options) {
510
+ const r = attempt(ctx, () => applyAtom(option, ctx, consumeAll));
511
+ if (r !== void 0)
512
+ return r;
513
+ lastFail = "alternative failed";
514
+ }
515
+ throw new Fail(lastFail);
516
+ }
517
+ };
518
+ var Repeat = class {
519
+ atom;
520
+ min;
521
+ max;
522
+ constructor(atom, min, max) {
523
+ this.atom = atom;
524
+ this.min = min;
525
+ this.max = max;
526
+ }
527
+ get inner() {
528
+ return this.atom instanceof P2 ? this.atom.atom : this.atom;
529
+ }
530
+ _match(ctx, consumeAll) {
531
+ const results = [];
532
+ let count = 0;
533
+ while (count < this.max) {
534
+ const r = attempt(ctx, () => applyAtom(this.inner, ctx, false));
535
+ if (r === void 0)
536
+ break;
537
+ results.push(r);
538
+ count++;
539
+ if (ctx.pos >= ctx.input.length && count < this.min)
540
+ break;
541
+ }
542
+ if (count < this.min) {
543
+ throw new Fail(`Expected at least ${this.min} of repetition`);
544
+ }
545
+ if (consumeAll && count < this.max && ctx.pos < ctx.input.length) {
546
+ throw new Fail("Don't know what to do with trailing input after repetition");
547
+ }
548
+ if (results.some((r) => typeof r === "object"))
549
+ return results;
550
+ return results.join("");
551
+ }
552
+ };
553
+ var Maybe = class {
554
+ atom;
555
+ constructor(atom) {
556
+ this.atom = atom;
557
+ }
558
+ _match(ctx, consumeAll) {
559
+ const inner = this.atom instanceof P2 ? this.atom.atom : this.atom;
560
+ const r = attempt(ctx, () => applyAtom(inner, ctx, consumeAll));
561
+ if (r === void 0 || r === "")
562
+ return void 0;
563
+ return r;
564
+ }
565
+ };
566
+ var As = class {
567
+ atom;
568
+ key;
569
+ constructor(atom, key) {
570
+ this.atom = atom;
571
+ this.key = key;
572
+ }
573
+ get inner() {
574
+ return this.atom instanceof P2 ? this.atom.atom : this.atom;
575
+ }
576
+ _match(ctx, consumeAll) {
577
+ const r = this.inner._match(ctx, consumeAll);
578
+ return { [this.key]: r === void 0 ? null : r };
579
+ }
580
+ };
581
+ var Absent = class {
582
+ atom;
583
+ constructor(atom) {
584
+ this.atom = atom;
585
+ }
586
+ _match(ctx, _consumeAll) {
587
+ const inner = this.atom instanceof P2 ? this.atom.atom : this.atom;
588
+ const r = attempt(ctx, () => inner._match(ctx, false));
589
+ if (r !== void 0)
590
+ throw new Fail("unexpectedly matched");
591
+ return "";
592
+ }
593
+ };
594
+ var Present = class {
595
+ atom;
596
+ constructor(atom) {
597
+ this.atom = atom;
598
+ }
599
+ _match(ctx, _consumeAll) {
600
+ const inner = this.atom instanceof P2 ? this.atom.atom : this.atom;
601
+ const saved = ctx.pos;
602
+ try {
603
+ inner._match(ctx, false);
604
+ } catch (e) {
605
+ if (!(e instanceof Fail))
606
+ throw e;
607
+ ctx.pos = saved;
608
+ throw new Fail("present? probe did not match");
609
+ }
610
+ ctx.pos = saved;
611
+ return "";
612
+ }
613
+ };
614
+ var Ref = class {
615
+ rules;
616
+ name;
617
+ resolved;
618
+ constructor(rules, name) {
619
+ this.rules = rules;
620
+ this.name = name;
621
+ }
622
+ _match(ctx, consumeAll) {
623
+ if (!this.resolved) {
624
+ const rule = this.rules[this.name];
625
+ if (!rule)
626
+ throw new Error(`unknown rule :${this.name}`);
627
+ this.resolved = rule instanceof P2 ? rule.atom : rule;
628
+ }
629
+ return this.resolved._match(ctx, consumeAll);
630
+ }
631
+ };
632
+ var P2 = class _P {
633
+ atom;
634
+ constructor(atom) {
635
+ this.atom = atom;
636
+ }
637
+ then(...next) {
638
+ return new _P(new Seq([this.atom, ...next.map(unwrap)]));
639
+ }
640
+ or(...others) {
641
+ return new _P(new Alt([this.atom, ...others.map(unwrap)]));
642
+ }
643
+ repeat(min = 0, max = Infinity) {
644
+ return new _P(new Repeat(this.atom, min, max));
645
+ }
646
+ maybe() {
647
+ return new _P(new Maybe(this.atom));
648
+ }
649
+ as(key) {
650
+ return new _P(new As(this.atom, key));
651
+ }
652
+ absent() {
653
+ return new _P(new Absent(this.atom));
654
+ }
655
+ present() {
656
+ return new _P(new Present(this.atom));
657
+ }
658
+ };
659
+ function unwrap(p) {
660
+ return p instanceof P2 ? p.atom : p;
661
+ }
662
+ function str(s) {
663
+ return new P2(new Str(s));
664
+ }
665
+ function match(pattern) {
666
+ return new P2(new Regex(pattern));
667
+ }
668
+ function ref(rules, name) {
669
+ return new P2(new Ref(rules, name));
670
+ }
671
+ function parseGrammar(grammar, input) {
672
+ const ctx = new Ctx(input);
673
+ const root = new Ref(grammar.rules, grammar.root);
674
+ const result = attempt(ctx, () => applyAtom(root, ctx, true));
675
+ if (result === void 0) {
676
+ throw new ParseFailed(`Expected one of [${grammar.root.toUpperCase()}]`, ctx.pos);
677
+ }
678
+ return result;
679
+ }
680
+
681
+ // node_modules/@pubid/pubid/dist/flavors/oiml/grammar.js
682
+ function buildRules() {
683
+ const rules = {};
684
+ const rule = (name, build) => {
685
+ rules[name] = build();
686
+ };
687
+ rule("space", () => str(" "));
688
+ rule("space?", () => ref(rules, "space").maybe());
689
+ rule("digits", () => match("\\d").repeat(1));
690
+ rule("year", () => match("\\d").repeat(4, 4).as("year"));
691
+ rule("comma", () => str(", "));
692
+ rule("comma?", () => ref(rules, "comma").maybe());
693
+ rule("comma_space", () => ref(rules, "comma").or(ref(rules, "space")));
694
+ rule("dash", () => str("-"));
695
+ rule("dot", () => str("."));
696
+ rule("words_digits", () => match("[\\dA-Za-z]").repeat(1));
697
+ rule("words", () => match("[A-Za-z]").repeat(1));
698
+ rule("words?", () => ref(rules, "words").maybe());
699
+ rule("year_digits", () => str("19").or(str("20")).then(match("\\d").repeat(2, 2), ref(rules, "digits").absent()));
700
+ rule("month_digits", () => match("\\d").repeat(2, 2));
701
+ rule("day_digits", () => match("\\d").repeat(2, 2));
702
+ rule("originator", () => ref(rules, "organization").as("publisher").then(ref(rules, "space?").then(str("/"), ref(rules, "organization").as("copublisher")).repeat(0)));
703
+ rule("comma_month_year", () => ref(rules, "comma").then(ref(rules, "words").as("month"), str(" "), ref(rules, "year_digits").as("year")));
704
+ rule("year_month", () => ref(rules, "year_digits").then(ref(rules, "dash"), ref(rules, "month_digits")));
705
+ rule("organization", () => str("OIML"));
706
+ rule("colon", () => str(":"));
707
+ rule("lparen", () => str("("));
708
+ rule("rparen", () => str(")"));
709
+ rule("slash", () => str("/"));
710
+ rule("identifier", () => ref(rules, "amendment_identifier").or(ref(rules, "amendment_short")).or(ref(rules, "annex_letter_identifier")).or(ref(rules, "annex_identifier")).or(ref(rules, "plus_supplement_identifier")).or(ref(rules, "trailing_supplement_identifier")).or(ref(rules, "bulletin_identifier")).or(ref(rules, "base")));
711
+ rule("publisher", () => str("OIML").as("publisher").then(ref(rules, "space")));
712
+ rule("doc_type", () => match("[BDEGRSVX]").as("type").then(ref(rules, "space")));
713
+ rule("bulletin_date", () => ref(rules, "space").then(ref(rules, "year_digits").as("year")).then(ref(rules, "dash").then(ref(rules, "two_digits").as("issue")).maybe()).then(ref(rules, "dash").then(ref(rules, "two_digits").as("sequence")).maybe()));
714
+ rule("two_digits", () => match("\\d").repeat(2, 2));
715
+ rule("roman_numeral", () => match("[IVXLCDM]").repeat(1).as("volume_roman"));
716
+ rule("bulletin_citation", () => ref(rules, "space").then(ref(rules, "roman_numeral")).then(ref(rules, "lparen"), ref(rules, "digits").as("issue_arabic"), ref(rules, "rparen")).then(str(" "), match("\\d").repeat(8, 8).as("article_id")));
717
+ rule("bulletin_identifier", () => ref(rules, "publisher").then(str("Bulletin").as("type")).then(ref(rules, "bulletin_citation").or(ref(rules, "bulletin_date")).maybe()).then(ref(rules, "language_portion").maybe().as("language")));
718
+ rule("number_only", () => ref(rules, "digits").as("number"));
719
+ rule("part_number", () => ref(rules, "dash").then(ref(rules, "digits").then(ref(rules, "slash").then(ref(rules, "dash"), ref(rules, "digits")).repeat(0)).as("part")));
720
+ rule("subpart_number", () => ref(rules, "dash").then(ref(rules, "digits").as("subpart")));
721
+ rule("named_suffix", () => ref(rules, "dash").then(str("GUM").then(ref(rules, "space"), ref(rules, "digits")).or(match("[A-Za-z]").repeat(1).then(str("_").maybe(), ref(rules, "digits")).repeat(0)).as("code_suffix")).or(str(" ").then(str("Brochure").as("code_suffix"), str("").as("space_suffix"))));
722
+ rule("full_number", () => ref(rules, "number_only").then(ref(rules, "part_number"), ref(rules, "subpart_number"), ref(rules, "named_suffix").maybe()).or(ref(rules, "number_only").then(ref(rules, "part_number"), ref(rules, "named_suffix").maybe())).or(ref(rules, "number_only").then(ref(rules, "named_suffix").maybe())));
723
+ rule("edition_number", () => str("6th").or(str("5th")).or(str("4th")).or(str("3rd")).or(str("2nd")).or(str("1st")).or(match("\\d").repeat(1).then(str("th").or(str("nd")).or(str("rd")).or(str("st")))).as("edition"));
724
+ rule("edition_text", () => str("Edition").or(str("edition")));
725
+ rule("edition_portion", () => str(", ").or(ref(rules, "space")).then(ref(rules, "edition_number").maybe(), ref(rules, "space?"), ref(rules, "edition_text"), ref(rules, "space?"), ref(rules, "year_digits").as("year")).as("edition_format"));
726
+ rule("date", () => ref(rules, "edition_portion").or(ref(rules, "space?").then(ref(rules, "colon"), ref(rules, "space?"), ref(rules, "year_digits").as("year"))).or(ref(rules, "space?").then(ref(rules, "lparen"), ref(rules, "year_digits").as("year"), ref(rules, "rparen"))));
727
+ rule("stage_iteration", () => match("\\d").repeat(1).then(str("."), match("\\d").repeat(1)).or(match("\\d").repeat(1)).as("iteration"));
728
+ rule("stage_abbr", () => str("WD").or(str("CD")).as("stage"));
729
+ rule("draft_stage", () => ref(rules, "space").then(ref(rules, "stage_iteration").maybe(), ref(rules, "stage_abbr")));
730
+ rule("lang_single", () => match("[EFRXDSCAU]"));
731
+ rule("lang_multi_oiml", () => str("PO").or(str("PT")).or(str("PE")).or(str("SR")));
732
+ rule("lang_multi", () => match("[a-z]").repeat(2, 2));
733
+ rule("language_code", () => ref(rules, "lang_single").then(ref(rules, "slash"), ref(rules, "lang_single")).or(ref(rules, "lang_multi_oiml")).or(ref(rules, "lang_single")).or(ref(rules, "lang_multi")).as("language"));
734
+ rule("language_with_space", () => ref(rules, "space").then(ref(rules, "lparen"), ref(rules, "language_code"), ref(rules, "rparen")).then(str("").as("space_before_lang")));
735
+ rule("language_without_space", () => ref(rules, "lparen").then(ref(rules, "language_code"), ref(rules, "rparen")));
736
+ rule("language_portion", () => ref(rules, "language_with_space").or(ref(rules, "language_without_space")));
737
+ rule("amendment_identifier", () => str("Amendment").then(ref(rules, "space"), ref(rules, "lparen"), ref(rules, "year_digits").as("year"), ref(rules, "rparen")).then(str(" "), str("to"), str(" ")).then(ref(rules, "base_without_language").as("base")).then(ref(rules, "language_portion").maybe().as("language")));
738
+ rule("amendment_short", () => ref(rules, "publisher").then(ref(rules, "doc_type")).then(ref(rules, "full_number").as("base_code")).then(str(" "), str("Amendment").as("amd_marker")).then(str(" ").then(ref(rules, "edition_text"), ref(rules, "space?"), ref(rules, "year_digits").as("year")).as("edition_format").or(ref(rules, "colon").then(ref(rules, "space?"), ref(rules, "year_digits").as("year")))).then(ref(rules, "language_portion").maybe().as("language")));
739
+ rule("trailing_supplement_identifier", () => ref(rules, "base_without_language").as("base").then(str(" "), str("Amendment").or(str("Errata")).as("trailing_marker")).then(ref(rules, "language_portion").maybe().as("language")));
740
+ rule("plus_supplement_identifier", () => ref(rules, "base_without_language").as("base").then(str("+"), str("Amendment").or(str("Errata")).as("plus_marker")).then(ref(rules, "colon").then(ref(rules, "year_digits").as("year")).maybe()).then(ref(rules, "language_portion").maybe().as("language")));
741
+ rule("annex_identifier", () => ref(rules, "base_without_language").as("base").then(str(" "), str("Annexes").as("annex_marker")).then(str(" ").then(ref(rules, "edition_text"), str(" "), ref(rules, "year_digits").as("year")).as("edition_format").or(ref(rules, "colon").then(ref(rules, "year_digits").as("year"))).maybe()).then(ref(rules, "language_portion").maybe().as("language")));
742
+ rule("annex_letter_value", () => match("[A-Z]").then(ref(rules, "dash").then(match("[A-Z]")).maybe()).as("annex_letter"));
743
+ rule("annex_letter_identifier", () => ref(rules, "base_without_language").as("base").then(str(" "), str("Annex"), str(" "), ref(rules, "annex_letter_value")).then(str(" ").then(ref(rules, "edition_text"), str(" "), ref(rules, "year_digits").as("year")).or(ref(rules, "colon").then(ref(rules, "year_digits").as("year"))).maybe()).then(ref(rules, "language_portion").maybe().as("language")));
744
+ rule("base_without_language", () => ref(rules, "publisher").then(ref(rules, "doc_type")).then(ref(rules, "full_number")).then(ref(rules, "date").maybe()).then(ref(rules, "draft_stage").maybe()));
745
+ rule("base", () => ref(rules, "publisher").then(ref(rules, "doc_type")).then(ref(rules, "full_number")).then(ref(rules, "date").maybe()).then(ref(rules, "draft_stage").maybe()).then(ref(rules, "language_portion").maybe()));
746
+ return rules;
747
+ }
748
+ var oimlGrammar = {
749
+ rules: buildRules(),
750
+ root: "identifier"
751
+ };
752
+
753
+ // node_modules/@pubid/pubid/dist/model/component.js
754
+ function renderComponent(value, context) {
755
+ if (value === void 0 || value === null)
756
+ return void 0;
757
+ if (value instanceof Component)
758
+ return value.render(context);
759
+ return String(value);
760
+ }
761
+ var Component = class _Component {
762
+ /**
763
+ * The scalar this component degenerates to when `field` is its only
764
+ * significant value, else undefined (Pubid::Identifier#degenerate_scalar).
765
+ * A field holding another component never degenerates.
766
+ */
767
+ degenerateScalar(field) {
768
+ let found;
769
+ for (const [name, value] of Object.entries(this)) {
770
+ if (value === void 0 || value === null || value === "")
771
+ continue;
772
+ if (this.fieldIsDefaulted(name, value))
773
+ continue;
774
+ if (name === field) {
775
+ if (value instanceof _Component)
776
+ return void 0;
777
+ found = String(value);
778
+ } else {
779
+ return void 0;
780
+ }
781
+ }
782
+ return found;
783
+ }
784
+ /** True when `value` equals the field's declared default. */
785
+ fieldIsDefaulted(_name, _value) {
786
+ return false;
787
+ }
788
+ };
789
+ var pad2 = (value) => value.padStart(2, "0");
790
+ var PubidDate = class extends Component {
791
+ year;
792
+ month;
793
+ day;
794
+ undated;
795
+ constructor(attrs) {
796
+ super();
797
+ this.year = attrs["year"];
798
+ this.month = attrs["month"];
799
+ this.day = attrs["day"];
800
+ this.undated = attrs["undated"] ?? false;
801
+ }
802
+ present() {
803
+ if (this.undated)
804
+ return true;
805
+ return this.year !== void 0 && this.year !== "";
806
+ }
807
+ render(context) {
808
+ if (this.undated && (this.year === void 0 || this.year === ""))
809
+ return "--";
810
+ if (!this.present())
811
+ return void 0;
812
+ if (context === "urn")
813
+ return this.year;
814
+ if (this.month === void 0)
815
+ return this.year;
816
+ let result = `${this.year}-${pad2(this.month)}`;
817
+ if (this.day !== void 0)
818
+ result += `-${pad2(this.day)}`;
819
+ return result;
820
+ }
821
+ toWire() {
822
+ const wire = {};
823
+ if (this.year !== void 0)
824
+ wire["year"] = this.year;
825
+ if (this.month !== void 0)
826
+ wire["month"] = this.month;
827
+ if (this.day !== void 0)
828
+ wire["day"] = this.day;
829
+ if (this.undated)
830
+ wire["undated"] = true;
831
+ return wire;
832
+ }
833
+ fieldIsDefaulted(name, value) {
834
+ return name === "undated" && value === false;
835
+ }
836
+ };
837
+ var Publisher = class extends Component {
838
+ body;
839
+ constructor(attrs) {
840
+ super();
841
+ this.body = attrs["body"];
842
+ }
843
+ render(context) {
844
+ return context === "urn" ? this.body.toLowerCase() : this.body;
845
+ }
846
+ toWire() {
847
+ return { body: this.body };
848
+ }
849
+ };
850
+ var Language = class extends Component {
851
+ static CHAR_MAP = {
852
+ R: "ru",
853
+ F: "fr",
854
+ E: "en",
855
+ A: "ar",
856
+ S: "es",
857
+ D: "de"
858
+ };
859
+ code;
860
+ originalCode;
861
+ constructor(attrs) {
862
+ super();
863
+ this.code = attrs["code"];
864
+ this.originalCode = attrs["originalCode"] ?? attrs["original_code"];
865
+ }
866
+ render(context) {
867
+ if (context === "urn")
868
+ return this.code.toLowerCase();
869
+ if (this.originalCode !== void 0) {
870
+ return this.originalCode.length === 1 ? this.code : this.originalCode;
871
+ }
872
+ return this.code;
873
+ }
874
+ toWire() {
875
+ return this.originalCode === void 0 ? { code: this.code } : { code: this.code, original_code: this.originalCode };
876
+ }
877
+ };
878
+ var Edition = class extends Component {
879
+ number;
880
+ phase;
881
+ constructor(attrs) {
882
+ super();
883
+ this.number = attrs["number"];
884
+ this.phase = attrs["phase"];
885
+ }
886
+ render(context) {
887
+ void context;
888
+ return this.phase === void 0 ? this.number : `${this.number}${this.phase}`;
889
+ }
890
+ toWire() {
891
+ return this.phase === void 0 ? { number: this.number } : { number: this.number, phase: this.phase };
892
+ }
893
+ };
894
+ var Iteration = class extends Component {
895
+ string;
896
+ constructor(attrs) {
897
+ super();
898
+ this.string = attrs["string"];
899
+ }
900
+ render(_context) {
901
+ return this.string;
902
+ }
903
+ toWire() {
904
+ return { string: this.string };
905
+ }
906
+ };
907
+
908
+ // node_modules/@pubid/pubid/dist/model/attribute.js
909
+ function extendAttributes(parent, defs) {
910
+ return { ...parent.attributes, ...defs };
911
+ }
912
+ var BASE_ATTRIBUTES = {
913
+ number: { type: "string" },
914
+ part: { type: "string" },
915
+ subpart: { type: "string" },
916
+ stage_iteration: { type: Iteration },
917
+ date: { type: PubidDate },
918
+ edition: { type: Edition },
919
+ languages: { type: Language, collection: true },
920
+ publisher: { type: Publisher },
921
+ copublishers: { type: Publisher, collection: true },
922
+ all_parts: { type: "boolean", default: false }
923
+ };
924
+ function keyValue(...fields) {
925
+ return fields;
926
+ }
927
+ var FLAT_SCALAR_COMPONENTS = {
928
+ edition: "edition",
929
+ date: "year",
930
+ stage_iteration: "stage_iteration"
931
+ };
932
+ var FLAT_SCALAR_FIELDS = {
933
+ edition: "number",
934
+ date: "year",
935
+ stage_iteration: "string"
936
+ };
937
+
938
+ // node_modules/@pubid/pubid/dist/model/urn-generator.js
939
+ var BaseUrnGenerator = class {
940
+ identifier;
941
+ constructor(identifier) {
942
+ this.identifier = identifier;
943
+ }
944
+ generate() {
945
+ const parts = ["urn", this.urnNamespace()];
946
+ const push = (v) => {
947
+ if (v !== void 0 && v !== null && v !== "")
948
+ parts.push(v);
949
+ };
950
+ push(this.urnPublisher());
951
+ push(this.urnType());
952
+ push(this.urnNumber());
953
+ push(this.urnPart());
954
+ push(this.urnSubpart());
955
+ push(this.urnYear());
956
+ push(this.urnEdition());
957
+ push(this.urnLanguage());
958
+ return parts.join(":");
959
+ }
960
+ /** Template methods — override in subclasses (Ruby precedent). */
961
+ urnNamespace() {
962
+ const [, flavor] = this.identifier.constructor.polymorphicName.split(":");
963
+ return flavor ?? "unknown";
964
+ }
965
+ /** Reads a DECLARED attribute only (Base#maybe) — constants never appear. */
966
+ maybe(name) {
967
+ const attributes = this.identifier.constructor.attributes;
968
+ if (!attributes || !(name in attributes))
969
+ return void 0;
970
+ return this.identifier[name];
971
+ }
972
+ urnPublisher() {
973
+ const pub = this.maybe("publisher");
974
+ if (pub === void 0 || pub === null)
975
+ return void 0;
976
+ return renderComponent(pub, "urn");
977
+ }
978
+ urnType() {
979
+ return void 0;
980
+ }
981
+ urnNumber() {
982
+ const val = this.maybe("number") ?? this.maybe("code");
983
+ return val === void 0 || val === null ? void 0 : renderComponent(val, "urn");
984
+ }
985
+ urnPart() {
986
+ const val = this.maybe("part");
987
+ return val === void 0 || val === null ? void 0 : `-${renderComponent(val, "urn")}`;
988
+ }
989
+ urnSubpart() {
990
+ const val = this.maybe("subpart");
991
+ return val === void 0 || val === null ? void 0 : `-${renderComponent(val, "urn")}`;
992
+ }
993
+ urnYear() {
994
+ const date = this.maybe("date");
995
+ if (date !== void 0 && date !== null && typeof date === "object" && "render" in date) {
996
+ const rendered = date.render("urn");
997
+ return rendered ?? void 0;
998
+ }
999
+ if (date !== void 0 && date !== null)
1000
+ return String(date);
1001
+ const year = this.maybe("year");
1002
+ return year === void 0 || year === null ? void 0 : String(year);
1003
+ }
1004
+ urnEdition() {
1005
+ const ed = this.maybe("edition");
1006
+ if (ed === void 0 || ed === null)
1007
+ return void 0;
1008
+ const num = typeof ed === "object" && "number" in ed ? ed.number : ed;
1009
+ return num === void 0 || num === null || num === "" ? void 0 : `ed.${String(num)}`;
1010
+ }
1011
+ urnLanguage() {
1012
+ const langs = this.maybe("languages");
1013
+ if (!Array.isArray(langs) || langs.length === 0)
1014
+ return void 0;
1015
+ return langs.map((l) => renderComponent(l, "urn")).filter((s) => s !== void 0).join(",");
1016
+ }
1017
+ };
1018
+
1019
+ // node_modules/@pubid/pubid/dist/model/identifier.js
1020
+ var TYPE_REGISTRY = /* @__PURE__ */ new Map();
1021
+ function registerType(klass) {
1022
+ TYPE_REGISTRY.set(klass.polymorphicName, klass);
1023
+ }
1024
+ function resolveType(type) {
1025
+ return TYPE_REGISTRY.get(type);
1026
+ }
1027
+ function isScalarType(t) {
1028
+ return typeof t === "string";
1029
+ }
1030
+ function coerce(value, spec) {
1031
+ if (value === void 0 || value === null)
1032
+ return value;
1033
+ if (spec.collection) {
1034
+ const list = Array.isArray(value) ? value : [value];
1035
+ return list.map((v) => coerceOne(v, spec));
1036
+ }
1037
+ return coerceOne(value, spec);
1038
+ }
1039
+ function coerceOne(value, spec) {
1040
+ if (isScalarType(spec.type)) {
1041
+ if (spec.type === "integer")
1042
+ return Number(value);
1043
+ if (spec.type === "boolean")
1044
+ return Boolean(value);
1045
+ return typeof value === "object" && value !== null ? value : String(value);
1046
+ }
1047
+ if (value instanceof spec.type)
1048
+ return value;
1049
+ if (value instanceof BaseIdentifier)
1050
+ return value;
1051
+ if (typeof value === "object" && value !== null) {
1052
+ if (typeof spec.type === "function" && spec.type.prototype instanceof BaseIdentifier) {
1053
+ const idCtor = spec.type;
1054
+ const v = value;
1055
+ return "_type" in v ? idCtor.fromHash(v) : idCtor.fromHash({ ...v, _type: idCtor.polymorphicName });
1056
+ }
1057
+ return new spec.type(value);
1058
+ }
1059
+ return value;
1060
+ }
1061
+ function isEmptyValue(value) {
1062
+ if (value === "")
1063
+ return true;
1064
+ if (Array.isArray(value) && value.length === 0)
1065
+ return true;
1066
+ return false;
1067
+ }
1068
+ function resolveDefault(spec) {
1069
+ return typeof spec.default === "function" ? spec.default() : spec.default;
1070
+ }
1071
+ var BaseIdentifier = class _BaseIdentifier {
1072
+ /** The root table; subclasses compose via extendAttributes(BaseIdentifier, …). */
1073
+ static attributes = BASE_ATTRIBUTES;
1074
+ constructor(attrs = {}) {
1075
+ for (const [name, spec] of Object.entries(this.classAttributes())) {
1076
+ const value = attrs[name];
1077
+ if (value !== void 0) {
1078
+ this[name] = coerce(value, spec);
1079
+ } else if (spec.initializeEmpty && spec.collection) {
1080
+ this[name] = [];
1081
+ }
1082
+ }
1083
+ }
1084
+ /** The human form (Ruby render(format: :human) → the flavor renderer). */
1085
+ toHuman() {
1086
+ return this.render();
1087
+ }
1088
+ /** Ruby to_urn: the flavor's UrnGenerator, else the base template. */
1089
+ toUrn() {
1090
+ const Generator = this.constructor.urnGenerator ?? BaseUrnGenerator;
1091
+ return new Generator(this).generate();
1092
+ }
1093
+ fromHash(hash) {
1094
+ return this.constructor.fromHash(hash);
1095
+ }
1096
+ classAttributes() {
1097
+ return this.constructor.attributes;
1098
+ }
1099
+ /** Wire key for an attribute: custom mapping or the attribute name. */
1100
+ wireKeyFor(name) {
1101
+ const mappings = this.constructor.mappings;
1102
+ const found = mappings?.find((m) => m.to === name);
1103
+ return found ?? { wire: name };
1104
+ }
1105
+ attrValue(name) {
1106
+ return this[name];
1107
+ }
1108
+ /** Serialize one attribute's value (component → toWire, nested identifier → toHash, scalars as-is). */
1109
+ serializeValue(value) {
1110
+ if (value instanceof _BaseIdentifier)
1111
+ return value.toHashNested();
1112
+ if (value instanceof Component)
1113
+ return value.toWire();
1114
+ if (Array.isArray(value))
1115
+ return value.map((v) => this.serializeValue(v));
1116
+ return value;
1117
+ }
1118
+ /** Nested serialization: same as toHash but with the unfiltered mappings. */
1119
+ toHashNested() {
1120
+ const ctor = this.constructor;
1121
+ if (ctor.mappingsNested === void 0)
1122
+ return this.toHash();
1123
+ return this.toHashWith(ctor.mappingsNested);
1124
+ }
1125
+ toHash() {
1126
+ return this.toHashWith(this.constructor.mappings);
1127
+ }
1128
+ toHashWith(mappings) {
1129
+ const hash = { _type: this.constructor.polymorphicName };
1130
+ const emitted = mappings ? mappings.map((m) => [m.to, m.wire, m.toWire]) : Object.keys(this.classAttributes()).map((name) => [name, name, void 0]);
1131
+ for (const [name, wire, toWire] of emitted) {
1132
+ const value = this.attrValue(name);
1133
+ if (value === void 0 || value === null)
1134
+ continue;
1135
+ const spec = this.classAttributes()[name];
1136
+ if (spec && isEmptyValue(value))
1137
+ continue;
1138
+ if (spec?.default !== void 0 && deepEqual(value, resolveDefault(spec)))
1139
+ continue;
1140
+ const serialized = toWire ? toWire(this) : this.serializeValue(value);
1141
+ if (serialized === void 0 || serialized === null)
1142
+ continue;
1143
+ hash[wire] = serialized;
1144
+ }
1145
+ this.flattenScalars(hash);
1146
+ this.constructor.compactHash?.(this, hash);
1147
+ return hash;
1148
+ }
1149
+ /**
1150
+ * Degenerate single-field components collapse to their scalar
1151
+ * (identifier.rb flatten_scalar_components): `date` RENAMES to `year`,
1152
+ * `edition` keeps its name; guards: never overwrite an emitted wire
1153
+ * key, never rename onto a declared attribute name.
1154
+ */
1155
+ flattenScalars(hash) {
1156
+ const table = { ...FLAT_SCALAR_COMPONENTS, ...this.constructor.flatScalarComponents };
1157
+ for (const [attrName, flatKey] of Object.entries(table)) {
1158
+ const key = attrName in hash ? attrName : void 0;
1159
+ if (key === void 0)
1160
+ continue;
1161
+ const value = hash[key];
1162
+ const field = FLAT_SCALAR_FIELDS[attrName] ?? this.constructor.flatScalarFields?.[attrName];
1163
+ if (field === void 0)
1164
+ continue;
1165
+ const model = this.attrValue(attrName);
1166
+ if (Array.isArray(value) && Array.isArray(model)) {
1167
+ if (model.every((c) => c instanceof Component) && model.length === value.length) {
1168
+ const scalars = model.map((c) => c.degenerateScalar(field));
1169
+ if (scalars.every((s) => s !== void 0))
1170
+ hash[key] = scalars;
1171
+ }
1172
+ continue;
1173
+ }
1174
+ if (!(model instanceof Component))
1175
+ continue;
1176
+ const scalar = model.degenerateScalar(field);
1177
+ if (scalar === void 0)
1178
+ continue;
1179
+ if (flatKey !== key) {
1180
+ if (flatKey in hash || flatKey in this.classAttributes())
1181
+ continue;
1182
+ delete hash[key];
1183
+ hash[flatKey] = scalar;
1184
+ } else {
1185
+ hash[key] = scalar;
1186
+ }
1187
+ }
1188
+ }
1189
+ static fromHash(hash) {
1190
+ const klass = typeof hash["_type"] === "string" ? resolveType(hash["_type"]) : void 0;
1191
+ if (klass && klass !== this) {
1192
+ return klass.fromHash(hash);
1193
+ }
1194
+ const inflated = this.inflateScalarComponents(hash);
1195
+ return new this(this.applyMappings(inflated));
1196
+ }
1197
+ /** Re-nest flat scalars into component hashes (identifier.rb inflate_scalar_components). */
1198
+ static inflateScalarComponents(data) {
1199
+ const klass = this;
1200
+ if (!klass.attributes)
1201
+ return data;
1202
+ const convertedKeys = new Set((klass.mappings ?? []).map((m) => m.wire));
1203
+ const out = { ...data };
1204
+ for (const [attrName, flatKey] of Object.entries({ ...FLAT_SCALAR_COMPONENTS, ...klass.flatScalarComponents })) {
1205
+ const spec = klass.attributes[attrName];
1206
+ if (!spec || typeof spec.type === "string")
1207
+ continue;
1208
+ if (convertedKeys.has(flatKey))
1209
+ continue;
1210
+ if (flatKey !== attrName && flatKey in klass.attributes)
1211
+ continue;
1212
+ const value = out[flatKey];
1213
+ if (value === void 0 || value === null || typeof value === "object")
1214
+ continue;
1215
+ const field = FLAT_SCALAR_FIELDS[attrName];
1216
+ if (Array.isArray(value))
1217
+ continue;
1218
+ delete out[flatKey];
1219
+ out[attrName] = { [field]: String(value) };
1220
+ }
1221
+ return out;
1222
+ }
1223
+ /** Apply custom `fromWire` converters to the inflated hash. */
1224
+ static applyMappings(data) {
1225
+ const klass = this;
1226
+ const mappings = klass.mappings;
1227
+ if (!mappings)
1228
+ return data;
1229
+ const out = { ...data };
1230
+ for (const m of mappings) {
1231
+ if (m.fromWire && m.wire in out) {
1232
+ const value = m.fromWire(out);
1233
+ if (value !== void 0 && value !== null)
1234
+ out[m.to] = value;
1235
+ } else if (m.wire !== m.to && m.wire in out) {
1236
+ out[m.to] = out[m.wire];
1237
+ delete out[m.wire];
1238
+ }
1239
+ }
1240
+ return out;
1241
+ }
1242
+ };
1243
+ function deepEqual(a, b) {
1244
+ return JSON.stringify(a) === JSON.stringify(b);
1245
+ }
1246
+
1247
+ // node_modules/@pubid/pubid/dist/flavors/oiml/model.js
1248
+ var KIND_BY_TYPE = {
1249
+ B: "basic-publication",
1250
+ D: "document",
1251
+ E: "expert-report",
1252
+ G: "guide",
1253
+ R: "recommendation",
1254
+ S: "seminar-report",
1255
+ V: "vocabulary"
1256
+ };
1257
+ var TYPE_STRINGS = {
1258
+ "basic-publication": "B",
1259
+ document: "D",
1260
+ "expert-report": "E",
1261
+ guide: "G",
1262
+ recommendation: "R",
1263
+ "seminar-report": "S",
1264
+ vocabulary: "V"
1265
+ };
1266
+ function isObj(v) {
1267
+ return typeof v === "object" && v !== null && !Array.isArray(v);
1268
+ }
1269
+ function str2(v) {
1270
+ return v === void 0 || v === null ? void 0 : String(v);
1271
+ }
1272
+ function extractLanguage(langData) {
1273
+ if (isObj(langData))
1274
+ return str2(langData["language"]);
1275
+ return str2(langData);
1276
+ }
1277
+ var SINGLE_ATTRS = {
1278
+ publisher: { type: "string" },
1279
+ language: { type: "string" },
1280
+ parsed_format: { type: "string", default: "short" },
1281
+ number: { type: "string" },
1282
+ part: { type: "string" },
1283
+ subpart: { type: "string" },
1284
+ suffix: { type: "string" },
1285
+ space_suffix: { type: "boolean", default: false },
1286
+ year: { type: "string" },
1287
+ edition: { type: "string" },
1288
+ stage: { type: "string" },
1289
+ iteration: { type: "string" }
1290
+ };
1291
+ var OimlBase = class extends BaseIdentifier {
1292
+ effectiveFormat() {
1293
+ return this.parsed_format === "long" ? "long" : "short";
1294
+ }
1295
+ };
1296
+ var OimlSingle = class extends OimlBase {
1297
+ /** Ruby Identifiers::CodeNumber#code. */
1298
+ composedCode() {
1299
+ if (this.number === void 0)
1300
+ return void 0;
1301
+ let result = this.number;
1302
+ if (this.part)
1303
+ result += `-${this.part}`;
1304
+ if (this.subpart)
1305
+ result += `-${this.subpart}`;
1306
+ if (this.suffix)
1307
+ result += `${this.space_suffix ? " " : "-"}${this.suffix}`;
1308
+ return result;
1309
+ }
1310
+ typeString() {
1311
+ return TYPE_STRINGS[this.constructor.polymorphicName.slice("pubid:oiml:".length)] ?? "R";
1312
+ }
1313
+ /** renderSingle — the formatOverride threads through supplement rendering. */
1314
+ render(formatOverride) {
1315
+ const format = formatOverride ?? this.effectiveFormat();
1316
+ let result = `${this.publisher} ${this.typeString()} ${this.composedCode()}`;
1317
+ let usingEditionFormat = false;
1318
+ if (this.edition && this.year) {
1319
+ result += ` ${this.edition} Edition ${this.year}`;
1320
+ usingEditionFormat = true;
1321
+ } else if (this.edition) {
1322
+ result += ` ${this.edition}`;
1323
+ usingEditionFormat = true;
1324
+ } else if (this.year) {
1325
+ if (format === "long") {
1326
+ result += ` Edition ${this.year}`;
1327
+ usingEditionFormat = true;
1328
+ } else {
1329
+ result += `:${this.year}`;
1330
+ }
1331
+ }
1332
+ if (this.stage || this.iteration) {
1333
+ result += " ";
1334
+ if (this.iteration)
1335
+ result += this.iteration;
1336
+ if (this.stage)
1337
+ result += this.stage;
1338
+ }
1339
+ if (this.language) {
1340
+ result += usingEditionFormat || this.parsed_format === "short_with_space" ? ` (${this.language})` : `(${this.language})`;
1341
+ }
1342
+ return result;
1343
+ }
1344
+ };
1345
+ function oimlSingleClass(kind) {
1346
+ const isBulletin = kind === "bulletin";
1347
+ class OimlSingleIdentifier extends OimlSingle {
1348
+ static polymorphicName = `pubid:oiml:${kind}`;
1349
+ static attributes = isBulletin ? extendAttributes(BaseIdentifier, { ...SINGLE_ATTRS, sequence: { type: "string" } }) : extendAttributes(BaseIdentifier, SINGLE_ATTRS);
1350
+ render(formatOverride) {
1351
+ if (!isBulletin)
1352
+ return super.render(formatOverride);
1353
+ if (this.parsed_format === "citation" && this.year && this.number && this.sequence) {
1354
+ return `${this.publisher} Bulletin ${toRoman(Number(this.year) - 1959)}(${Number(this.number)}) ${this.year}${this.number}${this.sequence}`;
1355
+ }
1356
+ let result = `${this.publisher} Bulletin`;
1357
+ if (this.year) {
1358
+ result += ` ${this.year}`;
1359
+ if (this.number)
1360
+ result += `-${this.number}`;
1361
+ if (this.sequence)
1362
+ result += `-${this.sequence}`;
1363
+ }
1364
+ if (this.language)
1365
+ result += ` (${this.language})`;
1366
+ return result;
1367
+ }
1368
+ }
1369
+ registerType(OimlSingleIdentifier);
1370
+ return OimlSingleIdentifier;
1371
+ }
1372
+ var SUPP_ATTRS = {
1373
+ language: { type: "string" },
1374
+ parsed_format: { type: "string", default: "short" },
1375
+ base: { type: OimlSingle },
1376
+ supp_year: { type: "string" },
1377
+ trailing: { type: "boolean", default: false },
1378
+ joined: { type: "boolean", default: false },
1379
+ letter: { type: "string" },
1380
+ year_on_base: { type: "boolean", default: false }
1381
+ };
1382
+ var SUPP_MAPPINGS = keyValue({ wire: "language", to: "language" }, { wire: "parsed_format", to: "parsed_format" }, { wire: "base", to: "base" }, { wire: "year", to: "supp_year" }, { wire: "trailing", to: "trailing" }, { wire: "joined", to: "joined" }, { wire: "letter", to: "letter" }, { wire: "year_on_base", to: "year_on_base" });
1383
+ var OimlSupplement = class extends OimlBase {
1384
+ supplementType() {
1385
+ const kind = this.constructor.polymorphicName.slice("pubid:oiml:".length);
1386
+ if (kind === "annex")
1387
+ return this.letter ? `Annex ${this.letter}` : "Annexes";
1388
+ return kind === "errata" ? "Errata" : "Amendment";
1389
+ }
1390
+ render() {
1391
+ const kind = this.constructor.polymorphicName.slice("pubid:oiml:".length);
1392
+ if (kind === "annex")
1393
+ return this.renderAnnex();
1394
+ return this.renderSupplement();
1395
+ }
1396
+ /** renderSupplement */
1397
+ renderSupplement() {
1398
+ if (this.joined) {
1399
+ let result2 = `${stripLanguage(this.base.render())}+${this.supplementType()}`;
1400
+ if (this.supp_year)
1401
+ result2 += `:${this.supp_year}`;
1402
+ if (this.language)
1403
+ result2 += ` (${this.language})`;
1404
+ return result2;
1405
+ }
1406
+ if (this.trailing) {
1407
+ let result2 = `${stripLanguage(this.base.render())} ${this.supplementType()}`;
1408
+ if (this.language)
1409
+ result2 += ` (${this.language})`;
1410
+ return result2;
1411
+ }
1412
+ const baseFormat = this.effectiveFormat() !== "short" ? this.effectiveFormat() : this.base.parsed_format === "long" ? "long" : "short";
1413
+ const baseStr = stripLanguage(this.base.render(baseFormat));
1414
+ let result = `${this.supplementType()} (${this.supp_year}) to ${baseStr}`;
1415
+ if (this.language)
1416
+ result += ` (${this.language})`;
1417
+ return result;
1418
+ }
1419
+ /** renderAnnex */
1420
+ renderAnnex() {
1421
+ if (this.year_on_base) {
1422
+ const marker = this.letter ? `Annex ${this.letter}` : "Annexes";
1423
+ let result2 = `${stripLanguage(this.base.render())} ${marker}`;
1424
+ if (this.language)
1425
+ result2 += ` (${this.language})`;
1426
+ return result2;
1427
+ }
1428
+ const annexFormat = this.effectiveFormat();
1429
+ const baseStr = this.base.render(this.base.parsed_format === "long" ? "long" : "short").replace(/:.*/, "").replace(/\s+Edition\s+\d{4}/, "").replace(/\(.*\)/, "").trim();
1430
+ let result = baseStr;
1431
+ if (this.letter) {
1432
+ result += ` Annex ${this.letter}`;
1433
+ if (this.supp_year)
1434
+ result += ` Edition ${this.supp_year}`;
1435
+ } else {
1436
+ result += " Annexes";
1437
+ if (this.supp_year) {
1438
+ if (annexFormat === "long") {
1439
+ result += ` Edition ${this.supp_year}`;
1440
+ } else {
1441
+ result += `:${this.supp_year}`;
1442
+ }
1443
+ }
1444
+ }
1445
+ if (this.language)
1446
+ result += ` (${this.language})`;
1447
+ return result;
1448
+ }
1449
+ };
1450
+ function oimlSupplementClass(kind) {
1451
+ class OimlSupplementIdentifier extends OimlSupplement {
1452
+ static polymorphicName = `pubid:oiml:${kind}`;
1453
+ static attributes = extendAttributes(BaseIdentifier, SUPP_ATTRS);
1454
+ static mappings = SUPP_MAPPINGS;
1455
+ }
1456
+ registerType(OimlSupplementIdentifier);
1457
+ return OimlSupplementIdentifier;
1458
+ }
1459
+ var KIND_CLASSES = {};
1460
+ for (const kind of [
1461
+ "recommendation",
1462
+ "basic-publication",
1463
+ "document",
1464
+ "guide",
1465
+ "vocabulary",
1466
+ "expert-report",
1467
+ "seminar-report",
1468
+ "bulletin"
1469
+ ]) {
1470
+ KIND_CLASSES[kind] = oimlSingleClass(kind);
1471
+ }
1472
+ KIND_CLASSES["amendment"] = oimlSupplementClass("amendment");
1473
+ KIND_CLASSES["errata"] = oimlSupplementClass("errata");
1474
+ KIND_CLASSES["annex"] = oimlSupplementClass("annex");
1475
+ var OimlUrnGenerator = class extends BaseUrnGenerator {
1476
+ generate() {
1477
+ const id = this.identifier;
1478
+ const kind = id.constructor.polymorphicName.slice("pubid:oiml:".length);
1479
+ if (kind === "bulletin") {
1480
+ const b = id;
1481
+ const parts2 = ["urn", "oiml", "bulletin"];
1482
+ if (b.year) {
1483
+ let locator = b.year;
1484
+ if (b.number)
1485
+ locator += `-${b.number}`;
1486
+ if (b.sequence)
1487
+ locator += `-${b.sequence}`;
1488
+ parts2.push(locator);
1489
+ }
1490
+ if (id.language)
1491
+ parts2.push(id.language.toLowerCase());
1492
+ return parts2.join(":");
1493
+ }
1494
+ const isSupp = kind === "amendment" || kind === "errata" || kind === "annex";
1495
+ const single = isSupp ? id.base : id;
1496
+ const parts = ["urn", "oiml"];
1497
+ parts.push(isSupp ? "r" : (TYPE_STRINGS[kind] ?? "r").toLowerCase());
1498
+ const code = single.composedCode();
1499
+ if (code)
1500
+ parts.push(code);
1501
+ const year = id.year ?? id.supp_year;
1502
+ if (year)
1503
+ parts.push(year);
1504
+ const stage = id.stage;
1505
+ if (stage)
1506
+ parts.push(stage.toLowerCase());
1507
+ const iteration = id.iteration;
1508
+ if (iteration)
1509
+ parts.push(iteration);
1510
+ if (id.language)
1511
+ parts.push(id.language.toLowerCase());
1512
+ return parts.join(":");
1513
+ }
1514
+ };
1515
+ for (const klass of Object.values(KIND_CLASSES)) {
1516
+ klass.urnGenerator = OimlUrnGenerator;
1517
+ }
1518
+ function buildOimlIdentifier(tree) {
1519
+ if (!isObj(tree))
1520
+ throw new ParseFailed("OIML: unexpected parse tree", 0);
1521
+ if (tree["amd_marker"] !== void 0)
1522
+ return buildShortAmendment(tree);
1523
+ if (tree["base"] !== void 0)
1524
+ return buildSupplement(tree);
1525
+ return buildBaseDocument(tree);
1526
+ }
1527
+ function buildShortAmendment(tree) {
1528
+ const baseCode = isObj(tree["base_code"]) ? tree["base_code"] : void 0;
1529
+ const base = buildBaseDocument({
1530
+ publisher: tree["publisher"],
1531
+ type: tree["type"],
1532
+ number: baseCode?.["number"],
1533
+ part: baseCode?.["part"],
1534
+ subpart: baseCode?.["subpart"]
1535
+ });
1536
+ const editionFormat = isObj(tree["edition_format"]) ? tree["edition_format"] : void 0;
1537
+ const yearValue = editionFormat ? editionFormat["year"] : tree["year"];
1538
+ const attrs = {
1539
+ publisher: "OIML",
1540
+ base,
1541
+ parsed_format: editionFormat ? "long" : "short"
1542
+ };
1543
+ const suppYear = str2(yearValue);
1544
+ if (suppYear !== void 0)
1545
+ attrs["supp_year"] = suppYear;
1546
+ const language = extractLanguage(tree["language"]);
1547
+ if (language !== void 0)
1548
+ attrs["language"] = language;
1549
+ return new KIND_CLASSES["amendment"](attrs);
1550
+ }
1551
+ function buildSupplement(tree) {
1552
+ const marker = str2(tree["trailing_marker"]);
1553
+ const plusMarker = str2(tree["plus_marker"]);
1554
+ let kind;
1555
+ if (tree["annex_letter"] !== void 0 || tree["annex_marker"] !== void 0) {
1556
+ kind = "annex";
1557
+ } else if (marker === "Errata" || plusMarker === "Errata") {
1558
+ kind = "errata";
1559
+ } else {
1560
+ kind = "amendment";
1561
+ }
1562
+ const base = buildOimlIdentifier(tree["base"]);
1563
+ const editionFormat = isObj(tree["edition_format"]) ? tree["edition_format"] : void 0;
1564
+ const yearValue = editionFormat ? editionFormat["year"] : tree["year"];
1565
+ const attrs = {
1566
+ publisher: "OIML",
1567
+ base,
1568
+ parsed_format: editionFormat ? "long" : "short"
1569
+ };
1570
+ const suppYear = str2(yearValue);
1571
+ if (suppYear !== void 0)
1572
+ attrs["supp_year"] = suppYear;
1573
+ const language = extractLanguage(tree["language"]);
1574
+ if (language !== void 0)
1575
+ attrs["language"] = language;
1576
+ if (marker !== void 0)
1577
+ attrs["trailing"] = true;
1578
+ if (plusMarker !== void 0)
1579
+ attrs["joined"] = true;
1580
+ const letter = str2(tree["annex_letter"]);
1581
+ if (letter !== void 0)
1582
+ attrs["letter"] = letter;
1583
+ if (kind === "annex" && !yearValue && base.year)
1584
+ attrs["year_on_base"] = true;
1585
+ return new KIND_CLASSES[kind](attrs);
1586
+ }
1587
+ function buildBaseDocument(tree) {
1588
+ const type = str2(tree["type"]);
1589
+ const kind = type === "Bulletin" ? "bulletin" : KIND_BY_TYPE[type ?? ""] ?? "recommendation";
1590
+ const attrs = {
1591
+ publisher: str2(tree["publisher"]) ?? "OIML"
1592
+ };
1593
+ const number = str2(tree["number"]);
1594
+ if (number !== void 0)
1595
+ attrs["number"] = number;
1596
+ const part = str2(tree["part"]);
1597
+ if (part !== void 0)
1598
+ attrs["part"] = part;
1599
+ const subpart = str2(tree["subpart"]);
1600
+ if (subpart !== void 0)
1601
+ attrs["subpart"] = subpart;
1602
+ const codeSuffix = str2(tree["code_suffix"]);
1603
+ if (codeSuffix !== void 0)
1604
+ attrs["suffix"] = codeSuffix;
1605
+ if ("space_suffix" in tree)
1606
+ attrs["space_suffix"] = true;
1607
+ const editionFormat = isObj(tree["edition_format"]) ? tree["edition_format"] : void 0;
1608
+ let yearValue;
1609
+ if (editionFormat) {
1610
+ yearValue = editionFormat["year"];
1611
+ const edition = str2(editionFormat["edition"]);
1612
+ if (edition !== void 0)
1613
+ attrs["edition"] = edition;
1614
+ } else {
1615
+ yearValue = tree["year"];
1616
+ }
1617
+ const year = str2(yearValue);
1618
+ if (year !== void 0)
1619
+ attrs["year"] = year;
1620
+ if (kind === "bulletin")
1621
+ applyBulletinLocator(attrs, tree);
1622
+ attrs["parsed_format"] = editionFormat ? "long" : tree["space_before_lang"] !== void 0 ? "short_with_space" : tree["article_id"] !== void 0 ? "citation" : "short";
1623
+ const stage = str2(tree["stage"]);
1624
+ if (stage !== void 0)
1625
+ attrs["stage"] = stage;
1626
+ const iteration = str2(tree["iteration"]);
1627
+ if (iteration !== void 0)
1628
+ attrs["iteration"] = iteration;
1629
+ const language = extractLanguage(tree["language"]);
1630
+ if (language !== void 0)
1631
+ attrs["language"] = language;
1632
+ return new KIND_CLASSES[kind](attrs);
1633
+ }
1634
+ function applyBulletinLocator(attrs, tree) {
1635
+ const articleId = str2(tree["article_id"]);
1636
+ if (articleId) {
1637
+ attrs["year"] = articleId.slice(0, 4);
1638
+ attrs["number"] = articleId.slice(4, 6);
1639
+ attrs["sequence"] = articleId.slice(6, 8);
1640
+ return;
1641
+ }
1642
+ const issue = str2(tree["issue"]);
1643
+ if (issue !== void 0)
1644
+ attrs["number"] = issue;
1645
+ const sequence = str2(tree["sequence"]);
1646
+ if (sequence !== void 0)
1647
+ attrs["sequence"] = sequence;
1648
+ }
1649
+ function stripLanguage(s) {
1650
+ return s.replace(/\s*\([^)]+\)\s*$/, "").trim();
1651
+ }
1652
+ function toRoman(n) {
1653
+ const table = [
1654
+ [1e3, "M"],
1655
+ [900, "CM"],
1656
+ [500, "D"],
1657
+ [400, "CD"],
1658
+ [100, "C"],
1659
+ [90, "XC"],
1660
+ [50, "L"],
1661
+ [40, "XL"],
1662
+ [10, "X"],
1663
+ [9, "IX"],
1664
+ [5, "V"],
1665
+ [4, "IV"],
1666
+ [1, "I"]
1667
+ ];
1668
+ let out = "";
1669
+ for (const [value, sym] of table) {
1670
+ while (n >= value) {
1671
+ out += sym;
1672
+ n -= value;
1673
+ }
1674
+ }
1675
+ return out;
1676
+ }
1677
+
1678
+ // node_modules/@pubid/pubid/dist/flavors/oiml/implementation.js
1679
+ function oimlGrammarImplementation() {
1680
+ return {
1681
+ parse(input) {
1682
+ return buildOimlIdentifier(parseGrammar(oimlGrammar, input));
1683
+ }
1684
+ };
1685
+ }
1686
+
1687
+ // workers/worker_public/src/codecs.ts
1688
+ var oimlParser = oimlGrammarImplementation();
1689
+ var TYPE_LETTER = {
1690
+ recommendation: "R",
1691
+ document: "D",
1692
+ basic_publication: "B",
1693
+ "basic-publication": "B",
1694
+ guide: "G",
1695
+ expert_report: "E",
1696
+ "expert-report": "E",
1697
+ vocabulary: "V",
1698
+ seminar_report: "S",
1699
+ "seminar-report": "S"
1700
+ };
1701
+ function dualOimlSpine(side) {
1702
+ try {
1703
+ const h = oimlParser.parse(side.trim()).toHash();
1704
+ if (h.number === void 0) return null;
1705
+ const kind = String(h._type ?? "").split(":").pop() ?? "";
1706
+ const letter = TYPE_LETTER[kind] ?? "";
1707
+ if (!letter) return null;
1708
+ const num = String(Number(h.number));
1709
+ const part = h.part !== void 0 ? String(h.part) : void 0;
1710
+ const ed = h.year !== void 0 ? String(h.year) : h.edition !== void 0 ? String(h.edition) : void 0;
1711
+ return {
1712
+ doc_number: num,
1713
+ ...ed ? { edition: ed } : {},
1714
+ label: `OIML ${letter} ${num}${part ? `-${part}` : ""}${ed ? `:${ed}` : ""}`
1715
+ };
1716
+ } catch {
1717
+ return null;
1718
+ }
1719
+ }
392
1720
  var urnToDisplay = (u) => {
393
1721
  const pub = u.match(/^urn:oiml:pub:([a-z]+):(\d+)(?:-([0-9a-z]+))?(?::(\d{4}))?(?::[a-z]{1,7}(?:-[a-z]{1,7})?)?$/i);
394
1722
  if (pub) return `OIML ${pub[1].toUpperCase()} ${pub[2]}${pub[3] ? `-${pub[3]}` : ""}${pub[4] ? `:${pub[4]}` : ""}`;
@@ -402,6 +1730,11 @@ var parsePubid = (doc) => {
402
1730
  };
403
1731
  var oimlPubid = {
404
1732
  parse(doc, edition) {
1733
+ if (!/^urn:/i.test(doc) && doc.includes("|")) {
1734
+ const side = doc.split("|").map((s) => s.trim()).find((s) => /^(?:OIML|oiml)\b/i.test(s));
1735
+ const dual = side ? dualOimlSpine(side) : null;
1736
+ if (dual) return dual;
1737
+ }
405
1738
  const p = parsePubid(doc);
406
1739
  if (!p || p.series !== "pub") return null;
407
1740
  const type = p.family.toUpperCase();
@@ -570,7 +1903,7 @@ function cfModelRunner(ai) {
570
1903
  async embed(texts) {
571
1904
  const order = embedRequestWinner ? [embedRequestWinner] : Object.keys(EMBED_REQUEST_SHAPES);
572
1905
  for (const name of order) {
573
- for (let attempt = 0; attempt < 3; attempt++) {
1906
+ for (let attempt2 = 0; attempt2 < 3; attempt2++) {
574
1907
  try {
575
1908
  const res = await A.run("@cf/qwen/qwen3-embedding-0.6b", EMBED_REQUEST_SHAPES[name](texts));
576
1909
  const vecs = extractVecBatch(res, texts.length);
@@ -580,7 +1913,7 @@ function cfModelRunner(ai) {
580
1913
  }
581
1914
  } catch {
582
1915
  }
583
- await new Promise((r) => setTimeout(r, 250 * (attempt + 1)));
1916
+ await new Promise((r) => setTimeout(r, 250 * (attempt2 + 1)));
584
1917
  }
585
1918
  }
586
1919
  throw new Error(`embedding failed for all request shapes (${texts.length} text(s))`);
@@ -2692,13 +4025,13 @@ async function understandQuery(ai, model, query, history, entities = []) {
2692
4025
  top_k: 20
2693
4026
  };
2694
4027
  const ATTEMPT_TIMEOUTS = [1e4, 5e3];
2695
- for (let attempt = 0; attempt < ATTEMPT_TIMEOUTS.length; attempt++) {
4028
+ for (let attempt2 = 0; attempt2 < ATTEMPT_TIMEOUTS.length; attempt2++) {
2696
4029
  const call = (async () => {
2697
4030
  const res = await ai.run({ model, messages: body.messages, effort: body.reasoning_effort, maxTokens: body.max_tokens, temperature: body.temperature, topP: body.top_p, topK: body.top_k });
2698
4031
  const text = res?.text ?? null;
2699
4032
  return typeof text === "string" ? extractJson(text) : null;
2700
4033
  })();
2701
- const timeout = new Promise((r) => setTimeout(() => r(null), ATTEMPT_TIMEOUTS[attempt]));
4034
+ const timeout = new Promise((r) => setTimeout(() => r(null), ATTEMPT_TIMEOUTS[attempt2]));
2702
4035
  try {
2703
4036
  const got = await Promise.race([call, timeout]);
2704
4037
  if (got) return got;