@pubid/pubid 0.1.68 → 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/iec/model.d.ts +46 -0
- package/dist/flavors/iec/model.js +224 -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 +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/dist/parg/runtime.d.ts
CHANGED
|
@@ -10,16 +10,4 @@ export declare class PubidRuntime extends EngineRuntime {
|
|
|
10
10
|
static artifactsDir(): string;
|
|
11
11
|
static load(grammar: string, entry?: string): EngineRuntime;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
* The artifact emits capture leaves ({value, line, column, offset,
|
|
15
|
-
* length}) and a top-level sequence of capture hashes. This mirrors the
|
|
16
|
-
* gem's Pubid::Parg::Backend.to_builder_hash: scalarize leaves, fold the
|
|
17
|
-
* top-level list into one hash (last key wins — parslet's sequence fold).
|
|
18
|
-
*/
|
|
19
|
-
export declare function toBuilderTree(shape: unknown): unknown;
|
|
20
|
-
/**
|
|
21
|
-
* Strip the shape metadata an artifact parse carries (offset/line/column
|
|
22
|
-
* wrappers) down to the plain string/array capture tree the builders
|
|
23
|
-
* consume — the same tree shape the hand-written grammars produced.
|
|
24
|
-
*/
|
|
25
|
-
export declare function normalizeShape(node: unknown): unknown;
|
|
13
|
+
export { toBuilderTree, normalizeShape } from "./shape.js";
|
package/dist/parg/runtime.js
CHANGED
|
@@ -38,39 +38,7 @@ export class PubidRuntime extends EngineRuntime {
|
|
|
38
38
|
return EngineRuntime.fromFile(join(artifactsDir(), `${grammar}.json`), entry);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
* top-level list into one hash (last key wins — parslet's sequence fold).
|
|
46
|
-
*/
|
|
47
|
-
export function toBuilderTree(shape) {
|
|
48
|
-
const normalized = normalizeShape(shape);
|
|
49
|
-
if (Array.isArray(normalized) &&
|
|
50
|
-
normalized.length > 0 &&
|
|
51
|
-
normalized.every((n) => typeof n === "object" && n !== null && !Array.isArray(n))) {
|
|
52
|
-
return Object.assign({}, ...normalized);
|
|
53
|
-
}
|
|
54
|
-
return normalized;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Strip the shape metadata an artifact parse carries (offset/line/column
|
|
58
|
-
* wrappers) down to the plain string/array capture tree the builders
|
|
59
|
-
* consume — the same tree shape the hand-written grammars produced.
|
|
60
|
-
*/
|
|
61
|
-
export function normalizeShape(node) {
|
|
62
|
-
if (Array.isArray(node))
|
|
63
|
-
return node.map(normalizeShape);
|
|
64
|
-
if (typeof node === "object" && node !== null) {
|
|
65
|
-
const rec = node;
|
|
66
|
-
if (typeof rec["value"] === "string" && Object.keys(rec).length >= 1 &&
|
|
67
|
-
"offset" in rec) {
|
|
68
|
-
return rec["value"];
|
|
69
|
-
}
|
|
70
|
-
const out = {};
|
|
71
|
-
for (const [k, v] of Object.entries(rec))
|
|
72
|
-
out[k] = normalizeShape(v);
|
|
73
|
-
return out;
|
|
74
|
-
}
|
|
75
|
-
return node;
|
|
76
|
-
}
|
|
41
|
+
// The shape helpers are pure and shared with the worker entries
|
|
42
|
+
// (pubid-ts#232): re-exported here so every existing node import keeps
|
|
43
|
+
// resolving.
|
|
44
|
+
export { toBuilderTree, normalizeShape } from "./shape.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The artifact emits capture leaves ({value, line, column, offset,
|
|
3
|
+
* length}) and a top-level sequence of capture hashes. This mirrors the
|
|
4
|
+
* gem's Pubid::Parg::Backend.to_builder_hash: scalarize leaves, fold the
|
|
5
|
+
* top-level list into one hash (last key wins — parslet's sequence fold).
|
|
6
|
+
*/
|
|
7
|
+
export declare function toBuilderTree(shape: unknown): unknown;
|
|
8
|
+
/**
|
|
9
|
+
* Strip the shape metadata an artifact parse carries (offset/line/column
|
|
10
|
+
* wrappers) down to the plain string/array capture tree the builders
|
|
11
|
+
* consume — the same tree shape the hand-written grammars produced.
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeShape(node: unknown): unknown;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//! The pure artifact-shape helpers shared by every artifact-backed
|
|
2
|
+
//! flavor and by the worker entries. No node import may appear here:
|
|
3
|
+
//! these run inside the worker-safe graphs (pubid/pubid-ts#232).
|
|
4
|
+
/**
|
|
5
|
+
* The artifact emits capture leaves ({value, line, column, offset,
|
|
6
|
+
* length}) and a top-level sequence of capture hashes. This mirrors the
|
|
7
|
+
* gem's Pubid::Parg::Backend.to_builder_hash: scalarize leaves, fold the
|
|
8
|
+
* top-level list into one hash (last key wins — parslet's sequence fold).
|
|
9
|
+
*/
|
|
10
|
+
export function toBuilderTree(shape) {
|
|
11
|
+
const normalized = normalizeShape(shape);
|
|
12
|
+
if (Array.isArray(normalized) &&
|
|
13
|
+
normalized.length > 0 &&
|
|
14
|
+
normalized.every((n) => typeof n === "object" && n !== null && !Array.isArray(n))) {
|
|
15
|
+
return Object.assign({}, ...normalized);
|
|
16
|
+
}
|
|
17
|
+
return normalized;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Strip the shape metadata an artifact parse carries (offset/line/column
|
|
21
|
+
* wrappers) down to the plain string/array capture tree the builders
|
|
22
|
+
* consume — the same tree shape the hand-written grammars produced.
|
|
23
|
+
*/
|
|
24
|
+
export function normalizeShape(node) {
|
|
25
|
+
if (Array.isArray(node))
|
|
26
|
+
return node.map(normalizeShape);
|
|
27
|
+
if (typeof node === "object" && node !== null) {
|
|
28
|
+
const rec = node;
|
|
29
|
+
if (typeof rec["value"] === "string" && Object.keys(rec).length >= 1 &&
|
|
30
|
+
"offset" in rec) {
|
|
31
|
+
return rec["value"];
|
|
32
|
+
}
|
|
33
|
+
const out = {};
|
|
34
|
+
for (const [k, v] of Object.entries(rec))
|
|
35
|
+
out[k] = normalizeShape(v);
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
return node;
|
|
39
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { initialize, PargRuntime } from "parsanol/browser";
|
|
2
|
+
export type WorkerWasmInput = Parameters<typeof initialize>[0];
|
|
3
|
+
declare const bundledArtifacts: Record<string, string>;
|
|
4
|
+
export type WorkerPargGrammar = keyof typeof bundledArtifacts;
|
|
5
|
+
/** Initialize the browser engine once per isolate (the lazy ~2.4 MB wasm). */
|
|
6
|
+
export declare function initWorkerEngine(wasm?: WorkerWasmInput): Promise<void>;
|
|
7
|
+
/** The artifact-backed runtime for one grammar over the browser engine. */
|
|
8
|
+
export declare function workerPargRuntime(grammar: WorkerPargGrammar, wasm?: WorkerWasmInput): Promise<PargRuntime>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//! The worker-side PARG engine (pubid/pubid-ts#232): the baked
|
|
2
|
+
//! artifacts ship as bundled module strings (src/parg/artifacts/,
|
|
3
|
+
//! generated from vendor/parg by `npm run artifact:emit`) and the
|
|
4
|
+
//! engine is parsanol's browser build — no node:fs anywhere in this
|
|
5
|
+
//! graph. The wasm is loaded lazily on the first runtime request: a
|
|
6
|
+
//! flavor that never parses in a worker never pays the ~2.4 MB engine
|
|
7
|
+
//! cost. `initialize()` fetches the wasm per parsanol/browser's
|
|
8
|
+
//! bundler contract (the glue resolves `parsanol_bg.wasm` beside
|
|
9
|
+
//! itself); Workers bundles pass a CompiledWasm module or a URL
|
|
10
|
+
//! instead via the `wasm` argument.
|
|
11
|
+
import { initialize, PargRuntime } from "parsanol/browser";
|
|
12
|
+
import nistArtifact from "./artifacts/nist.js";
|
|
13
|
+
import ieeeArtifact from "./artifacts/ieee.js";
|
|
14
|
+
const bundledArtifacts = {
|
|
15
|
+
nist: nistArtifact,
|
|
16
|
+
ieee: ieeeArtifact,
|
|
17
|
+
};
|
|
18
|
+
let enginePromise;
|
|
19
|
+
/** Initialize the browser engine once per isolate (the lazy ~2.4 MB wasm). */
|
|
20
|
+
export function initWorkerEngine(wasm) {
|
|
21
|
+
enginePromise ??= initialize(wasm);
|
|
22
|
+
return enginePromise;
|
|
23
|
+
}
|
|
24
|
+
/** The artifact-backed runtime for one grammar over the browser engine. */
|
|
25
|
+
export async function workerPargRuntime(grammar, wasm) {
|
|
26
|
+
await initWorkerEngine(wasm);
|
|
27
|
+
const artifact = bundledArtifacts[grammar];
|
|
28
|
+
if (artifact === undefined) {
|
|
29
|
+
throw new Error(`no bundled PARG artifact for "${grammar}" (worker graph, pubid-ts#232)`);
|
|
30
|
+
}
|
|
31
|
+
return new PargRuntime(artifact);
|
|
32
|
+
}
|
package/dist/register-types.d.ts
CHANGED
|
@@ -17,7 +17,13 @@
|
|
|
17
17
|
*
|
|
18
18
|
* covers every flavor in a worker. The grammar-backed
|
|
19
19
|
* `grammarImplementation` (open-ended parse routing) deliberately stays
|
|
20
|
-
* behind the node-only barrel
|
|
20
|
+
* behind the node-only barrel — the barrel as a whole still carries the
|
|
21
|
+
* node-only parg runtime for the ten other artifact-backed flavors —
|
|
22
|
+
* but the three flavors it blocked for workers
|
|
23
|
+
* ship dedicated worker entries now (pubid/pubid-ts#232):
|
|
24
|
+
* `dist/flavors/nist/worker.js`, `dist/flavors/ieee/worker.js` and
|
|
25
|
+
* `dist/flavors/oiml/worker.js`, with no node-only module in their
|
|
26
|
+
* graphs.
|
|
21
27
|
*/
|
|
22
28
|
import "./flavors/register-types.js";
|
|
23
29
|
export * as PubidUrn from "./pubid-urn/index.js";
|
package/dist/register-types.js
CHANGED
|
@@ -17,7 +17,13 @@
|
|
|
17
17
|
*
|
|
18
18
|
* covers every flavor in a worker. The grammar-backed
|
|
19
19
|
* `grammarImplementation` (open-ended parse routing) deliberately stays
|
|
20
|
-
* behind the node-only barrel
|
|
20
|
+
* behind the node-only barrel — the barrel as a whole still carries the
|
|
21
|
+
* node-only parg runtime for the ten other artifact-backed flavors —
|
|
22
|
+
* but the three flavors it blocked for workers
|
|
23
|
+
* ship dedicated worker entries now (pubid/pubid-ts#232):
|
|
24
|
+
* `dist/flavors/nist/worker.js`, `dist/flavors/ieee/worker.js` and
|
|
25
|
+
* `dist/flavors/oiml/worker.js`, with no node-only module in their
|
|
26
|
+
* graphs.
|
|
21
27
|
*/
|
|
22
28
|
import "./flavors/register-types.js";
|
|
23
29
|
export * as PubidUrn from "./pubid-urn/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pubid/pubid",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.70",
|
|
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",
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "tsc -p tsconfig.json",
|
|
14
14
|
"test": "tsc -p tsconfig.test.json && node --test dist-test/test/*.test.js",
|
|
15
|
+
"test:worker": "vitest run --config vitest.worker.config.mts",
|
|
15
16
|
"conformance": "tsc -p tsconfig.json && node dist/conformance/cli.js",
|
|
16
17
|
"probe:urn": "node scripts/probe-pubid-urn.mjs",
|
|
17
18
|
"prepublishOnly": "tsc -p tsconfig.json",
|
|
18
19
|
"artifact": "tsc -p tsconfig.json && node scripts/build-artifact.mjs",
|
|
20
|
+
"artifact:emit": "node scripts/emit-parg-artifacts.mjs",
|
|
19
21
|
"doc:api": "node scripts/api-reference.mjs"
|
|
20
22
|
},
|
|
21
23
|
"dependencies": {
|
|
@@ -23,9 +25,12 @@
|
|
|
23
25
|
"yaml": "^2.5.0"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
28
|
+
"@cloudflare/vitest-pool-workers": "^0.23.0",
|
|
26
29
|
"@types/node": "^20.14.0",
|
|
30
|
+
"esbuild": "^0.28.2",
|
|
27
31
|
"typedoc": "^0.28.20",
|
|
28
|
-
"typescript": "^5.6.0"
|
|
32
|
+
"typescript": "^5.6.0",
|
|
33
|
+
"vitest": "^4.1.0"
|
|
29
34
|
},
|
|
30
35
|
"files": [
|
|
31
36
|
"dist",
|