relaton 3.1.1 → 3.1.3

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +5 -3
  3. data/lib/relaton/3gpp.rb +1 -1
  4. data/lib/relaton/bib/converter/csl/from_csl.rb +195 -0
  5. data/lib/relaton/bib/converter/csl.rb +13 -1
  6. data/lib/relaton/bib/model/docidentifier.rb +66 -5
  7. data/lib/relaton/calconnect/hit_collection.rb +1 -1
  8. data/lib/relaton/cli/command.rb +3 -1
  9. data/lib/relaton/cli/frontend_assets.rb +7 -6
  10. data/lib/relaton/cli/subcommand_collection.rb +5 -1
  11. data/lib/relaton/core/request_error.rb +18 -0
  12. data/lib/relaton/db/config.rb +9 -1
  13. data/lib/relaton/db/workers_pool.rb +11 -1
  14. data/lib/relaton/db.rb +160 -58
  15. data/lib/relaton/ecma/bibliography.rb +2 -2
  16. data/lib/relaton/etsi/data_fetcher.rb +16 -6
  17. data/lib/relaton/iala/bibliography.rb +1 -1
  18. data/lib/relaton/iana.rb +1 -1
  19. data/lib/relaton/iec/data_parser.rb +41 -2
  20. data/lib/relaton/itu/README.adoc +1 -1
  21. data/lib/relaton/itu/data_crawler_r.rb +1 -1
  22. data/lib/relaton/jis/README.adoc +2 -0
  23. data/lib/relaton/jis/data_fetcher.rb +74 -13
  24. data/lib/relaton/jis/hit_collection.rb +2 -1
  25. data/lib/relaton/jis/processor.rb +1 -1
  26. data/lib/relaton/jis/scraper.rb +46 -5
  27. data/lib/relaton/oasis/bibliography.rb +1 -1
  28. data/lib/relaton/ogc/hit_collection.rb +1 -1
  29. data/lib/relaton/ogc.rb +1 -1
  30. data/lib/relaton/plateau/data_fetcher.rb +10 -1
  31. data/lib/relaton/plateau/handbook_parser.rb +38 -2
  32. data/lib/relaton/plateau/hit_collection.rb +20 -5
  33. data/lib/relaton/sae.rb +1 -1
  34. data/lib/relaton/version.rb +1 -1
  35. data/lib/relaton/w3c/bibliography.rb +1 -1
  36. data/lib/relaton/xsf/bibliography.rb +1 -1
  37. data/lib/relaton/xsf.rb +1 -1
  38. metadata +35 -48
  39. data/lib/relaton/3gpp/CLAUDE.md +0 -218
  40. data/lib/relaton/adobe/CLAUDE.md +0 -104
  41. data/lib/relaton/bib/CLAUDE.md +0 -150
  42. data/lib/relaton/bipm/CLAUDE.md +0 -187
  43. data/lib/relaton/bsi/CLAUDE.md +0 -35
  44. data/lib/relaton/calconnect/CLAUDE.md +0 -177
  45. data/lib/relaton/ccsds/CLAUDE.md +0 -74
  46. data/lib/relaton/cen/CLAUDE.md +0 -219
  47. data/lib/relaton/cie/CLAUDE.md +0 -90
  48. data/lib/relaton/core/CLAUDE.md +0 -140
  49. data/lib/relaton/db/CLAUDE.md +0 -385
  50. data/lib/relaton/doi/CLAUDE.md +0 -105
  51. data/lib/relaton/easc/CLAUDE.md +0 -85
  52. data/lib/relaton/ecma/CLAUDE.md +0 -217
  53. data/lib/relaton/etsi/CLAUDE.md +0 -219
  54. data/lib/relaton/evs/CLAUDE.md +0 -120
  55. data/lib/relaton/gb/CLAUDE.md +0 -47
  56. data/lib/relaton/gost/CLAUDE.md +0 -100
  57. data/lib/relaton/iala/CLAUDE.md +0 -97
  58. data/lib/relaton/iana/CLAUDE.md +0 -105
  59. data/lib/relaton/iec/CLAUDE.md +0 -13
  60. data/lib/relaton/ieee/CLAUDE.md +0 -202
  61. data/lib/relaton/ietf/CLAUDE.md +0 -382
  62. data/lib/relaton/iho/CLAUDE.md +0 -76
  63. data/lib/relaton/index/CLAUDE.md +0 -208
  64. data/lib/relaton/isbn/CLAUDE.md +0 -47
  65. data/lib/relaton/iso/CLAUDE.md +0 -38
  66. data/lib/relaton/itu/CLAUDE.md +0 -685
  67. data/lib/relaton/jcgm/CLAUDE.md +0 -107
  68. data/lib/relaton/jis/CLAUDE.md +0 -64
  69. data/lib/relaton/logger/CLAUDE.md +0 -37
  70. data/lib/relaton/nist/CLAUDE.md +0 -194
  71. data/lib/relaton/oasis/CLAUDE.md +0 -251
  72. data/lib/relaton/ogc/CLAUDE.md +0 -242
  73. data/lib/relaton/oiml/CLAUDE.md +0 -47
  74. data/lib/relaton/omg/CLAUDE.md +0 -137
  75. data/lib/relaton/plateau/CLAUDE.md +0 -126
  76. data/lib/relaton/sae/CLAUDE.md +0 -91
  77. data/lib/relaton/sdo/CLAUDE.md +0 -81
  78. data/lib/relaton/un/CLAUDE.md +0 -91
  79. data/lib/relaton/w3c/CLAUDE.md +0 -369
  80. data/lib/relaton/xsf/CLAUDE.md +0 -189
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9eef3d372dd9873e179368bed9c4e49f80484881fd0e469db1e07ff2dbb7568
4
- data.tar.gz: de460fda09be00fbe2580a2cb4c1fb6cb0beea9009519c84fa46b91cbb3e39fa
3
+ metadata.gz: cf214dd5828ef52d54652cd3c01d5406527e7dd0f6be2c52447a72889e7ed3c8
4
+ data.tar.gz: 48c41d919e828654ae0ddfd8fc0c6dcf2dafc912b65b58b493964145eb936ca6
5
5
  SHA512:
6
- metadata.gz: 6e42b68c6b256aebf17a83184db8939e286dfd70a7274ebe918619cb966277fd89607894207ca767e1d9b2cad59810bfa719284cdbb1b26168780a476086cda2
7
- data.tar.gz: 26ca0ae9cf979c22d944bc0981048668e8d035983825f49ba6915d452604e39de17f51a6a025fc8d7ca71a068c5f8694d22f7b73668adc84cc2b407f82765d69
6
+ metadata.gz: 612e007cdc0a28b1eb0ac6ef9e0e563f067daa8532a25002d76835233e43b5e5051e2af133ad078a96be66d73c56c4ca58f5e3c675e51b8331cb58e3d842060c
7
+ data.tar.gz: 55ba69a723f91403724139457801a0fa92842208d5cc06be86fd7260a8507e85ccccbe3eb454f82553247130e1e072b1def59eee9a6c54c9b2086b8c6a29bd8d
data/README.adoc CHANGED
@@ -6,8 +6,8 @@ image:https://github.com/relaton/relaton/actions/workflows/rake.yml/badge.svg["B
6
6
  Gem for importing and caching bibliographic references to technical standards.
7
7
  Every standards-body flavor ships inside this single gem; flavor code loads on
8
8
  demand via `autoload`, and the `Relaton::Db` API routes a reference to the right
9
- flavor by its prefix. The command-line interface,
10
- link:gems/relaton-cli/docs/README.adoc[`relaton-cli`], is a separate gem.
9
+ flavor by its prefix. The command-line interface (the `relaton` executable) and
10
+ the citation renderer ship inside this gem too.
11
11
 
12
12
  == Installation
13
13
 
@@ -482,10 +482,12 @@ lib/
482
482
  ├── db.rb, db/ # Relaton::Db: registry, cache, workers pool
483
483
  ├── core/ bib/ index/ logger/ # shared infrastructure
484
484
  ├── sdo/ # Relaton.organization: SDO org/logo store (non-flavor)
485
+ ├── cli/ # the CLI: commands, convertors, frontend/ (+ bin/relaton)
486
+ ├── render/ # the citation renderer (ISO 690 engine + styles)
485
487
  └── iso/ iec/ ietf/ … 3gpp/ # ~29 flavor plugins
486
488
  spec/<flavor>/ # each flavor's spec suite
489
+ docs/ # per-component architecture notes (docs/<name>.md)
487
490
  grammar/ # shared RelaxNG test schemas (test-only, not shipped)
488
- gems/relaton-cli/ # the separate relaton-cli gem
489
491
  ----
490
492
 
491
493
  == Flavors
data/lib/relaton/3gpp.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "net/http"
2
2
  # pubid loads with the flavor, for the ::Pubid::Tgpp::Identifier that the
3
3
  # index code names. Processor#remove_index_file names no pubid class: the
4
- # delete never reads the index (see lib/relaton/index/CLAUDE.md).
4
+ # delete never reads the index (see docs/index.md).
5
5
  require "pubid"
6
6
  require_relative "index"
7
7
  require_relative "core"
@@ -0,0 +1,195 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Bib
5
+ module Converter
6
+ module Csl
7
+ # CSL-JSON entry -> ItemData. The downgrade direction: a CSL record
8
+ # is a flat citation, so fields it does not express are left out
9
+ # rather than invented. The mirror of Converter::Bibtex::FromBibtex.
10
+ class FromCsl
11
+ # The reverse of ENTRY_TYPES for the types the export emits; any
12
+ # other CSL type is kept as written.
13
+ TYPES = {
14
+ "article-journal" => "article", "chapter" => "inbook",
15
+ "paper-conference" => "inproceedings", "webpage" => "webresource",
16
+ }.freeze
17
+
18
+ # @param entry [Hash] one CSL-JSON entry
19
+ def initialize(entry)
20
+ @entry = entry
21
+ end
22
+
23
+ # @return [Relaton::Bib::ItemData]
24
+ def transform # rubocop:disable Metrics/MethodLength
25
+ ItemData.new(
26
+ id: @entry["id"],
27
+ docidentifier: fetch_docid,
28
+ type: fetch_type,
29
+ title: fetch_title,
30
+ contributor: fetch_contributor,
31
+ date: fetch_date,
32
+ abstract: fetch_abstract,
33
+ extent: fetch_extent,
34
+ edition: fetch_edition,
35
+ series: fetch_series,
36
+ source: fetch_source,
37
+ language: fetch_language,
38
+ keyword: fetch_keyword,
39
+ relation: fetch_relation,
40
+ )
41
+ end
42
+
43
+ private
44
+
45
+ # @return [Array<Relaton::Bib::Docidentifier>]
46
+ def fetch_docid
47
+ docid = [Docidentifier.new(content: @entry["id"].to_s, primary: true)]
48
+ docid << Docidentifier.new(content: @entry["ISBN"].to_s, type: "isbn") if @entry["ISBN"]
49
+ docid << Docidentifier.new(content: @entry["ISSN"].to_s, type: "issn") if @entry["ISSN"]
50
+ docid
51
+ end
52
+
53
+ # @return [String, nil]
54
+ def fetch_type
55
+ TYPES[@entry["type"]] || @entry["type"]
56
+ end
57
+
58
+ # @return [Array<Relaton::Bib::Title>]
59
+ def fetch_title
60
+ return [] unless @entry["title"]
61
+
62
+ [Title.new(type: "main", content: @entry["title"])]
63
+ end
64
+
65
+ # @return [Array<Relaton::Bib::Contributor>]
66
+ def fetch_contributor
67
+ contribs = []
68
+ fetch_person("author") { |c| contribs << c }
69
+ fetch_person("editor") { |c| contribs << c }
70
+
71
+ return contribs unless @entry["publisher"]
72
+
73
+ contribs << Contributor.new(
74
+ organization: Organization.new(name: [TypedLocalizedString.new(content: @entry["publisher"])]),
75
+ role: [Contributor::Role.new(type: "publisher")],
76
+ )
77
+ contribs
78
+ end
79
+
80
+ # CSL names are {family:, given:} or a bare {literal:}.
81
+ #
82
+ # @param role [String] contributor role
83
+ def fetch_person(role, &_)
84
+ Array(@entry[role]).each do |name|
85
+ yield Contributor.new(person: Person.new(name: build_name(name)), role: [Contributor::Role.new(type: role)])
86
+ end
87
+ end
88
+
89
+ # @param name [Hash] CSL name variable
90
+ # @return [Relaton::Bib::FullName]
91
+ def build_name(name)
92
+ return FullName.new(completename: LocalizedString.new(content: name["literal"])) if name["literal"]
93
+
94
+ fore = name["given"].to_s.split
95
+ FullName.new(
96
+ surname: LocalizedString.new(content: name["family"].to_s),
97
+ forename: fore.map { |fn| FullNameType::Forename.new(content: fn) },
98
+ )
99
+ end
100
+
101
+ # @return [Array<Relaton::Bib::Date>]
102
+ def fetch_date
103
+ { "issued" => "published", "accessed" => "accessed" }.filter_map do |field, type|
104
+ parts = @entry.dig(field, "date-parts")&.first
105
+ next unless parts
106
+
107
+ Bib::Date.new(type: type, at: iso_date(parts))
108
+ end
109
+ end
110
+
111
+ # @param parts [Array<Integer>] [year], [year, month] or [year, month, day]
112
+ # @return [String]
113
+ def iso_date(parts)
114
+ format("%04d", parts[0]).tap do |iso|
115
+ iso << "-%02d" % parts[1] if parts[1]
116
+ iso << "-%02d" % parts[2] if parts[2]
117
+ end
118
+ end
119
+
120
+ # @return [Array<Relaton::Bib::Abstract>]
121
+ def fetch_abstract
122
+ return [] unless @entry["abstract"]
123
+
124
+ [Abstract.new(content: @entry["abstract"])]
125
+ end
126
+
127
+ # @return [Array<Relaton::Bib::Extent>]
128
+ def fetch_extent
129
+ locs = []
130
+ locs << Locality.new(type: "volume", reference_from: @entry["volume"].to_s) if @entry["volume"]
131
+ if @entry["page"]
132
+ from, to = @entry["page"].to_s.split("-", 2)
133
+ locs << Locality.new(type: "page", reference_from: from, reference_to: to)
134
+ end
135
+ locs.any? ? [Extent.new(locality: locs)] : []
136
+ end
137
+
138
+ # @return [Relaton::Bib::Edition, nil]
139
+ def fetch_edition
140
+ Edition.new(content: @entry["edition"].to_s) if @entry["edition"]
141
+ end
142
+
143
+ # @return [Array<Relaton::Bib::Series>]
144
+ # container-title is the journal for article types and the book for
145
+ # chapters; the chapter shape maps to partOf, the journal shape to
146
+ # a series — the same split FromBibtex makes for journal/booktitle.
147
+ def fetch_series
148
+ return [] unless container_title && fetch_type != "inbook"
149
+
150
+ [Series.new(
151
+ type: "journal",
152
+ title: Title.new(content: container_title),
153
+ number: @entry["number"]&.to_s,
154
+ )]
155
+ end
156
+
157
+ # @return [Array<Relaton::Bib::Uri>]
158
+ def fetch_source
159
+ source = []
160
+ source << Uri.new(type: "src", content: @entry["URL"]) if @entry["URL"]
161
+ source << Uri.new(type: "doi", content: @entry["DOI"]) if @entry["DOI"]
162
+ source
163
+ end
164
+
165
+ # @return [Array<String>]
166
+ def fetch_language
167
+ return [] unless @entry["language"]
168
+
169
+ sub = @entry["language"].split("-").first
170
+ [Iso639[sub]&.alpha2 || sub]
171
+ end
172
+
173
+ # @return [Array<Relaton::Bib::Keyword>]
174
+ def fetch_keyword
175
+ Array(@entry["keyword"]).map do |kw|
176
+ Keyword.new(vocab: LocalizedString.new(content: kw))
177
+ end
178
+ end
179
+
180
+ # @return [Array<Relaton::Bib::Relation>]
181
+ def fetch_relation
182
+ return [] unless container_title && fetch_type == "inbook"
183
+
184
+ ttl = Title.new(type: "main", content: container_title)
185
+ [Relation.new(type: "partOf", bibitem: ItemData.new(title: [ttl]))]
186
+ end
187
+
188
+ def container_title
189
+ @entry["container-title"]
190
+ end
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  require "yeptris"
4
4
 
5
+ require_relative "csl/from_csl"
6
+
5
7
 
6
8
  module Relaton
7
9
  module Bib
@@ -21,6 +23,16 @@ module Relaton
21
23
  Renderer.new(item).to_s
22
24
  end
23
25
 
26
+ # CSL-JSON string -> Hash{String=>ItemData}
27
+ def self.to_item(csl_str)
28
+ entries = ::Yeptris::JSON.load(csl_str)
29
+ entries.reduce({}) do |h, entry|
30
+ item = FromCsl.new(entry).transform
31
+ h[item.id.to_s] = item
32
+ h
33
+ end
34
+ end
35
+
24
36
  class Renderer
25
37
  def initialize(item)
26
38
  @item = item
@@ -97,7 +109,7 @@ module Relaton
97
109
  def published_year
98
110
  date = Array(@item.date).find { |d| %w[published issued].include?(d.type.to_s) } || @item.date.first
99
111
  value = date && (date.at || date.from || date.to)
100
- value.to_s[/\d{4}/]
112
+ value.to_s[/\d{4}/] || ""
101
113
  end
102
114
 
103
115
  def source_uri
@@ -66,6 +66,54 @@ module Relaton
66
66
  "BSI" => :Bsi,
67
67
  }.freeze
68
68
 
69
+ # The :slug form's type → pubid flavor map (relaton#441): every
70
+ # docidentifier type whose pubid flavor has a landed pubid-scheme
71
+ # URN schema (pubid#656). Unlike FORM_PUBID — which gates only the
72
+ # SDO publisher forms and stays deliberately small — this table
73
+ # grows with the pubid URN coverage: the slug is the lossless
74
+ # pubid-scheme URN in path clothes, so there is no publisher-form
75
+ # policy in the decision, only "can this flavor emit a
76
+ # round-trippable slug". Every row was verified end-to-end at
77
+ # adoption: parse → Pubid.to_slug → Pubid.from_slug → equal hash.
78
+ # A type absent here degrades to the stored content.
79
+ SLUG_PUBID = {
80
+ "ISO" => :Iso,
81
+ "IEC" => :Iec,
82
+ "IEEE" => :Ieee,
83
+ "IHO" => :Iho,
84
+ "ITU-T" => :Itu,
85
+ "ITU-R" => :Itu,
86
+ "ITU" => :Itu,
87
+ "W3C" => :W3c,
88
+ "3GPP" => :Tgpp,
89
+ "OGC" => :Ogc,
90
+ "OASIS" => :Oasis,
91
+ "OMG" => :Omg,
92
+ "UN" => :Un,
93
+ "XEP" => :Xsf,
94
+ "EVS" => :Evs,
95
+ "CCSDS" => :Ccsds,
96
+ "CEN" => :CenCenelec,
97
+ "BIPM" => :Bipm,
98
+ "CalConnect" => :Calconnect,
99
+ "ECMA" => :Ecma,
100
+ "GB" => :Gb,
101
+ "IANA" => :Iana,
102
+ "NIST" => :Nist,
103
+ "BSI" => :Bsi,
104
+ "IETF" => :Ietf,
105
+ "Internet-Draft" => :Ietf,
106
+ "GOST" => :Gost,
107
+ "JCGM" => :Jcgm,
108
+ "OIML" => :Oiml,
109
+ "SAE" => :Sae,
110
+ "IALA" => :Iala,
111
+ "EASC" => :Easc,
112
+ "DOI" => :Doi,
113
+ "ISBN" => :Isbn,
114
+ "JIS" => :Jis,
115
+ }.freeze
116
+
69
117
  FORMS = %i[external internal slug].freeze
70
118
 
71
119
  # The parsed identifier. A pubid-backed flavor subclass overrides it.
@@ -88,12 +136,25 @@ module Relaton
88
136
 
89
137
  private
90
138
 
91
- # pubid renders the form (`to_s(with_publisher:)`, pubid#620). A
92
- # docidentifier with no parsed pubid (a plain `Bib::Docidentifier`) is
93
- # parsed here; content that pubid cannot parse is returned unchanged.
139
+ # pubid renders the form (`to_s(with_publisher:)`, pubid#620); the
140
+ # :slug form renders through the flavor's pubid-scheme URN schema.
141
+ # A docidentifier with a parsed pubid (a flavor subclass) uses it;
142
+ # a plain `Bib::Docidentifier` is parsed through the form's flavor
143
+ # table — FORM_PUBID for the publisher forms, SLUG_PUBID for :slug
144
+ # (relaton#441). Content pubid cannot parse is returned unchanged.
94
145
  def form_content(form)
95
- flavor = FORM_PUBID[type]
96
- id = flavor && (pubid || parse_form_pubid(flavor))
146
+ flavor = form == :slug ? SLUG_PUBID[type] : FORM_PUBID[type]
147
+ # :slug takes a parsed pubid from anywhere — the slug is the
148
+ # pubid-scheme URN, publisher policy plays no part in it. The
149
+ # publisher forms keep the FORM_PUBID gate: a type outside the
150
+ # table answers its stored content (relaton#49), even when a
151
+ # subclass carries a parsed pubid.
152
+ id =
153
+ if form == :slug
154
+ pubid || (flavor && parse_form_pubid(flavor))
155
+ else
156
+ flavor && (pubid || parse_form_pubid(flavor))
157
+ end
97
158
  return content unless id
98
159
 
99
160
  return slug_form(id) if form == :slug
@@ -66,7 +66,7 @@ module Relaton::Calconnect
66
66
  # An unrecognized reference **raises**; like ISO, ETSI and 3GPP we let it
67
67
  # propagate. relaton-cli rescues `Pubid::Errors::Error` and renders
68
68
  # `"..." is not a recognized standards identifier`
69
- # (`gems/relaton-cli/lib/relaton/cli/command.rb:324`), and `Db#fetch`
69
+ # (`lib/relaton/cli/command.rb`), and `Db#fetch`
70
70
  # logs it through the `StandardError` arm at `lib/relaton/db.rb:122`.
71
71
  # Rescuing here would collapse "this identifier is malformed" into "no
72
72
  # such document", leaving a caller unable to tell them apart.
@@ -371,7 +371,9 @@ module Relaton
371
371
  nil
372
372
  rescue Pubid::Errors::Error
373
373
  %("#{code}" is not a recognized standards identifier)
374
- rescue Relaton::RequestError => e
374
+ rescue Relaton::RequestError, Relaton::NotInLocalStoreError => e
375
+ # A transport failure, or offline mode with no stored entry
376
+ # (relaton#536): print the reason instead of a backtrace.
375
377
  e.message
376
378
  end
377
379
 
@@ -1,9 +1,10 @@
1
1
  module Relaton
2
2
  module Cli
3
- # Resolves the compiled frontend bundle (`app.iife.js` + `style.css`) that is
4
- # built from `gems/relaton-cli/frontend/` at gem-build time and shipped inside
5
- # the gem under `frontend/dist/`. Both the installed gem and a git checkout
6
- # place `frontend/dist` at the gem root, so one relative path covers both.
3
+ # Resolves the compiled frontend bundle (`app.iife.js` + `style.css`) whose
4
+ # source lives at `lib/relaton/cli/frontend/` and whose built dist is
5
+ # committed inside the gem under `frontend/dist/`. Both the installed gem
6
+ # and a git checkout place `frontend/dist` at the gem root, so one relative
7
+ # path covers both.
7
8
  #
8
9
  # If the bundle is missing (a fresh checkout that hasn't run the frontend
9
10
  # build), raise a clear, actionable error rather than emitting a broken page.
@@ -47,8 +48,8 @@ module Relaton
47
48
  unless File.exist?(path)
48
49
  raise BuildMissingError,
49
50
  "Frontend build missing (#{name} not found in #{dist_dir}). " \
50
- "Run `bundle exec rake build_frontend` in gems/relaton-cli " \
51
- "(or `cd frontend && npm install && npm run build`) first."
51
+ "Run `bundle exec rake spec:build_frontend` at the repo root " \
52
+ "(or `cd lib/relaton/cli/frontend && npm install && npm run build`) first."
52
53
  end
53
54
  File.read(path, encoding: "utf-8")
54
55
  end
@@ -131,7 +131,11 @@ module Relaton
131
131
  File.write colfile, coll.to_yaml, encoding: "UTF-8"
132
132
  else Util.info "No matching bibliographic entry found"
133
133
  end
134
- rescue Relaton::UnknownReferenceError => e
134
+ rescue Relaton::UnknownReferenceError, Relaton::NotInLocalStoreError,
135
+ Relaton::RequestError => e
136
+ # An unknown reference, offline mode with no stored entry
137
+ # (relaton#536) or a transport failure: log the reason, and do not
138
+ # write the collection.
135
139
  Util.warn e.message
136
140
  rescue Pubid::Errors::Error
137
141
  Util.error %("#{code}" is not a recognized standards identifier)
@@ -17,6 +17,24 @@ module Relaton
17
17
  # declare only when absent — both forms rescue as StandardError
18
18
  class RequestError < Error; end unless defined?(Relaton::RequestError)
19
19
 
20
+ # Offline mode (`Relaton::Db.configuration.offline`, RELATON_OFFLINE) and
21
+ # the local store has no entry for the reference (relaton#536). Not a
22
+ # RequestError: `Relaton::Db#net_retry` must not retry it, since no
23
+ # request was made.
24
+ class NotInLocalStoreError < Error
25
+ # @return [String] the reference the local store lacks
26
+ attr_reader :reference
27
+
28
+ # @param reference [String]
29
+ # @param dirs [Array<String>] the cache directories that were read
30
+ def initialize(reference, dirs = [])
31
+ @reference = reference
32
+ where = dirs.empty? ? "no cache directory" : dirs.join(", ")
33
+ super("`#{reference}` is not in the local store (#{where}); " \
34
+ "offline mode makes no network request")
35
+ end
36
+ end
37
+
20
38
  # `Relaton::Db` found no flavor for a reference: no flavor's pubid grammar
21
39
  # reads it exactly, and no flavor's prefix matches it. relaton-cli rescues
22
40
  # it, logs the message and returns no document.
@@ -11,11 +11,19 @@ module Relaton
11
11
  end
12
12
 
13
13
  class Configuration
14
- attr_accessor :use_api, :api_host
14
+ # Values of RELATON_OFFLINE that turn offline mode on.
15
+ OFFLINE_ON = %w[1 true yes on].freeze
16
+
17
+ # @!attribute offline
18
+ # @return [Boolean] true: every fetch is answered from the local
19
+ # store only, and a miss raises Relaton::NotInLocalStoreError
20
+ # (relaton#536). Defaults to RELATON_OFFLINE.
21
+ attr_accessor :use_api, :api_host, :offline
15
22
 
16
23
  def initialize
17
24
  @use_api = false
18
25
  @api_host = "https://api.relaton.org"
26
+ @offline = OFFLINE_ON.include?(ENV["RELATON_OFFLINE"].to_s.downcase)
19
27
  end
20
28
  end
21
29
 
@@ -8,7 +8,17 @@ module Relaton
8
8
  @queue = SizedQueue.new(workers * 2)
9
9
  @threads = Array.new workers do
10
10
  Thread.new do
11
- while item = @queue.pop; yield(item) end
11
+ # A worker that dies silently wedges the pool: the item it was
12
+ # processing never completes, and every consumer blocked on that
13
+ # completion blocks forever (metanorma-standoc CI deadlock,
14
+ # 2026-11-13). The pool outlives any single item's failure.
15
+ while item = @queue.pop
16
+ begin
17
+ yield(item)
18
+ rescue Exception => e # rubocop:disable Lint/RescueException
19
+ Util.error "fetch worker item failed: #{e.class}: #{e.message}"
20
+ end
21
+ end
12
22
  end
13
23
  end
14
24
  end