@pubid/pubid 0.1.70 → 0.1.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -192,6 +192,52 @@ dedicated worker entries with no `node:*` module in their import graph:
192
192
  worker entry routes its co-published ISO side to the parg-free iso
193
193
  implementation. No wasm at all.
194
194
 
195
+ ## Worker-safe parse: the shared-builder family (pubid-ts#236)
196
+
197
+ Five more flavors were unreachable in a worker for a different reason:
198
+ **bsi, cen_cenelec, csa** and **gost** build on the central
199
+ `grammarImplementation` (the node barrel) for their adopted-identifier
200
+ routing, and the barrel statically imports the parg-backed flavors —
201
+ so importing the flavor reached `node:fs` even though the flavor's own
202
+ grammar is the pure-TS parslet port. **evs** composes the CEN/CENELEC
203
+ builder, so it dragged the same graph transitively.
204
+
205
+ They now take their foreign-flavor resolution as a parameter
206
+ (`src/flavors/foreign-resolver.ts`): the node barrel wires the full
207
+ central registry (node behavior unchanged), and the worker entries
208
+ wire `workerForeignResolver()` (`src/flavors/worker-registry.ts`) — a
209
+ registry over the worker-available subset (the pure-TS parslet ports
210
+ plus oiml/iso/iec). The gost-style fallback walks then run over the
211
+ worker-available flavors only, which is the honest answer in a worker:
212
+ a flavor whose worker implementation does not exist yet answers
213
+ `undefined` there, exactly like an unknown flavor does in the node
214
+ barrel. Widen the set by merging the parg worker entries in:
215
+
216
+ ```ts
217
+ import { bsiWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/bsi/worker.js";
218
+ import { cenCenelecWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/cen_cenelec/worker.js";
219
+ import { csaWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/csa/worker.js";
220
+ import { gostWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/gost/worker.js";
221
+ import { evsWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/evs/worker.js";
222
+
223
+ // Sync — no wasm, no artifact: the grammars are pure TS.
224
+ const bsi = bsiWorkerGrammarImplementation();
225
+ const cen = cenCenelecWorkerGrammarImplementation();
226
+ const csa = csaWorkerGrammarImplementation();
227
+ const gost = gostWorkerGrammarImplementation();
228
+ const evs = evsWorkerGrammarImplementation();
229
+
230
+ bsi.parse("BS EN ISO 105-B06:2020"); // adopted → worker iso
231
+ cen.parse("EN ISO 11140-3:2009");
232
+ csa.parse("CSA ISO/IEC 8824-1:22");
233
+ gost.parse("GOST 31425.2-2025/ISO 9902-2:2001"); // adoption → worker iso
234
+ evs.parse("EVS-EN ISO 14001:2026"); // → worker cen → worker iso
235
+ ```
236
+
237
+ Each entry accepts a resolver to widen or narrow the foreign set —
238
+ `workerForeignResolverWith({ ieee: await ieeeWorkerGrammarImplementation(wasm) })`
239
+ puts the parg-backed ieee worker entry into gost's fallback walk.
240
+
195
241
  A Cloudflare Worker consumes them like this (`relaton-api-js`'s
196
242
  `engine.ts`; `NO_WORKER_ENGINE = {nist, ieee, oiml}` dissolves). The
197
243
  wasm argument is whatever `parsanol/browser`'s `initialize()` takes —
@@ -238,7 +284,9 @@ your own via `ieeeWorkerGrammarImplementation({ coPublished })`.
238
284
 
239
285
  The receipts are pinned in CI: `npm run test:worker` runs
240
286
  `test/worker/worker-parse.test.ts` inside workerd with NO
241
- `nodejs_compat` (vitest-pool-workers), and `worker-graph.test.ts`
287
+ `nodejs_compat` (vitest-pool-workers) — the nist/ieee/oiml entries and
288
+ the five shared-builder entries all parse their attested corpus
289
+ examples there — and `worker-graph.test.ts`
242
290
  walks the compiled import graphs (no `node:*` module, nothing beyond
243
291
  `parsanol/browser`) and bundles every entry with
244
292
  `esbuild --platform=neutral` and no node externals.
@@ -1,4 +1,5 @@
1
1
  import type { Tree } from "../../grammar/engine.js";
2
2
  import type { FlavorImplementation, Identifier } from "../../conformance/implementation.js";
3
- export declare function buildBsiIdentifier(tree: Tree): Identifier;
4
- export declare function bsiGrammarImplementation(): FlavorImplementation;
3
+ import type { ForeignResolver } from "../foreign-resolver.js";
4
+ export declare function buildBsiIdentifier(tree: Tree, resolveForeign: ForeignResolver): Identifier;
5
+ export declare function bsiGrammarImplementation(resolveForeign: ForeignResolver): FlavorImplementation;
@@ -1,5 +1,4 @@
1
1
  import { parseGrammar } from "../../grammar/engine.js";
2
- import { grammarImplementation } from "../index.js";
3
2
  import { bsiGrammar, preprocessBsi } from "./grammar.js";
4
3
  import { PubidDate, Publisher } from "../../model/component.js";
5
4
  import { AdoptedEuropeanNormClass as CenAdoptedEuropeanNormClass } from "../cen_cenelec/model.js";
@@ -38,8 +37,8 @@ function pub(body) {
38
37
  // The adopted routing mirrors the gem: a routed branch that fails to
39
38
  // parse RAISES through (build_adopted_identifier calls the foreign
40
39
  // parser directly), which is what rejects e.g. "BS HD 629.1 S3:2019".
41
- function tryForeign(flavor, raw) {
42
- const impl = grammarImplementation(flavor);
40
+ function tryForeign(flavor, raw, resolveForeign) {
41
+ const impl = resolveForeign(flavor);
43
42
  if (impl === undefined)
44
43
  return undefined;
45
44
  return impl.parse(raw);
@@ -199,10 +198,10 @@ function assignAttributes(data) {
199
198
  return attrs;
200
199
  }
201
200
  // --- The builder ---------------------------------------------------------------------
202
- export function buildBsiIdentifier(tree) {
203
- return buildTree(flatten(tree));
201
+ export function buildBsiIdentifier(tree, resolveForeign) {
202
+ return buildTree(flatten(tree), resolveForeign);
204
203
  }
205
- function buildTree(data) {
204
+ function buildTree(data, resolveForeign) {
206
205
  const original = { ...data };
207
206
  if (data["standalone_amendment"] !== undefined || data["parenthesized_amd"] !== undefined) {
208
207
  return buildStandaloneAmendment(data);
@@ -238,26 +237,26 @@ function buildTree(data) {
238
237
  return buildAerospaceIdentifier(flatten(data["aerospace_identifier"]));
239
238
  }
240
239
  if (data["supplement_document"] !== undefined) {
241
- return buildSupplementDocument(flatten(data["supplement_document"]));
240
+ return buildSupplementDocument(flatten(data["supplement_document"]), resolveForeign);
242
241
  }
243
242
  if (data["addendum_document"] !== undefined) {
244
- return buildAddendumDocument(flatten(data["addendum_document"]));
243
+ return buildAddendumDocument(flatten(data["addendum_document"]), resolveForeign);
245
244
  }
246
245
  if (data["bundled_parts"] !== undefined || data["bundled_list"] !== undefined) {
247
- return buildBundledIdentifier(data);
246
+ return buildBundledIdentifier(data, resolveForeign);
248
247
  }
249
248
  if (data["set"] !== undefined) {
250
- return buildSetData(data["set"]);
249
+ return buildSetData(data["set"], resolveForeign);
251
250
  }
252
251
  const supplementsData = extractSupplements(data);
253
252
  if (data["pdf_format"] !== undefined || data["tc_format"] !== undefined || data["book_format"] !== undefined) {
254
- return buildValueAddedPublication(data, supplementsData);
253
+ return buildValueAddedPublication(data, supplementsData, resolveForeign);
255
254
  }
256
255
  if (data["na_prefix"] !== undefined) {
257
- return buildNationalAnnex(data, supplementsData);
256
+ return buildNationalAnnex(data, supplementsData, resolveForeign);
258
257
  }
259
258
  if (data["adopted_string"] !== undefined) {
260
- const adopted = buildAdoptedIdentifier(data, original);
259
+ const adopted = buildAdoptedIdentifier(data, original, resolveForeign);
261
260
  if (adopted !== undefined)
262
261
  return adopted;
263
262
  }
@@ -464,7 +463,7 @@ function buildCommitteeDocument(data) {
464
463
  attrs["date"] = new PubidDate({ year: String(Number(fullYear)) });
465
464
  return new (ctor(CommitteeDocumentClass))(attrs);
466
465
  }
467
- function buildValueAddedPublication(data, _supplements) {
466
+ function buildValueAddedPublication(data, _supplements, resolveForeign) {
468
467
  const format = data["pdf_format"] !== undefined
469
468
  ? "PDF"
470
469
  : data["tc_format"] !== undefined
@@ -476,17 +475,17 @@ function buildValueAddedPublication(data, _supplements) {
476
475
  delete baseData["pdf_format"];
477
476
  delete baseData["tc_format"];
478
477
  delete baseData["book_format"];
479
- const baseId = buildTree(baseData);
478
+ const baseId = buildTree(baseData, resolveForeign);
480
479
  return new (ctor(ValueAddedPublicationClass))({
481
480
  base: baseId,
482
481
  format,
483
482
  });
484
483
  }
485
- function buildNationalAnnex(data, _supplements) {
484
+ function buildNationalAnnex(data, _supplements, resolveForeign) {
486
485
  const baseData = { ...data };
487
486
  delete baseData["na_prefix"];
488
487
  delete baseData["na_supplements"];
489
- const baseId = buildTree(baseData);
488
+ const baseId = buildTree(baseData, resolveForeign);
490
489
  const naPrefix = isObj(data["na_prefix"]) ? data["na_prefix"] : undefined;
491
490
  const naSuppRaw = naPrefix !== undefined && naPrefix["na_supplements"] !== undefined
492
491
  ? naPrefix["na_supplements"]
@@ -530,7 +529,7 @@ function iterationOf(v) {
530
529
  }
531
530
  return undefined;
532
531
  }
533
- function buildSupplementDocument(data) {
532
+ function buildSupplementDocument(data, resolveForeign) {
534
533
  const publisherVal = strv(data["publisher"]);
535
534
  // The grammar nests the parts under a "parts" key inside the parts
536
535
  // subtree; unwrap before extracting part/subpart.
@@ -556,7 +555,7 @@ function buildSupplementDocument(data) {
556
555
  else if (data["year"] !== undefined) {
557
556
  baseData["year"] = data["year"];
558
557
  }
559
- const baseId = buildTree(baseData);
558
+ const baseId = buildTree(baseData, resolveForeign);
560
559
  const suppType = strv(data["supp_no_prefix"]) === "No."
561
560
  ? "No."
562
561
  : strv(data["supp_no_prefix"]) !== undefined
@@ -571,7 +570,7 @@ function buildSupplementDocument(data) {
571
570
  separator: strv(data["supp_sep"]) ?? ":",
572
571
  });
573
572
  }
574
- function buildAddendumDocument(data) {
573
+ function buildAddendumDocument(data, resolveForeign) {
575
574
  const publisherVal = strv(data["publisher"]);
576
575
  // The grammar nests the parts under a "parts" key inside the
577
576
  // "parts" subtree; unwrap before extracting part/subpart.
@@ -588,7 +587,7 @@ function buildAddendumDocument(data) {
588
587
  };
589
588
  if (data["base_year"] !== undefined)
590
589
  baseData["year"] = data["base_year"];
591
- const baseId = buildTree(baseData);
590
+ const baseId = buildTree(baseData, resolveForeign);
592
591
  const addType = strv(data["add_no_prefix"]) === "No."
593
592
  ? "No."
594
593
  : strv(data["add_no_prefix"]) !== undefined
@@ -605,7 +604,7 @@ function buildAddendumDocument(data) {
605
604
  separator,
606
605
  });
607
606
  }
608
- function buildBundleItem(itemData, defaultPublisher, defaultPrefix) {
607
+ function buildBundleItem(itemData, defaultPublisher, defaultPrefix, resolveForeign) {
609
608
  if (isObj(itemData)) {
610
609
  const d = itemData;
611
610
  const hasExplicitPublisher = d["publisher"] !== undefined;
@@ -636,7 +635,7 @@ function buildBundleItem(itemData, defaultPublisher, defaultPrefix) {
636
635
  // Simple string (alphanumeric like "N001")
637
636
  return new BsiIdentifier({ number: strv(itemData) });
638
637
  }
639
- function buildBundledIdentifier(data) {
638
+ function buildBundledIdentifier(data, resolveForeign) {
640
639
  if (data["bundled_parts"] !== undefined) {
641
640
  const partsData = flatten(data["bundled_parts"]);
642
641
  const baseNumber = strv(partsData["number"]) ?? "";
@@ -660,7 +659,7 @@ function buildBundledIdentifier(data) {
660
659
  const items = [];
661
660
  const separators = [];
662
661
  if (firstElem["bundle_item"] !== undefined) {
663
- items.push(buildBundleItem(firstElem["bundle_item"], publisherVal, prefixVal));
662
+ items.push(buildBundleItem(firstElem["bundle_item"], publisherVal, prefixVal, resolveForeign));
664
663
  }
665
664
  for (const rawElem of listArray.slice(1)) {
666
665
  const elem = flatten(rawElem);
@@ -681,7 +680,7 @@ function buildBundledIdentifier(data) {
681
680
  else if (elem["sep_comma"] !== undefined)
682
681
  sep = ",";
683
682
  separators.push(sep);
684
- items.push(buildBundleItem(elem["bundle_item"], publisherVal, prefixVal));
683
+ items.push(buildBundleItem(elem["bundle_item"], publisherVal, prefixVal, resolveForeign));
685
684
  }
686
685
  }
687
686
  const yearElem = listArray.map((e) => flatten(e)).find((e) => e["year"] !== undefined);
@@ -692,7 +691,7 @@ function buildBundledIdentifier(data) {
692
691
  common_year: yearVal !== undefined ? new PubidDate({ year: String(Number(yearVal)) }) : undefined,
693
692
  });
694
693
  }
695
- function buildSetData(setRaw) {
694
+ function buildSetData(setRaw, resolveForeign) {
696
695
  const itemsArray = Array.isArray(setRaw) ? setRaw.flat(Infinity) : [setRaw];
697
696
  const identifiers = [];
698
697
  for (const item of itemsArray) {
@@ -721,7 +720,7 @@ function buildSetData(setRaw) {
721
720
  idStr += `:${strv(itemData["year"])}`;
722
721
  if (idStr.trim() === "")
723
722
  continue;
724
- const parsed = parseBsi(idStr);
723
+ const parsed = parseBsi(idStr, resolveForeign);
725
724
  if (parsed !== undefined)
726
725
  identifiers.push(parsed);
727
726
  }
@@ -731,7 +730,7 @@ function buildSetData(setRaw) {
731
730
  });
732
731
  }
733
732
  // --- Adopted identifiers ---------------------------------------------------------------
734
- function buildAdoptedIdentifier(dataIn, originalIn) {
733
+ function buildAdoptedIdentifier(dataIn, originalIn, resolveForeign) {
735
734
  const data = dataIn;
736
735
  const original = originalIn;
737
736
  const adoptedRaw = data["adopted_string"];
@@ -846,13 +845,13 @@ function buildAdoptedIdentifier(dataIn, originalIn) {
846
845
  const isoIecStr = adoptedStr.replace(/^EN\s+/, "");
847
846
  let parsed;
848
847
  if (isoIecStr.startsWith("ISO/IEC") || isoIecStr.includes("ISO/IEC")) {
849
- parsed = tryForeign("iso", isoIecStr);
848
+ parsed = tryForeign("iso", isoIecStr, resolveForeign);
850
849
  }
851
850
  else if (isoIecStr.startsWith("ISO")) {
852
- parsed = tryForeign("iso", isoIecStr);
851
+ parsed = tryForeign("iso", isoIecStr, resolveForeign);
853
852
  }
854
853
  else if (isoIecStr.startsWith("IEC")) {
855
- parsed = tryForeign("iec", isoIecStr);
854
+ parsed = tryForeign("iec", isoIecStr, resolveForeign);
856
855
  }
857
856
  // Wrap the ISO/IEC identifier in a CEN EN adoption.
858
857
  if (parsed !== undefined) {
@@ -862,23 +861,23 @@ function buildAdoptedIdentifier(dataIn, originalIn) {
862
861
  });
863
862
  }
864
863
  else {
865
- adoptedId = tryForeign("cen_cenelec", adoptedStr);
864
+ adoptedId = tryForeign("cen_cenelec", adoptedStr, resolveForeign);
866
865
  }
867
866
  }
868
867
  else if (adoptedStr.startsWith("ISO/IEC") || adoptedStr.includes("ISO/IEC")) {
869
- adoptedId = tryForeign("iso", adoptedStr);
868
+ adoptedId = tryForeign("iso", adoptedStr, resolveForeign);
870
869
  }
871
870
  else if (adoptedStr.startsWith("ISO")) {
872
- adoptedId = tryForeign("iso", adoptedStr);
871
+ adoptedId = tryForeign("iso", adoptedStr, resolveForeign);
873
872
  }
874
873
  else if (adoptedStr.startsWith("IEC")) {
875
- adoptedId = tryForeign("iec", adoptedStr);
874
+ adoptedId = tryForeign("iec", adoptedStr, resolveForeign);
876
875
  }
877
876
  else if (/^(EN|CEN|CLC|CR|ES|ENV|HD|CWA)/.test(adoptedStr)) {
878
- adoptedId = tryForeign("cen_cenelec", adoptedStr);
877
+ adoptedId = tryForeign("cen_cenelec", adoptedStr, resolveForeign);
879
878
  }
880
879
  else if (adoptedStr.startsWith("CISPR")) {
881
- adoptedId = tryForeign("iec", adoptedStr);
880
+ adoptedId = tryForeign("iec", adoptedStr, resolveForeign);
882
881
  }
883
882
  if (isBare && adoptedId !== undefined)
884
883
  return adoptedId;
@@ -909,17 +908,17 @@ function buildAdoptedIdentifier(dataIn, originalIn) {
909
908
  return undefined;
910
909
  }
911
910
  // --- The parse entry -------------------------------------------------------------------
912
- function parseBsi(input) {
911
+ function parseBsi(input, resolveForeign) {
913
912
  const cleaned = preprocessBsi(input);
914
913
  try {
915
914
  const tree = parseGrammar(bsiGrammar, cleaned);
916
- return buildBsiIdentifier(tree);
915
+ return buildBsiIdentifier(tree, resolveForeign);
917
916
  }
918
917
  catch {
919
918
  return undefined;
920
919
  }
921
920
  }
922
- export function bsiGrammarImplementation() {
921
+ export function bsiGrammarImplementation(resolveForeign) {
923
922
  return {
924
923
  parse(input) {
925
924
  // Delegate to IEC for bare IEC identifiers with VAP suffixes or
@@ -928,10 +927,12 @@ export function bsiGrammarImplementation() {
928
927
  && (/\s+(CSV|CMV|RLV|SER|EXV|PAC|PRV)\b/.test(input)
929
928
  || /\+AMD\d+:/.test(input)
930
929
  || /\+COR\d+:/.test(input))) {
931
- const iec = grammarImplementation("iec");
930
+ const iec = resolveForeign("iec");
931
+ if (iec === undefined)
932
+ throw new Error("iec implementation unavailable");
932
933
  return iec.parse(input);
933
934
  }
934
- const parsed = parseBsi(input);
935
+ const parsed = parseBsi(input, resolveForeign);
935
936
  if (parsed === undefined) {
936
937
  throw new Error("Failed to parse BSI identifier");
937
938
  }
@@ -0,0 +1,3 @@
1
+ import type { FlavorImplementation } from "../../conformance/implementation.js";
2
+ import type { ForeignResolver } from "../foreign-resolver.js";
3
+ export declare function bsiWorkerGrammarImplementation(foreign?: ForeignResolver): FlavorImplementation;
@@ -0,0 +1,18 @@
1
+ //! The worker entry for the bsi flavor (pubid/pubid-ts#236): the same
2
+ //! implementation the node entry runs, with the foreign-flavor
3
+ //! resolution (the adopted ISO/IEC/CEN routing) wired to the
4
+ //! worker-safe registry instead of the node barrel. No `node:*` module
5
+ //! appears in this graph and no wasm loads — the bsi grammar is the
6
+ //! pure-TS parslet port, so the entry is synchronous.
7
+ //!
8
+ //! import { bsiWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/bsi/worker.js";
9
+ //! const bsi = bsiWorkerGrammarImplementation();
10
+ //! bsi.parse("BS EN ISO 105-B06:2020"); // adopted routing → worker iso
11
+ //!
12
+ //! Pass a resolver to widen or narrow the foreign set (e.g. merged with
13
+ //! the parg worker entries via `workerForeignResolverWith`).
14
+ import { workerForeignResolver } from "../worker-registry.js";
15
+ import { bsiGrammarImplementation } from "./index.js";
16
+ export function bsiWorkerGrammarImplementation(foreign) {
17
+ return bsiGrammarImplementation(foreign ?? workerForeignResolver());
18
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Tree } from "../../grammar/engine.js";
2
2
  import type { FlavorImplementation, Identifier } from "../../conformance/implementation.js";
3
+ import type { ForeignResolver } from "../foreign-resolver.js";
3
4
  /** The tree → identifier pipeline, shared with composed flavors (evs). */
4
- export declare function buildCenIdentifier(tree: Tree): Identifier;
5
- export declare function cenCenelecGrammarImplementation(): FlavorImplementation;
5
+ export declare function buildCenIdentifier(tree: Tree, resolveForeign: ForeignResolver): Identifier;
6
+ export declare function cenCenelecGrammarImplementation(resolveForeign: ForeignResolver): FlavorImplementation;
@@ -1,5 +1,4 @@
1
1
  import { parseGrammar, ParseFailed } from "../../grammar/engine.js";
2
- import { grammarImplementation } from "../index.js";
3
2
  import { cenCenelecGrammar, preprocessCenCenelec } from "./grammar.js";
4
3
  import { AdoptedEuropeanNormClass, AmendmentClass, CEN_DOCUMENT_CLASSES, ConsolidatedIdentifierClass, CorrigendumClass, DEFAULT_TYPED_STAGE, EuropeanPrestandardClass, FragmentClass, PUBLISHER_TYPES, locateStage, locateTypeClass, } from "./model.js";
5
4
  /**
@@ -23,6 +22,13 @@ function flattenArray(data) {
23
22
  return Object.assign({}, ...data);
24
23
  }
25
24
  class CenBuilder {
25
+ /** The foreign-flavor resolver for the adopted identifiers
26
+ * (pubid-ts#236): the node barrel wires the central registry, the
27
+ * worker entry wires the worker-available subset. */
28
+ #resolveForeign;
29
+ constructor(resolveForeign) {
30
+ this.#resolveForeign = resolveForeign;
31
+ }
26
32
  build(data) {
27
33
  const d = Array.isArray(data) ? flattenArray(data) : data;
28
34
  if (d["fragment_number"] !== undefined) {
@@ -131,13 +137,13 @@ class CenBuilder {
131
137
  }
132
138
  parseAdoptedString(adoptedStr) {
133
139
  if (adoptedStr.startsWith("ISO/IEC") || adoptedStr.includes("ISO/IEC") || adoptedStr.startsWith("ISO")) {
134
- const impl = grammarImplementation("iso");
140
+ const impl = this.#resolveForeign("iso");
135
141
  if (impl === undefined)
136
142
  throw new Error("iso implementation unavailable");
137
143
  return impl.parse(adoptedStr);
138
144
  }
139
145
  if (adoptedStr.startsWith("IEC")) {
140
- const impl = grammarImplementation("iec");
146
+ const impl = this.#resolveForeign("iec");
141
147
  if (impl === undefined)
142
148
  throw new Error("iec implementation unavailable");
143
149
  return impl.parse(adoptedStr);
@@ -181,7 +187,7 @@ class CenBuilder {
181
187
  const num = Number.parseInt(numStr, 10);
182
188
  if (!(num >= 60000 && num <= 79999))
183
189
  return undefined;
184
- const impl = grammarImplementation("iec");
190
+ const impl = this.#resolveForeign("iec");
185
191
  if (impl === undefined)
186
192
  return undefined;
187
193
  return new AdoptedEuropeanNormClass({
@@ -267,11 +273,11 @@ class CenBuilder {
267
273
  }
268
274
  import { PubidDate as PubidDateRef } from "../../model/component.js";
269
275
  /** The tree → identifier pipeline, shared with composed flavors (evs). */
270
- export function buildCenIdentifier(tree) {
271
- return new CenBuilder().build(tree);
276
+ export function buildCenIdentifier(tree, resolveForeign) {
277
+ return new CenBuilder(resolveForeign).build(tree);
272
278
  }
273
- export function cenCenelecGrammarImplementation() {
274
- const builder = new CenBuilder();
279
+ export function cenCenelecGrammarImplementation(resolveForeign) {
280
+ const builder = new CenBuilder(resolveForeign);
275
281
  return {
276
282
  parse(input) {
277
283
  const cleaned = preprocessCenCenelec(input);
@@ -0,0 +1,3 @@
1
+ import type { FlavorImplementation } from "../../conformance/implementation.js";
2
+ import type { ForeignResolver } from "../foreign-resolver.js";
3
+ export declare function cenCenelecWorkerGrammarImplementation(foreign?: ForeignResolver): FlavorImplementation;
@@ -0,0 +1,17 @@
1
+ //! The worker entry for the cen_cenelec flavor (pubid/pubid-ts#236):
2
+ //! the same implementation the node entry runs, with the adopted
3
+ //! ISO/IEC resolution wired to the worker-safe registry instead of the
4
+ //! node barrel. No `node:*` module appears in this graph and no wasm
5
+ //! loads — the CEN/CENELEC grammar is the pure-TS parslet port, so the
6
+ //! entry is synchronous.
7
+ //!
8
+ //! import { cenCenelecWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/cen_cenelec/worker.js";
9
+ //! const cen = cenCenelecWorkerGrammarImplementation();
10
+ //! cen.parse("EN ISO 11140-3:2009"); // adopted routing → worker iso
11
+ //!
12
+ //! Pass a resolver to widen or narrow the foreign set.
13
+ import { workerForeignResolver } from "../worker-registry.js";
14
+ import { cenCenelecGrammarImplementation } from "./index.js";
15
+ export function cenCenelecWorkerGrammarImplementation(foreign) {
16
+ return cenCenelecGrammarImplementation(foreign ?? workerForeignResolver());
17
+ }
@@ -1,2 +1,3 @@
1
1
  import type { FlavorImplementation } from "../../conformance/implementation.js";
2
- export declare function csaGrammarImplementation(): FlavorImplementation;
2
+ import type { ForeignResolver } from "../foreign-resolver.js";
3
+ export declare function csaGrammarImplementation(resolveForeign: ForeignResolver): FlavorImplementation;
@@ -1,5 +1,4 @@
1
1
  import { parseGrammar } from "../../grammar/engine.js";
2
- import { grammarImplementation } from "../index.js";
3
2
  import { csaGrammar, normalizeCsa, csaPublisherPrefix } from "./grammar.js";
4
3
  import { BundledClass, CanadianAdoptedClass, CecClass, CombinedClass, CsaAdoptedClass, CsaSingleIdentifier, PackageClass, SeriesClass, StandardClass, } from "./model.js";
5
4
  /**
@@ -23,8 +22,8 @@ function flatten(data) {
23
22
  return Array.isArray(data) ? Object.assign({}, ...data) : data;
24
23
  }
25
24
  const ctor = (klass) => klass;
26
- function tryForeign(flavor, raw) {
27
- const impl = grammarImplementation(flavor);
25
+ function tryForeign(flavor, raw, resolveForeign) {
26
+ const impl = resolveForeign(flavor);
28
27
  if (impl === undefined)
29
28
  return undefined;
30
29
  try {
@@ -186,14 +185,14 @@ function buildCec(dataIn) {
186
185
  return cec;
187
186
  }
188
187
  // --- The builder dispatch ---------------------------------------------------------------
189
- function buildTree(parsed) {
188
+ function buildTree(parsed, resolveForeign) {
190
189
  const data = parsed;
191
190
  if (data["publisher_prefix"] !== undefined
192
191
  && ["CAN/CSA-", "CAN3-"].includes(strv(data["publisher_prefix"]) ?? "")) {
193
192
  return buildCanadianAdopted(data);
194
193
  }
195
194
  if ("adoption_number" in data)
196
- return buildAdoption(data);
195
+ return buildAdoption(data, resolveForeign);
197
196
  if ("series_type" in data)
198
197
  return buildSeries(parsed);
199
198
  if ("cec_part" in data)
@@ -216,16 +215,16 @@ function buildPackage(data) {
216
215
  : {}),
217
216
  });
218
217
  }
219
- function parseAdoptionBase(adoptionOrg, baseStr) {
218
+ function parseAdoptionBase(adoptionOrg, baseStr, resolveForeign) {
220
219
  if (adoptionOrg.startsWith("ISO") || adoptionOrg.startsWith("CEI")) {
221
- return tryForeign("iso", baseStr);
220
+ return tryForeign("iso", baseStr, resolveForeign);
222
221
  }
223
222
  if (adoptionOrg.startsWith("IEC")) {
224
- return tryForeign("iec", baseStr);
223
+ return tryForeign("iec", baseStr, resolveForeign);
225
224
  }
226
- return tryForeign("iso", baseStr) ?? tryForeign("iec", baseStr);
225
+ return tryForeign("iso", baseStr, resolveForeign) ?? tryForeign("iec", baseStr, resolveForeign);
227
226
  }
228
- function buildAdoption(data) {
227
+ function buildAdoption(data, resolveForeign) {
229
228
  let adoptionOrg = strv(data["adoption_org"]) ?? "";
230
229
  const adoptionNumber = strv(data["adoption_number"]) ?? "";
231
230
  const adoptionYear = strv(data["adoption_year"]) ?? "";
@@ -239,14 +238,14 @@ function buildAdoption(data) {
239
238
  const amendmentYear = strv(data["adoption_amendment_year"]) ?? "";
240
239
  const wrappedAmendmentYear = amendmentYear.length === 2 ? `20${amendmentYear}` : amendmentYear;
241
240
  const amendmentStr = `${baseStr}/Amd ${strv(data["adoption_amendment"])}:${wrappedAmendmentYear}`;
242
- base = parseAdoptionBase(adoptionOrg, amendmentStr);
241
+ base = parseAdoptionBase(adoptionOrg, amendmentStr, resolveForeign);
243
242
  }
244
243
  else {
245
244
  let wrappedIdStr = `${adoptionOrg} ${adoptionNumber}${yearSep}${wrappedYear}`;
246
245
  if (adoptionOrg === "CEI/IEC") {
247
246
  wrappedIdStr = wrappedIdStr.replace("CEI/IEC", "IEC");
248
247
  }
249
- base = parseAdoptionBase(adoptionOrg, wrappedIdStr);
248
+ base = parseAdoptionBase(adoptionOrg, wrappedIdStr, resolveForeign);
250
249
  }
251
250
  const self = { base };
252
251
  if (data["reaffirmation_4digit"] !== undefined) {
@@ -378,9 +377,9 @@ function parseTree(input) {
378
377
  return hash;
379
378
  }
380
379
  // --- Identifier.parse (identifier.rb) ------------------------------------------------------
381
- function tryParse(input) {
380
+ function tryParse(input, resolveForeign) {
382
381
  try {
383
- return parseCsa(input);
382
+ return parseCsa(input, resolveForeign);
384
383
  }
385
384
  catch {
386
385
  return undefined;
@@ -415,22 +414,22 @@ function setPublisherPrefix(obj, prefix) {
415
414
  setPublisherPrefix(base, prefix);
416
415
  }
417
416
  }
418
- function parseExternalStandard(input) {
417
+ function parseExternalStandard(input, resolveForeign) {
419
418
  if (/^(ISO\/IEC|ISO|IEC|CEI|CEI\/IEC)\s/.test(input)) {
420
- return tryForeign("iso", input.replace(/^CEI\/IEC/, "IEC"));
419
+ return tryForeign("iso", input.replace(/^CEI\/IEC/, "IEC"), resolveForeign);
421
420
  }
422
421
  // The catalogue also prints the IWA designation without the ISO
423
422
  // keyword ("CAN/CSA-IWA 18:17" beside "CAN/CSA-ISO IWA 18:17"); the
424
423
  // ISO parser wants the ISO/ prefix.
425
424
  if (/^IWA\s/.test(input)) {
426
- return tryForeign("iso", input.replace(/^IWA\s/, "ISO/IWA "));
425
+ return tryForeign("iso", input.replace(/^IWA\s/, "ISO/IWA "), resolveForeign);
427
426
  }
428
427
  if (/^CISPR\s/.test(input)) {
429
- return tryForeign("iec", input);
428
+ return tryForeign("iec", input, resolveForeign);
430
429
  }
431
430
  return undefined;
432
431
  }
433
- function parseCsa(input) {
432
+ function parseCsa(input, resolveForeign) {
434
433
  if (input.startsWith("#")) {
435
434
  throw new Error(`Not a CSA identifier (comment): ${input}`);
436
435
  }
@@ -447,7 +446,7 @@ function parseCsa(input) {
447
446
  let normalized = wrappedInput0.replace(/^CSA-/, "CSA ");
448
447
  normalized = normalized.replaceAll("CAN/CSA-", "CSA ").replaceAll("CAN3-", "CSA ");
449
448
  normalized = normalized.replaceAll(/\s+/g, " ").trim();
450
- const result = buildTree(parseTree(normalized));
449
+ const result = buildTree(parseTree(normalized), resolveForeign);
451
450
  setPublisherPrefix(result, "CAN/CSA-");
452
451
  const rMatch = /\(R(\d{4})\)/.exec(wrappedInput0);
453
452
  if (rMatch !== null) {
@@ -462,7 +461,7 @@ function parseCsa(input) {
462
461
  ? "CSA"
463
462
  : undefined;
464
463
  const normalized = stripped.replace(/^CSA-/, "CSA ");
465
- const base = parseCsa(normalized);
464
+ const base = parseCsa(normalized, resolveForeign);
466
465
  const baseSelf = base;
467
466
  // Only the single-document types and CsaAdopted declare
468
467
  // publisher_prefix; the containers (Combined/Bundled/Package) keep
@@ -489,7 +488,7 @@ function parseCsa(input) {
489
488
  const wrapped0 = input.replace(/^CAN3-/, "CSA ");
490
489
  const hasDashYear = /-\d{2}\b/.test(wrapped0);
491
490
  const { year: reaffirmYear, was4digit, rest: stripped } = extractReaffirmation(wrapped0);
492
- const base = parseCsa(stripped);
491
+ const base = parseCsa(stripped, resolveForeign);
493
492
  const baseSelf = base;
494
493
  if (hasDashYear) {
495
494
  baseSelf["year_format"] = "dash";
@@ -531,7 +530,7 @@ function parseCsa(input) {
531
530
  : year;
532
531
  return `/Amd ${num}${sep}${full}`;
533
532
  });
534
- const base = parseExternalStandard(wrapped);
533
+ const base = parseExternalStandard(wrapped, resolveForeign);
535
534
  if (base === undefined) {
536
535
  throw new Error(`Unparseable adopted standard: ${input}`);
537
536
  }
@@ -592,7 +591,7 @@ function parseCsa(input) {
592
591
  if (/^PACKAGE$/i.test(token))
593
592
  break;
594
593
  const testInput = acc === "" ? token : `${acc} ${token}`;
595
- if (tryParse(testInput) === undefined)
594
+ if (tryParse(testInput, resolveForeign) === undefined)
596
595
  break;
597
596
  acc = testInput;
598
597
  }
@@ -606,7 +605,7 @@ function parseCsa(input) {
606
605
  if (baseInput === undefined || baseInput === "") {
607
606
  throw new Error(`Unparseable package base: ${input}`);
608
607
  }
609
- const base = parseCsa(baseInput);
608
+ const base = parseCsa(baseInput, resolveForeign);
610
609
  return new (ctor(PackageClass))({
611
610
  base,
612
611
  package_keyword: "PACKAGE",
@@ -618,17 +617,17 @@ function parseCsa(input) {
618
617
  }
619
618
  // Plain path with parser-level normalization and prefix injection.
620
619
  const hasDashYear = /-\d{2}\b/.test(input);
621
- const result = buildTree(parseTree(input));
620
+ const result = buildTree(parseTree(input), resolveForeign);
622
621
  const self = result;
623
622
  if (hasDashYear && self["year_format"] === undefined) {
624
623
  self["year_format"] = "dash";
625
624
  }
626
625
  return result;
627
626
  }
628
- export function csaGrammarImplementation() {
627
+ export function csaGrammarImplementation(resolveForeign) {
629
628
  return {
630
629
  parse(input) {
631
- return parseCsa(input);
630
+ return parseCsa(input, resolveForeign);
632
631
  },
633
632
  };
634
633
  }
@@ -0,0 +1,3 @@
1
+ import type { FlavorImplementation } from "../../conformance/implementation.js";
2
+ import type { ForeignResolver } from "../foreign-resolver.js";
3
+ export declare function csaWorkerGrammarImplementation(foreign?: ForeignResolver): FlavorImplementation;
@@ -0,0 +1,17 @@
1
+ //! The worker entry for the csa flavor (pubid/pubid-ts#236): the same
2
+ //! implementation the node entry runs, with the adopted ISO/IEC
3
+ //! resolution wired to the worker-safe registry instead of the node
4
+ //! barrel. No `node:*` module appears in this graph and no wasm loads
5
+ //! — the csa grammar is the pure-TS parslet port, so the entry is
6
+ //! synchronous.
7
+ //!
8
+ //! import { csaWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/csa/worker.js";
9
+ //! const csa = csaWorkerGrammarImplementation();
10
+ //! csa.parse("CSA ISO/IEC 8824-1:22"); // adopted routing → worker iso/iec
11
+ //!
12
+ //! Pass a resolver to widen or narrow the foreign set.
13
+ import { workerForeignResolver } from "../worker-registry.js";
14
+ import { csaGrammarImplementation } from "./index.js";
15
+ export function csaWorkerGrammarImplementation(foreign) {
16
+ return csaGrammarImplementation(foreign ?? workerForeignResolver());
17
+ }
@@ -1,2 +1,3 @@
1
1
  import type { FlavorImplementation } from "../../conformance/implementation.js";
2
- export declare function evsGrammarImplementation(): FlavorImplementation;
2
+ import type { ForeignResolver } from "../foreign-resolver.js";
3
+ export declare function evsGrammarImplementation(resolveForeign: ForeignResolver): FlavorImplementation;
@@ -10,7 +10,7 @@ import { EstonianStandard, InternationalAdoption, NationalAdoption } from "./mod
10
10
  * is greedy over plain text and would swallow it).
11
11
  */
12
12
  const LANGUAGE_TAIL = / (et-en|et|en)$/;
13
- function buildIdentifier(tree, language) {
13
+ function buildIdentifier(tree, language, resolveForeign) {
14
14
  const d = Array.isArray(tree)
15
15
  ? Object.assign({}, ...tree)
16
16
  : tree;
@@ -28,7 +28,7 @@ function buildIdentifier(tree, language) {
28
28
  ? Object.fromEntries(Object.entries(adoptedData).filter(([k]) => k !== "type"))
29
29
  : adoptedData;
30
30
  id = new NationalAdoption({
31
- base: buildCenIdentifier(cenTree),
31
+ base: buildCenIdentifier(cenTree, resolveForeign),
32
32
  separator, draft_prefix: draft,
33
33
  });
34
34
  }
@@ -79,13 +79,13 @@ function attachSupplement(id, d) {
79
79
  id["cor_year"] = cor["cor_year"] !== undefined ? String(cor["cor_year"]) : undefined;
80
80
  }
81
81
  }
82
- export function evsGrammarImplementation() {
82
+ export function evsGrammarImplementation(resolveForeign) {
83
83
  return {
84
84
  parse(input) {
85
85
  const language = LANGUAGE_TAIL.exec(input)?.[1];
86
86
  const body = language !== undefined ? input.slice(0, input.length - language.length - 1) : input;
87
87
  const tree = parseGrammar(evsGrammar, body);
88
- return buildIdentifier(tree, language);
88
+ return buildIdentifier(tree, language, resolveForeign);
89
89
  },
90
90
  };
91
91
  }
@@ -0,0 +1,3 @@
1
+ import type { FlavorImplementation } from "../../conformance/implementation.js";
2
+ import type { ForeignResolver } from "../foreign-resolver.js";
3
+ export declare function evsWorkerGrammarImplementation(foreign?: ForeignResolver): FlavorImplementation;
@@ -0,0 +1,18 @@
1
+ //! The worker entry for the evs flavor (pubid/pubid-ts#236): the same
2
+ //! implementation the node entry runs — the EVS builder composes the
3
+ //! CEN/CENELEC one for the national adoptions — with the foreign
4
+ //! resolution wired to the worker-safe registry instead of the node
5
+ //! barrel. No `node:*` module appears in this graph and no wasm loads
6
+ //! — the evs grammar is the pure-TS parslet port, so the entry is
7
+ //! synchronous.
8
+ //!
9
+ //! import { evsWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/evs/worker.js";
10
+ //! const evs = evsWorkerGrammarImplementation();
11
+ //! evs.parse("EVS-EN ISO 14001:2026"); // adoption → worker cen → worker iso
12
+ //!
13
+ //! Pass a resolver to widen or narrow the foreign set.
14
+ import { workerForeignResolver } from "../worker-registry.js";
15
+ import { evsGrammarImplementation } from "./index.js";
16
+ export function evsWorkerGrammarImplementation(foreign) {
17
+ return evsGrammarImplementation(foreign ?? workerForeignResolver());
18
+ }
@@ -0,0 +1,6 @@
1
+ import type { FlavorImplementation } from "../conformance/implementation.js";
2
+ /** Resolve another flavor's grammar implementation, or undefined when
3
+ * the resolver's flavor set does not cover it (a worker resolver over
4
+ * the worker-available subset answers undefined for the parg-backed
5
+ * flavors it does not carry). */
6
+ export type ForeignResolver = (flavor: string) => FlavorImplementation | undefined;
@@ -0,0 +1,9 @@
1
+ //! The foreign-flavor resolution seam for the shared-builder flavors
2
+ //! (pubid/pubid-ts#236): bsi, cen_cenelec, csa, gost and evs route
3
+ //! adopted identifiers to other flavors' implementations. The node
4
+ //! barrel (src/flavors/index.ts) supplies the full central registry;
5
+ //! the worker entries supply the worker-safe subset
6
+ //! (src/flavors/worker-registry.ts). The type is dependency-free so
7
+ //! both sides — and the flavor modules themselves — can name it
8
+ //! without dragging either graph.
9
+ export {};
@@ -1,2 +1,3 @@
1
1
  import type { FlavorImplementation } from "../../conformance/implementation.js";
2
- export declare function gostGrammarImplementation(): FlavorImplementation;
2
+ import type { ForeignResolver } from "../foreign-resolver.js";
3
+ export declare function gostGrammarImplementation(resolveForeign: ForeignResolver): FlavorImplementation;
@@ -1,5 +1,4 @@
1
1
  import { parseGrammar } from "../../grammar/engine.js";
2
- import { grammarImplementation } from "../index.js";
3
2
  import { gostGrammar } from "./grammar.js";
4
3
  import { PREFIX_ROUTES } from "./prefix_routes.js";
5
4
  import { ForeignReference, Harmonized, IdenticalAdoption, InterstateStandard, NationalStandard, } from "./model.js";
@@ -37,10 +36,10 @@ const str = (v) => {
37
36
  function flatten(tree) {
38
37
  return Array.isArray(tree) ? Object.assign({}, ...tree) : tree;
39
38
  }
40
- function buildIdentifier(tree) {
41
- return buildFrom(flatten(tree));
39
+ function buildIdentifier(tree, resolveForeign) {
40
+ return buildFrom(flatten(tree), resolveForeign);
42
41
  }
43
- function buildFrom(d) {
42
+ function buildFrom(d, resolveForeign) {
44
43
  const russian = d["scope_r"] !== undefined;
45
44
  const [copublisher, subtype] = splitPrefix(str(d["prefix_text"]));
46
45
  const [number, year] = splitNumberYear(str(d["raw"]));
@@ -51,20 +50,20 @@ function buildFrom(d) {
51
50
  ...(number !== undefined ? { number } : {}),
52
51
  ...(year !== undefined ? { year } : {}),
53
52
  });
54
- return withForeignAdoption(base, d);
53
+ return withForeignAdoption(base, d, resolveForeign);
55
54
  }
56
- function withForeignAdoption(base, d) {
57
- return wrapHarmonized(wrapIdenticalAdoption(base, d), d);
55
+ function withForeignAdoption(base, d, resolveForeign) {
56
+ return wrapHarmonized(wrapIdenticalAdoption(base, d, resolveForeign), d, resolveForeign);
58
57
  }
59
- function wrapIdenticalAdoption(base, d) {
58
+ function wrapIdenticalAdoption(base, d, resolveForeign) {
60
59
  const adoptedRaw = str(d["adopted_raw"]);
61
60
  if (adoptedRaw === undefined)
62
61
  return base;
63
- const adopted = parseForeign(adoptedRaw);
62
+ const adopted = parseForeign(adoptedRaw, resolveForeign);
64
63
  const klass = IdenticalAdoption;
65
64
  return new klass({ base, adopted });
66
65
  }
67
- function wrapHarmonized(base, d) {
66
+ function wrapHarmonized(base, d, resolveForeign) {
68
67
  const referenceRaw = str(d["adopted_reference_raw"]);
69
68
  if (referenceRaw === undefined)
70
69
  return base;
@@ -72,12 +71,12 @@ function wrapHarmonized(base, d) {
72
71
  .split(",")
73
72
  .map((s) => s.trim())
74
73
  .map(normalizeForeign)
75
- .map(adoptIdentifier);
74
+ .map((raw) => adoptIdentifier(raw, resolveForeign));
76
75
  const klass = Harmonized;
77
76
  return new klass({ base, adoptedIdentifiers: adopted });
78
77
  }
79
- function adoptIdentifier(raw) {
80
- return parseForeign(raw) ?? new ForeignReference({ raw });
78
+ function adoptIdentifier(raw, resolveForeign) {
79
+ return parseForeign(raw, resolveForeign) ?? new ForeignReference({ raw });
81
80
  }
82
81
  function splitPrefix(text) {
83
82
  if (text === undefined)
@@ -130,8 +129,8 @@ function prefixOwner(raw) {
130
129
  const owners = PREFIX_ROUTES[match] ?? [];
131
130
  return owners.length === 1 ? owners[0] : undefined;
132
131
  }
133
- function tryParse(flavor, raw) {
134
- const impl = grammarImplementation(flavor);
132
+ function tryParse(flavor, raw, resolveForeign) {
133
+ const impl = resolveForeign(flavor);
135
134
  if (impl === undefined)
136
135
  return undefined;
137
136
  try {
@@ -141,25 +140,25 @@ function tryParse(flavor, raw) {
141
140
  return undefined;
142
141
  }
143
142
  }
144
- function parseForeign(raw) {
143
+ function parseForeign(raw, resolveForeign) {
145
144
  const owner = prefixOwner(raw);
146
145
  if (owner !== undefined) {
147
- const parsed = tryParse(owner, raw);
146
+ const parsed = tryParse(owner, raw, resolveForeign);
148
147
  if (parsed !== undefined)
149
148
  return parsed;
150
149
  }
151
150
  for (const flavor of FOREIGN_FALLBACK_ORDER) {
152
- const parsed = tryParse(flavor, raw);
151
+ const parsed = tryParse(flavor, raw, resolveForeign);
153
152
  if (parsed !== undefined)
154
153
  return parsed;
155
154
  }
156
155
  return undefined;
157
156
  }
158
- export function gostGrammarImplementation() {
157
+ export function gostGrammarImplementation(resolveForeign) {
159
158
  return {
160
159
  parse(input) {
161
160
  const tree = parseGrammar(gostGrammar, input.trim());
162
- return buildIdentifier(tree);
161
+ return buildIdentifier(tree, resolveForeign);
163
162
  },
164
163
  };
165
164
  }
@@ -0,0 +1,3 @@
1
+ import type { FlavorImplementation } from "../../conformance/implementation.js";
2
+ import type { ForeignResolver } from "../foreign-resolver.js";
3
+ export declare function gostWorkerGrammarImplementation(foreign?: ForeignResolver): FlavorImplementation;
@@ -0,0 +1,21 @@
1
+ //! The worker entry for the gost flavor (pubid/pubid-ts#236): the same
2
+ //! implementation the node entry runs, with the adopted-identifier
3
+ //! resolution wired to the worker-safe registry instead of the node
4
+ //! barrel. No `node:*` module appears in this graph and no wasm loads
5
+ //! — the gost grammar is the pure-TS parslet port, so the entry is
6
+ //! synchronous.
7
+ //!
8
+ //! import { gostWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/gost/worker.js";
9
+ //! const gost = gostWorkerGrammarImplementation();
10
+ //! gost.parse("GOST 31425.2-2025/ISO 9902-2:2001"); // adoption → worker iso
11
+ //!
12
+ //! The FOREIGN_FALLBACK_ORDER walk runs over the worker-available
13
+ //! flavors only — the honest answer in a worker, where the parg-backed
14
+ //! flavors have no worker implementation. Widen it by merging the parg
15
+ //! worker entries in: `workerForeignResolverWith({ ieee: await
16
+ //! ieeeWorkerGrammarImplementation(wasm) })` passed as the resolver.
17
+ import { workerForeignResolver } from "../worker-registry.js";
18
+ import { gostGrammarImplementation } from "./index.js";
19
+ export function gostWorkerGrammarImplementation(foreign) {
20
+ return gostGrammarImplementation(foreign ?? workerForeignResolver());
21
+ }
@@ -147,7 +147,7 @@ function grammarImplementationSwitch(flavor) {
147
147
  case "ieee":
148
148
  return ieeeGrammarImplementation();
149
149
  case "cen_cenelec":
150
- return cenCenelecGrammarImplementation();
150
+ return cenCenelecGrammarImplementation(grammarImplementation);
151
151
  case "cen_pfs":
152
152
  return cenPfsGrammarImplementation();
153
153
  case "astm":
@@ -155,17 +155,17 @@ function grammarImplementationSwitch(flavor) {
155
155
  case "idf":
156
156
  return idfGrammarImplementation();
157
157
  case "gost":
158
- return gostGrammarImplementation();
158
+ return gostGrammarImplementation(grammarImplementation);
159
159
  case "evs":
160
- return evsGrammarImplementation();
160
+ return evsGrammarImplementation(grammarImplementation);
161
161
  case "ashrae":
162
162
  return ashraeGrammarImplementation();
163
163
  case "bsi":
164
- return bsiGrammarImplementation();
164
+ return bsiGrammarImplementation(grammarImplementation);
165
165
  case "bsi_pfs":
166
166
  return bsiPfsGrammarImplementation();
167
167
  case "csa":
168
- return csaGrammarImplementation();
168
+ return csaGrammarImplementation(grammarImplementation);
169
169
  case "asme":
170
170
  return asmeGrammarImplementation();
171
171
  case "amca":
@@ -0,0 +1,13 @@
1
+ import type { FlavorImplementation } from "../conformance/implementation.js";
2
+ import type { ForeignResolver } from "./foreign-resolver.js";
3
+ /** The worker-available flavor implementations, wired to each other:
4
+ * every member's foreign lookups run over this same set (so bsi's
5
+ * adopted ISO routing, cen_cenelec's implicit IEC adoption and gost's
6
+ * fallback walk all resolve within the subset). */
7
+ export declare function workerForeignResolver(): ForeignResolver;
8
+ /** A resolver over an extended flavor set: the worker subset with the
9
+ * caller's additions merged over it (e.g. the parg-backed flavors via
10
+ * the worker entries #232 shipped — `nistWorkerGrammarImplementation` /
11
+ * `ieeeWorkerGrammarImplementation` — once the caller has awaited
12
+ * them). */
13
+ export declare function workerForeignResolverWith(extra: Record<string, FlavorImplementation>): ForeignResolver;
@@ -0,0 +1,120 @@
1
+ //! The worker-safe grammar registry for the shared-builder flavors
2
+ //! (pubid/pubid-ts#236): a `ForeignResolver` over the flavors whose
3
+ //! implementations carry no `node:*` module — the pure-TS parslet
4
+ //! ports plus the worker entries #232 shipped (oiml rides its worker
5
+ //! entry; iso and iec are parg-free node entries). This is what the
6
+ //! central barrel (`flavors/index.js`) CANNOT be in a worker: it
7
+ //! statically imports the parg-backed flavors (nist, ieee, ansi,
8
+ //! arxiv, doi_pfs, …), whose implementations reach
9
+ //! `parg/runtime.js` — a module scope that walks to a package.json
10
+ //! through `node:fs`.
11
+ //!
12
+ //! The five shared builders (bsi, cen_cenelec, csa, gost, evs) take a
13
+ //! `ForeignResolver` parameter for exactly this: the node barrel wires
14
+ //! the full central registry, the per-flavor worker entries wire this
15
+ //! subset. The gost-style fallback walks then run over the
16
+ //! worker-available flavors only — the honest answer for a worker,
17
+ //! where the parg-backed flavors have no worker implementation yet
18
+ //! (a consumer can inject them via their `*/worker.js` entries with
19
+ //! `workerForeignResolverWith`).
20
+ //!
21
+ //! No `node:*` module and nothing beyond relative imports appears in
22
+ //! this graph — pinned by `test/worker-graph.test.ts`.
23
+ import { oimlWorkerGrammarImplementation } from "./oiml/worker.js";
24
+ import { xsfGrammarImplementation } from "./xsf/index.js";
25
+ import { doiGrammarImplementation } from "./doi/index.js";
26
+ import { ianaGrammarImplementation } from "./iana/index.js";
27
+ import { unGrammarImplementation } from "./un/index.js";
28
+ import { plateauGrammarImplementation } from "./plateau/index.js";
29
+ import { w3cGrammarImplementation } from "./w3c/index.js";
30
+ import { omgGrammarImplementation } from "./omg/index.js";
31
+ import { ogcGrammarImplementation } from "./ogc/index.js";
32
+ import { isbnGrammarImplementation } from "./isbn/index.js";
33
+ import { eascGrammarImplementation } from "./easc/index.js";
34
+ import { ecmaGrammarImplementation } from "./ecma/index.js";
35
+ import { tgppGrammarImplementation } from "./tgpp/index.js";
36
+ import { oasisGrammarImplementation } from "./oasis/index.js";
37
+ import { ihoGrammarImplementation } from "./iho/index.js";
38
+ import { calconnectGrammarImplementation } from "./calconnect/index.js";
39
+ import { gbGrammarImplementation } from "./gb/index.js";
40
+ import { jcgmGrammarImplementation } from "./jcgm/index.js";
41
+ import { etsiGrammarImplementation } from "./etsi/index.js";
42
+ import { jisGrammarImplementation } from "./jis/index.js";
43
+ import { iecGrammarImplementation } from "./iec/index.js";
44
+ import { cieGrammarImplementation } from "./cie/index.js";
45
+ import { bipmGrammarImplementation } from "./bipm/index.js";
46
+ import { isoGrammarImplementation } from "./iso/index.js";
47
+ import { cenCenelecGrammarImplementation } from "./cen_cenelec/index.js";
48
+ import { astmGrammarImplementation } from "./astm/index.js";
49
+ import { idfGrammarImplementation } from "./idf/index.js";
50
+ import { gostGrammarImplementation } from "./gost/index.js";
51
+ import { evsGrammarImplementation } from "./evs/index.js";
52
+ import { ashraeGrammarImplementation } from "./ashrae/index.js";
53
+ import { bsiGrammarImplementation } from "./bsi/index.js";
54
+ import { csaGrammarImplementation } from "./csa/index.js";
55
+ import { asmeGrammarImplementation } from "./asme/index.js";
56
+ import { amcaGrammarImplementation } from "./amca/index.js";
57
+ import { apiGrammarImplementation } from "./api/index.js";
58
+ import { ituGrammarImplementation } from "./itu/index.js";
59
+ import { ietfGrammarImplementation } from "./ietf/index.js";
60
+ import { ialaGrammarImplementation } from "./iala/index.js";
61
+ /** The worker-available flavor implementations, wired to each other:
62
+ * every member's foreign lookups run over this same set (so bsi's
63
+ * adopted ISO routing, cen_cenelec's implicit IEC adoption and gost's
64
+ * fallback walk all resolve within the subset). */
65
+ export function workerForeignResolver() {
66
+ // The self-referencing wire: the resolver closes over the map, the
67
+ // shared builders receive the resolver, resolution happens at parse
68
+ // time.
69
+ const resolve = (flavor) => map[flavor];
70
+ const map = {
71
+ oiml: oimlWorkerGrammarImplementation(),
72
+ xsf: xsfGrammarImplementation(),
73
+ doi: doiGrammarImplementation(),
74
+ iana: ianaGrammarImplementation(),
75
+ un: unGrammarImplementation(),
76
+ plateau: plateauGrammarImplementation(),
77
+ w3c: w3cGrammarImplementation(),
78
+ omg: omgGrammarImplementation(),
79
+ ogc: ogcGrammarImplementation(),
80
+ isbn: isbnGrammarImplementation(),
81
+ easc: eascGrammarImplementation(),
82
+ ecma: ecmaGrammarImplementation(),
83
+ tgpp: tgppGrammarImplementation(),
84
+ oasis: oasisGrammarImplementation(),
85
+ iho: ihoGrammarImplementation(),
86
+ calconnect: calconnectGrammarImplementation(),
87
+ gb: gbGrammarImplementation(),
88
+ jcgm: jcgmGrammarImplementation(),
89
+ etsi: etsiGrammarImplementation(),
90
+ jis: jisGrammarImplementation(),
91
+ iec: iecGrammarImplementation(),
92
+ cie: cieGrammarImplementation(),
93
+ bipm: bipmGrammarImplementation(),
94
+ iso: isoGrammarImplementation(),
95
+ cen_cenelec: cenCenelecGrammarImplementation(resolve),
96
+ astm: astmGrammarImplementation(),
97
+ idf: idfGrammarImplementation(),
98
+ gost: gostGrammarImplementation(resolve),
99
+ evs: evsGrammarImplementation(resolve),
100
+ ashrae: ashraeGrammarImplementation(),
101
+ bsi: bsiGrammarImplementation(resolve),
102
+ csa: csaGrammarImplementation(resolve),
103
+ asme: asmeGrammarImplementation(),
104
+ amca: amcaGrammarImplementation(),
105
+ api: apiGrammarImplementation(),
106
+ itu: ituGrammarImplementation(),
107
+ ietf: ietfGrammarImplementation(),
108
+ iala: ialaGrammarImplementation(),
109
+ };
110
+ return resolve;
111
+ }
112
+ /** A resolver over an extended flavor set: the worker subset with the
113
+ * caller's additions merged over it (e.g. the parg-backed flavors via
114
+ * the worker entries #232 shipped — `nistWorkerGrammarImplementation` /
115
+ * `ieeeWorkerGrammarImplementation` — once the caller has awaited
116
+ * them). */
117
+ export function workerForeignResolverWith(extra) {
118
+ const base = workerForeignResolver();
119
+ return (flavor) => extra[flavor] ?? base(flavor);
120
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubid/pubid",
3
- "version": "0.1.70",
3
+ "version": "0.1.71",
4
4
  "description": "TypeScript PubID identifiers: resolution, normalization and canonical hashes for every identifier in the pubid-testsuite corpus (41 standards bodies), with a conformance runner mirroring the Ruby reference",
5
5
  "type": "module",
6
6
  "license": "MIT",