@pubid/pubid 0.1.69 → 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 +123 -1
- package/dist/flavors/bsi/index.d.ts +3 -2
- package/dist/flavors/bsi/index.js +43 -42
- package/dist/flavors/bsi/worker.d.ts +3 -0
- package/dist/flavors/bsi/worker.js +18 -0
- package/dist/flavors/cen_cenelec/index.d.ts +3 -2
- package/dist/flavors/cen_cenelec/index.js +14 -8
- package/dist/flavors/cen_cenelec/worker.d.ts +3 -0
- package/dist/flavors/cen_cenelec/worker.js +17 -0
- package/dist/flavors/csa/index.d.ts +2 -1
- package/dist/flavors/csa/index.js +27 -28
- package/dist/flavors/csa/worker.d.ts +3 -0
- package/dist/flavors/csa/worker.js +17 -0
- package/dist/flavors/evs/index.d.ts +2 -1
- package/dist/flavors/evs/index.js +4 -4
- package/dist/flavors/evs/worker.d.ts +3 -0
- package/dist/flavors/evs/worker.js +18 -0
- package/dist/flavors/foreign-resolver.d.ts +6 -0
- package/dist/flavors/foreign-resolver.js +9 -0
- package/dist/flavors/gost/index.d.ts +2 -1
- package/dist/flavors/gost/index.js +19 -20
- package/dist/flavors/gost/worker.d.ts +3 -0
- package/dist/flavors/gost/worker.js +21 -0
- package/dist/flavors/ieee/artifact_tree.js +1 -1
- package/dist/flavors/ieee/implementation.d.ts +16 -0
- package/dist/flavors/ieee/implementation.js +2195 -0
- package/dist/flavors/ieee/index.js +18 -2181
- package/dist/flavors/ieee/worker.d.ts +7 -0
- package/dist/flavors/ieee/worker.js +31 -0
- package/dist/flavors/index.js +6 -6
- package/dist/flavors/nist/implementation.d.ts +5 -0
- package/dist/flavors/nist/implementation.js +1326 -0
- package/dist/flavors/nist/index.js +14 -1330
- package/dist/flavors/nist/worker.d.ts +3 -0
- package/dist/flavors/nist/worker.js +24 -0
- package/dist/flavors/oiml/implementation.d.ts +2 -1
- package/dist/flavors/oiml/implementation.js +2 -3
- package/dist/flavors/oiml/index.d.ts +2 -0
- package/dist/flavors/oiml/index.js +10 -0
- package/dist/flavors/oiml/worker.d.ts +2 -0
- package/dist/flavors/oiml/worker.js +14 -0
- package/dist/flavors/worker-registry.d.ts +13 -0
- package/dist/flavors/worker-registry.js +120 -0
- package/dist/parg/artifacts/ieee.d.ts +2 -0
- package/dist/parg/artifacts/ieee.js +5 -0
- package/dist/parg/artifacts/nist.d.ts +2 -0
- package/dist/parg/artifacts/nist.js +5 -0
- package/dist/parg/runtime.d.ts +1 -13
- package/dist/parg/runtime.js +4 -36
- package/dist/parg/shape.d.ts +13 -0
- package/dist/parg/shape.js +39 -0
- package/dist/parg/worker.d.ts +9 -0
- package/dist/parg/worker.js +32 -0
- package/dist/register-types.d.ts +7 -1
- package/dist/register-types.js +7 -1
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -165,15 +165,137 @@ With the manifest loaded, `PubidUrn.fromSlug` covers all 41 flavors
|
|
|
165
165
|
that resolve identifier types (nist, ieee and oiml included — the three
|
|
166
166
|
the barrel could not reach from a worker). `grammarImplementation`
|
|
167
167
|
(open-ended parse routing) deliberately stays behind the node-only
|
|
168
|
-
barrel:
|
|
168
|
+
barrel: the barrel as a whole still carries the node-only parg runtime
|
|
169
|
+
for the ten other artifact-backed flavors. The invariants are pinned by
|
|
169
170
|
`test/register-types.test.ts`: the manifest registers exactly the
|
|
170
171
|
barrel's type set, and no node-only module is reachable from the worker
|
|
171
172
|
entry's import graph.
|
|
172
173
|
|
|
174
|
+
## Worker-safe parse: nist / ieee / oiml (pubid-ts#232)
|
|
175
|
+
|
|
176
|
+
The three flavors the barrel could not serve in a worker now ship
|
|
177
|
+
dedicated worker entries with no `node:*` module in their import graph:
|
|
178
|
+
|
|
179
|
+
- **nist / ieee** run the baked PARG artifact over parsanol's wasm
|
|
180
|
+
engine. Their implementations are environment-agnostic; the node
|
|
181
|
+
entries (`dist/flavors/<flavor>/index.js`) keep the lazy `node:fs`
|
|
182
|
+
artifact load they always had (zero regression), while the worker
|
|
183
|
+
entries build the same implementations over `parsanol/browser` and
|
|
184
|
+
the artifact bundled at build time (`dist/parg/artifacts/` — the same
|
|
185
|
+
checksummed payloads `vendor/parg/` ships, re-emitted by
|
|
186
|
+
`npm run artifact` so the two cannot drift). The ~2.7 MB wasm loads
|
|
187
|
+
lazily on the first entry call, once per isolate; the parse calls
|
|
188
|
+
themselves stay synchronous.
|
|
189
|
+
- **oiml** never needed the artifact — its grammar is the pure-TS
|
|
190
|
+
parslet port. It lacked a flavor index; it now has one
|
|
191
|
+
(`dist/flavors/oiml/index.js`, the node barrel surface), and the
|
|
192
|
+
worker entry routes its co-published ISO side to the parg-free iso
|
|
193
|
+
implementation. No wasm at all.
|
|
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
|
+
|
|
241
|
+
A Cloudflare Worker consumes them like this (`relaton-api-js`'s
|
|
242
|
+
`engine.ts`; `NO_WORKER_ENGINE = {nist, ieee, oiml}` dissolves). The
|
|
243
|
+
wasm argument is whatever `parsanol/browser`'s `initialize()` takes —
|
|
244
|
+
URL (the lazy path: a one-time R2/CDN fetch on the first parse), a
|
|
245
|
+
CompiledWasm module (bundled), or raw bytes:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
// Lazy (the ~2.7 MB wasm fetches once, on the first nist/ieee entry call):
|
|
249
|
+
const WASM_URL = "https://assets.example.com/parsanol/parsanol_bg.wasm";
|
|
250
|
+
|
|
251
|
+
import { nistWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/nist/worker.js";
|
|
252
|
+
import { ieeeWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/ieee/worker.js";
|
|
253
|
+
import { oimlWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/oiml/worker.js";
|
|
254
|
+
|
|
255
|
+
const nist = await nistWorkerGrammarImplementation(WASM_URL);
|
|
256
|
+
const ieee = await ieeeWorkerGrammarImplementation({ wasm: WASM_URL });
|
|
257
|
+
const oiml = oimlWorkerGrammarImplementation(); // sync — no wasm at all
|
|
258
|
+
|
|
259
|
+
nist.parse("NIST SP 800-53r5");
|
|
260
|
+
ieee.parse("IEEE Std 802.3-2022");
|
|
261
|
+
oiml.parse("OIML R 49-1:2024"); // and "ISO 4064-1:2024|OIML R 49-1:2024"
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Bundled instead of fetched: vendor the wasm (its `exports` map does not
|
|
265
|
+
expose the vendored file as a subpath, so copy
|
|
266
|
+
`node_modules/parsanol/vendor/parsanol-web/parsanol_bg.wasm` into your
|
|
267
|
+
repo) and declare wrangler's CompiledWasm rule:
|
|
268
|
+
|
|
269
|
+
```toml
|
|
270
|
+
# wrangler.toml — workerd compiles it at bundle load, no dynamic codegen:
|
|
271
|
+
rules = [{ type = "CompiledWasm", globs = ["**/parsanol_bg.wasm"], fallthrough = true }]
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
```ts
|
|
275
|
+
import parsanolWasm from "../vendor/parsanol_bg.wasm"; // WebAssembly.Module
|
|
276
|
+
const nist = await nistWorkerGrammarImplementation(parsanolWasm);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
The ieee worker entry routes its co-published iec side
|
|
280
|
+
through the parg-free iec implementation; the ansi side has no worker
|
|
281
|
+
implementation yet and rejects with the same "ANSI implementation
|
|
282
|
+
unavailable" the node router produces for an unknown flavor — inject
|
|
283
|
+
your own via `ieeeWorkerGrammarImplementation({ coPublished })`.
|
|
284
|
+
|
|
285
|
+
The receipts are pinned in CI: `npm run test:worker` runs
|
|
286
|
+
`test/worker/worker-parse.test.ts` inside workerd with NO
|
|
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`
|
|
290
|
+
walks the compiled import graphs (no `node:*` module, nothing beyond
|
|
291
|
+
`parsanol/browser`) and bundles every entry with
|
|
292
|
+
`esbuild --platform=neutral` and no node externals.
|
|
293
|
+
|
|
173
294
|
## Development
|
|
174
295
|
|
|
175
296
|
```sh
|
|
176
297
|
npm ci
|
|
177
298
|
npm test # builds + runs the corpus harness tests
|
|
299
|
+
npm run test:worker # the worker gate: parse inside workerd, no nodejs_compat
|
|
178
300
|
npm run conformance # prints the quadrant report for the pinned corpus
|
|
179
301
|
```
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Tree } from "../../grammar/engine.js";
|
|
2
2
|
import type { FlavorImplementation, Identifier } from "../../conformance/implementation.js";
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
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 =
|
|
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 =
|
|
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,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 =
|
|
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 =
|
|
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 =
|
|
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,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
|
-
|
|
2
|
+
import type { ForeignResolver } from "../foreign-resolver.js";
|
|
3
|
+
export declare function csaGrammarImplementation(resolveForeign: ForeignResolver): FlavorImplementation;
|