@pubid/pubid 0.1.69 → 0.1.70
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 +75 -1
- 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 +1 -1
- 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/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,89 @@ 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
|
+
A Cloudflare Worker consumes them like this (`relaton-api-js`'s
|
|
196
|
+
`engine.ts`; `NO_WORKER_ENGINE = {nist, ieee, oiml}` dissolves). The
|
|
197
|
+
wasm argument is whatever `parsanol/browser`'s `initialize()` takes —
|
|
198
|
+
URL (the lazy path: a one-time R2/CDN fetch on the first parse), a
|
|
199
|
+
CompiledWasm module (bundled), or raw bytes:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
// Lazy (the ~2.7 MB wasm fetches once, on the first nist/ieee entry call):
|
|
203
|
+
const WASM_URL = "https://assets.example.com/parsanol/parsanol_bg.wasm";
|
|
204
|
+
|
|
205
|
+
import { nistWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/nist/worker.js";
|
|
206
|
+
import { ieeeWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/ieee/worker.js";
|
|
207
|
+
import { oimlWorkerGrammarImplementation } from "@pubid/pubid/dist/flavors/oiml/worker.js";
|
|
208
|
+
|
|
209
|
+
const nist = await nistWorkerGrammarImplementation(WASM_URL);
|
|
210
|
+
const ieee = await ieeeWorkerGrammarImplementation({ wasm: WASM_URL });
|
|
211
|
+
const oiml = oimlWorkerGrammarImplementation(); // sync — no wasm at all
|
|
212
|
+
|
|
213
|
+
nist.parse("NIST SP 800-53r5");
|
|
214
|
+
ieee.parse("IEEE Std 802.3-2022");
|
|
215
|
+
oiml.parse("OIML R 49-1:2024"); // and "ISO 4064-1:2024|OIML R 49-1:2024"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Bundled instead of fetched: vendor the wasm (its `exports` map does not
|
|
219
|
+
expose the vendored file as a subpath, so copy
|
|
220
|
+
`node_modules/parsanol/vendor/parsanol-web/parsanol_bg.wasm` into your
|
|
221
|
+
repo) and declare wrangler's CompiledWasm rule:
|
|
222
|
+
|
|
223
|
+
```toml
|
|
224
|
+
# wrangler.toml — workerd compiles it at bundle load, no dynamic codegen:
|
|
225
|
+
rules = [{ type = "CompiledWasm", globs = ["**/parsanol_bg.wasm"], fallthrough = true }]
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
import parsanolWasm from "../vendor/parsanol_bg.wasm"; // WebAssembly.Module
|
|
230
|
+
const nist = await nistWorkerGrammarImplementation(parsanolWasm);
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
The ieee worker entry routes its co-published iec side
|
|
234
|
+
through the parg-free iec implementation; the ansi side has no worker
|
|
235
|
+
implementation yet and rejects with the same "ANSI implementation
|
|
236
|
+
unavailable" the node router produces for an unknown flavor — inject
|
|
237
|
+
your own via `ieeeWorkerGrammarImplementation({ coPublished })`.
|
|
238
|
+
|
|
239
|
+
The receipts are pinned in CI: `npm run test:worker` runs
|
|
240
|
+
`test/worker/worker-parse.test.ts` inside workerd with NO
|
|
241
|
+
`nodejs_compat` (vitest-pool-workers), and `worker-graph.test.ts`
|
|
242
|
+
walks the compiled import graphs (no `node:*` module, nothing beyond
|
|
243
|
+
`parsanol/browser`) and bundles every entry with
|
|
244
|
+
`esbuild --platform=neutral` and no node externals.
|
|
245
|
+
|
|
173
246
|
## Development
|
|
174
247
|
|
|
175
248
|
```sh
|
|
176
249
|
npm ci
|
|
177
250
|
npm test # builds + runs the corpus harness tests
|
|
251
|
+
npm run test:worker # the worker gate: parse inside workerd, no nodejs_compat
|
|
178
252
|
npm run conformance # prints the quadrant report for the pinned corpus
|
|
179
253
|
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Tree } from "../../grammar/engine.js";
|
|
2
|
+
import type { FlavorImplementation, Identifier } from "../../conformance/implementation.js";
|
|
3
|
+
export interface IeeeParseDeps {
|
|
4
|
+
/** The artifact engine's bound-parse (the parseAndBind contract). */
|
|
5
|
+
parseAndBind(input: string): unknown;
|
|
6
|
+
/** The co-published side resolver ("iec", "ansi"); undefined when
|
|
7
|
+
* the flavor is unavailable in the current environment. */
|
|
8
|
+
coPublished(flavor: string): FlavorImplementation | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface IeeeParseEngine {
|
|
11
|
+
parseSource(input: string): Tree;
|
|
12
|
+
coPublished(flavor: string): FlavorImplementation | undefined;
|
|
13
|
+
}
|
|
14
|
+
export declare function makeIeeeParseEngine(deps: IeeeParseDeps): IeeeParseEngine;
|
|
15
|
+
export declare function ieeeParseImpl(env: IeeeParseEngine, input: string): Identifier;
|
|
16
|
+
export declare function makeIeeeGrammarImplementation(env: IeeeParseEngine): FlavorImplementation;
|