@gmb/bitmark-parser 6.1.1 → 6.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../../../node_modules/tsup/assets/cjs_shims.js","../src/generated/package_info.ts","../src/core/hooked-transform.ts","../src/core/parallel.ts","../src/node/pool.ts","../src/node/transform-parallel.ts"],"sourcesContent":["// @zen-component: WASM-TSBindings\n\nimport { createRequire } from \"node:module\";\nimport { PACKAGE_INFO } from \"./generated/package_info.js\";\nimport { runHookedTransform, type HookedWasm } from \"./core/hooked-transform.js\";\nimport { runParallelTransform } from \"./node/transform-parallel.js\";\nimport type { LexOptions, ParseOptions, ConvertOptions, BreakscapeOptions, InfoOptions, NormalizeOptions, TransformOptions, BitSlice } from \"./types.js\";\nconst require = createRequire(import.meta.url);\nconst wasm = require(\"../wasm/bitmark_wasm.js\") as typeof import(\"../wasm/bitmark_wasm.js\");\n\nexport type { LexOptions, LexStage, ParseOptions, ConvertOptions, OutputMode, BreakscapeOptions, TextFormat, TextLocation, InfoOptions, InfoType, InfoFormat, InputFormat, OutputFormat, NormalizeOptions, TransformOptions, PatchOp, PatchEntry, BitSlice, BitView, PreHook, PostHook, PreHookResult } from \"./types.js\";\n\n/**\n * Get the version of the @gmb/bitmark-parser library.\n *\n * @returns Version string (e.g. \"3.0.0\").\n */\nexport function version(): string {\n return PACKAGE_INFO.version;\n}\n\n/**\n * Lex bitmark input text, returning one line per token.\n *\n * @param input - The bitmark source text.\n * @param options - Lex options (e.g. `{ stage: \"lex\" }`).\n * @returns Token dump string (one token per line).\n */\nexport function lex(input: string, options: LexOptions = {}): string {\n return wasm.lex(input, options.stage ?? \"lex\");\n}\n\n/**\n * Parse bitmark input text and return structured JSON entries.\n *\n * Each entry contains `bit`, `parser`, and `bitmark` fields.\n *\n * @param input - The bitmark source text.\n * @param options - Parse options (e.g. `{ mode: \"full\" }`).\n * @returns JSON string array of structured parsed entries.\n */\nexport function parse(input: string, options: ParseOptions = {}): string {\n return wasm.parse(input, options.mode ?? \"optimized\");\n}\n\n/**\n * Auto-detect input format and convert between bitmark and JSON.\n *\n * @param input - Bitmark or JSON input text.\n * @param options - Convert options (e.g. `{ mode: \"full\", warnings: true }`).\n * @returns Converted output string. For bitmark input, this is a JSON string\n * array of structured parsed entries (`bit`, `parser`, `bitmark`).\n */\nexport function convert(input: string, options: ConvertOptions = {}): string {\n return wasm.convert(\n input,\n options.inputFormat ?? \"auto\",\n options.outputFormat ?? \"auto\",\n options.mode ?? \"optimized\",\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Re-emit input in its own (auto-detected) format at optimized mode.\n *\n * @param input - Bitmark or JSON input text.\n * @returns Optimized output in the same format as the input.\n */\nexport function optimize(input: string, options: NormalizeOptions = {}): string {\n return wasm.optimize(input, options.pretty ?? false, options.indent ?? 2);\n}\n\n/**\n * Re-emit input in its own (auto-detected) format at full mode (all keys).\n * Aliased as {@link expand}.\n */\nexport function fullize(input: string, options: NormalizeOptions = {}): string {\n return wasm.fullize(input, options.pretty ?? false, options.indent ?? 2);\n}\n\n/** Alias of {@link fullize}. */\nexport const expand = fullize;\n\n/**\n * Re-emit input in its own (auto-detected) format in canonical form.\n */\nexport function canonicalize(input: string, options: NormalizeOptions = {}): string {\n return wasm.canonicalize(\n input,\n options.mode ?? \"optimized\",\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Count the bits in `input`, auto-detecting bitmark vs JSON.\n *\n * @throws If the input cannot be parsed.\n */\nexport function countBits(input: string): number {\n const out = wasm.count_bits(input);\n if (out.startsWith(\"error:\")) throw new Error(out);\n return Number.parseInt(out, 10);\n}\n\n/**\n * Split a bitmark document into per-bit source slices.\n *\n * @returns Array of `{ index, byteStart, byteEnd, source }`.\n */\nexport function splitBits(input: string): BitSlice[] {\n return JSON.parse(wasm.split_bits(input)) as BitSlice[];\n}\n\n/**\n * Transform a document bit-by-bit: apply an optional static `patch` and/or\n * per-bit `preHook`/`postHook`, then re-emit.\n *\n * With neither hook, the whole document is transformed in a single WASM pass\n * (the fast path). When a `preHook` or `postHook` is supplied, `transform`\n * drives the bits one at a time on the calling thread — the hook inspects each\n * bit, may return patches / an output-format override / `drop`, and only data\n * crosses into WASM. The patch may be an array of entries or a JSON string.\n *\n * @returns The transformed document, or an `error:`-prefixed string on failure.\n */\nexport function transform(input: string, options: TransformOptions = {}): string {\n if (options.preHook || options.postHook) {\n return runHookedTransform(wasm as unknown as HookedWasm, input, options);\n }\n const patchJson =\n options.patch === undefined\n ? \"\"\n : typeof options.patch === \"string\"\n ? options.patch\n : JSON.stringify(options.patch);\n return wasm.transform(\n input,\n options.inputFormat ?? \"auto\",\n options.outputFormat ?? \"json\",\n options.mode ?? \"optimized\",\n patchJson,\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Parallel counterpart of {@link transform} (Node only). Fans the per-bit WASM\n * compute across a `worker_threads` pool (`options.workers`, default `4`),\n * while `preHook`/`postHook` still run on the calling thread. Output is\n * identical to {@link transform}; this trades startup cost for throughput on\n * large documents.\n *\n * @returns A Promise of the transformed document, or an `error:`-prefixed\n * string on failure.\n */\nexport function transformParallel(input: string, options: TransformOptions = {}): Promise<string> {\n return runParallelTransform(wasm as unknown as HookedWasm, input, options);\n}\n\n/**\n * Breakscape text (escape bitmark special characters).\n *\n * @param input - The text to breakscape.\n * @param options - Breakscape options (e.g. `{ format: \"plainText\", location: \"tag\" }`).\n * @returns Breakscaped text.\n */\nexport function breakscapeText(input: string, options: BreakscapeOptions = {}): string {\n const format = options.format ?? \"bitmark++\";\n const location = options.location ?? \"body\";\n return wasm.breakscape_text(input, format, location);\n}\n\n/**\n * Unbreakscape text (unescape bitmark special characters).\n *\n * @param input - The text to unbreakscape.\n * @param options - Unbreakscape options (e.g. `{ format: \"plainText\", location: \"tag\" }`).\n * @returns Unbreakscaped text.\n */\nexport function unbreakscapeText(input: string, options: BreakscapeOptions = {}): string {\n const format = options.format ?? \"bitmark++\";\n const location = options.location ?? \"body\";\n return wasm.unbreakscape_text(input, format, location);\n}\n\n/**\n * Query information about supported bit types.\n *\n * @param options - Info options (e.g. `{ infoType: \"bit\", format: \"json\", bit: \"cloze\" }`).\n * @returns Information string.\n */\nexport function info(options: InfoOptions = {}): string {\n const infoType = options.infoType ?? \"list\";\n const format = options.format ?? \"text\";\n const bit = options.bit ?? \"\";\n const pretty = options.pretty ?? false;\n const indent = options.indent ?? 2;\n return wasm.info(infoType, format, bit, pretty, indent);\n}\n\n/**\n * Generate bitmark text from a JSON AST.\n *\n * The reverse pipeline: `JSON → json_to_ast → AST → ast_to_bitmark`.\n *\n * @param input - JSON string of the parsed bit entries (forward output shape).\n * @param options - Generate options (e.g. `{ mode: \"full\" }`).\n * @returns Bitmark text. On failure, an `error:`-prefixed string.\n */\nexport function generate(input: string, options: ParseOptions = {}): string {\n return wasm.convert(input, \"json\", \"bitmark\", options.mode ?? \"optimized\", false, 2, 1);\n}\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","// This file is automatically generated. DO NOT EDIT.\n\n/* eslint-disable */\n\nexport const PACKAGE_INFO = {\n \"name\": \"@gmb/bitmark-parser\",\n \"version\": \"6.1.1\",\n \"author\": \"Get More Brain Ltd <info@getmorebrain.com>\",\n \"license\": \"ISC\",\n \"description\": \"A parser for bitmark text, powered by WebAssembly.\"\n};\n","// @zen-component: TS-HookedTransform\n\nimport type { BitView, OutputFormat, PatchEntry, TransformOptions } from \"../types.js\";\n\n/**\n * The minimal WASM surface the per-bit hook driver needs. Both the Node and\n * browser entry points satisfy this with their loaded module.\n */\nexport interface HookedWasm {\n is_bitmark(input: string): boolean;\n split_bits(input: string): string;\n split_json_bits(input: string): string;\n prettify(json: string, indent: number): string;\n transform(\n input: string,\n inputFormat: string,\n outputFormat: string,\n mode: string,\n patchJson: string,\n pretty: boolean,\n indent: number,\n spacesAroundValues: number,\n ): string;\n}\n\n/** A single bit's compute job: data only, safe to ship to a worker thread. */\nexport interface BitJob {\n index: number;\n source: string;\n inputFormat: \"bitmark\" | \"json\";\n outputFormat: OutputFormat;\n mode: string;\n patchJson: string;\n spacesAroundValues: number;\n}\n\n/**\n * The result of running `preHook` over a document's bits: the compute `jobs`\n * for the bits that survived (in document order) and the matching `views`\n * (so `postHook` can be called per surviving bit), plus the document-level\n * recombination settings.\n */\nexport interface TransformPlan {\n jobs: BitJob[];\n views: BitView[];\n output: OutputFormat;\n pretty: boolean;\n indent: number;\n}\n\nexport function isError(s: string): boolean {\n return s.startsWith(\"error:\");\n}\n\n/**\n * Normalise a thrown value to an `error:`-prefixed string, without\n * double-prefixing a message that already carries the prefix (split helpers\n * surface WASM `error:` strings as thrown `Error`s).\n */\nexport function errorString(e: unknown): string {\n const m = e instanceof Error ? e.message : String(e);\n return m.startsWith(\"error:\") ? m : `error: ${m}`;\n}\n\n/** Strip the outer `[ … ]` of a compact one-element JSON array. */\nexport function stripArray(doc: string): string {\n const t = doc.trim();\n return t.startsWith(\"[\") && t.endsWith(\"]\") ? t.slice(1, -1) : doc;\n}\n\nfunction normalisePatch(patch: TransformOptions[\"patch\"]): PatchEntry[] {\n if (patch === undefined) return [];\n if (typeof patch === \"string\") {\n const trimmed = patch.trim();\n return trimmed === \"\" ? [] : (JSON.parse(trimmed) as PatchEntry[]);\n }\n return patch;\n}\n\nfunction buildUnits(\n wasm: HookedWasm,\n input: string,\n inputIsBitmark: boolean,\n): { view: BitView; source: string }[] {\n if (inputIsBitmark) {\n const out = wasm.split_bits(input);\n if (isError(out)) throw new Error(out);\n const slices = JSON.parse(out) as { index: number; source: string }[];\n return slices.map((s) => ({\n view: { format: \"bitmark\", index: s.index, total: slices.length, source: s.source },\n source: s.source,\n }));\n }\n const out = wasm.split_json_bits(input);\n if (isError(out)) throw new Error(out);\n const envelopes = JSON.parse(out) as { bit?: unknown }[];\n return envelopes.map((env, index) => ({\n view: { format: \"json\", index, total: envelopes.length, bit: env.bit },\n // Per-bit transform consumes a one-bit JSON document.\n source: JSON.stringify([env]),\n }));\n}\n\n/**\n * Split the document and run `preHook` (on the calling thread) for each bit,\n * producing the surviving compute jobs + their views. This is the main-thread\n * half shared by the sync and worker-pool drivers — only the resulting\n * data-only {@link BitJob}s ever cross to a worker.\n */\nexport function planTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): TransformPlan {\n const mode = options.mode ?? \"optimized\";\n const output: OutputFormat = options.outputFormat ?? \"json\";\n const spacesAroundValues = options.spacesAroundValues ?? 1;\n const indent = options.indent ?? 2;\n const pretty = options.pretty ?? false;\n\n const sel = options.inputFormat ?? \"auto\";\n const inputIsBitmark = sel === \"bitmark\" || (sel !== \"json\" && wasm.is_bitmark(input));\n const inputFormat = inputIsBitmark ? \"bitmark\" : \"json\";\n\n const staticPatch = normalisePatch(options.patch);\n const units = buildUnits(wasm, input, inputIsBitmark);\n const total = units.length;\n\n const jobs: BitJob[] = [];\n const views: BitView[] = [];\n for (let index = 0; index < total; index++) {\n const { view, source } = units[index];\n view.index = index;\n view.total = total;\n\n const result = options.preHook ? options.preHook(view) || {} : {};\n if (result.drop) continue;\n\n const patches = result.patches ? [...staticPatch, ...result.patches] : staticPatch;\n jobs.push({\n index,\n source,\n inputFormat,\n outputFormat: result.outputFormat ?? output,\n mode,\n patchJson: JSON.stringify(patches),\n spacesAroundValues,\n });\n views.push(view);\n }\n return { jobs, views, output, pretty, indent };\n}\n\n/**\n * Compute one bit's rendered element synchronously via WASM. The per-bit\n * element is always compact JSON (the document is prettified once on\n * recombination). Returns an `error:`-prefixed string on failure.\n */\nexport function computeBit(wasm: HookedWasm, job: BitJob): string {\n const out = wasm.transform(\n job.source,\n job.inputFormat,\n job.outputFormat,\n job.mode,\n job.patchJson,\n false,\n 2,\n job.spacesAroundValues,\n );\n if (isError(out)) return out;\n return job.outputFormat === \"json\" ? stripArray(out) : out;\n}\n\n/** Recombine per-bit elements into the final document, in document order. */\nexport function recombine(\n wasm: HookedWasm,\n elements: string[],\n output: OutputFormat,\n pretty: boolean,\n indent: number,\n): string {\n // Bitmark and plain-text bits both join with newlines; only JSON wraps as an\n // array. (`text` is output-only, lossy plain-text extraction.)\n if (output === \"bitmark\" || output === \"text\") return elements.join(\"\\n\");\n const arr = `[${elements.join(\",\")}]`;\n return pretty ? wasm.prettify(arr, indent) : arr;\n}\n\n/**\n * Per-bit transform driver (synchronous, in-process): split the document, run\n * `preHook` for each bit on the calling thread, apply the static patch + any\n * hook patches, re-emit the bit, run `postHook`, then recombine in document\n * order.\n *\n * Hooks run synchronously on the calling thread; only data crosses into WASM.\n * Used when a `preHook`/`postHook` is supplied; the hookless path stays a\n * single `wasm.transform` call. Returns the document, or an `error:`-prefixed\n * string on failure.\n */\nexport function runHookedTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): string {\n let plan: TransformPlan;\n try {\n plan = planTransform(wasm, input, options);\n } catch (e) {\n return errorString(e);\n }\n\n const rendered: string[] = [];\n for (let i = 0; i < plan.jobs.length; i++) {\n const element = computeBit(wasm, plan.jobs[i]);\n if (isError(element)) return element;\n options.postHook?.(plan.views[i], element);\n rendered.push(element);\n }\n return recombine(wasm, rendered, plan.output, plan.pretty, plan.indent);\n}\n","// @zen-component: TS-ParallelOrchestrator\n\nimport type { TransformOptions } from \"../types.js\";\nimport { type BitJob, errorString, type HookedWasm, isError, planTransform, recombine } from \"./hooked-transform.js\";\n\n/**\n * A platform pool: compute `jobs` across up to `workers` workers, returning the\n * rendered element per job in submission order. Node and browser supply their\n * own (worker_threads / Worker); the orchestration around it is shared.\n */\nexport type RunJobs = (jobs: BitJob[], workers: number) => Promise<string[]>;\n\n/**\n * Shared parallel transform orchestration. The main-thread half — split +\n * `preHook` + recombine + `postHook` — is identical to the sync driver; only\n * the data-only per-bit jobs cross to `runJobs` (the platform pool). Closures\n * (`preHook`/`postHook`) never leave the calling thread.\n *\n * Returns the document, or an `error:`-prefixed string on failure.\n */\nexport async function orchestrateParallel(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n runJobs: RunJobs,\n): Promise<string> {\n let plan;\n try {\n plan = planTransform(wasm, input, options);\n } catch (e) {\n return errorString(e);\n }\n\n let elements: string[];\n try {\n elements = await runJobs(plan.jobs, options.workers ?? 4);\n } catch (e) {\n return errorString(e);\n }\n\n for (let i = 0; i < elements.length; i++) {\n if (isError(elements[i])) return elements[i];\n options.postHook?.(plan.views[i], elements[i]);\n }\n return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);\n}\n","// @zen-component: TS-WorkerPool\n//\n// A fixed-size Node worker_threads pool that computes per-bit transform jobs in\n// parallel. Jobs are dispatched to idle workers; results are matched by id and\n// returned in submission order. The pool is short-lived (created per\n// transformParallel call) and terminated when all jobs settle.\n\nimport { fileURLToPath } from \"node:url\";\nimport { Worker } from \"node:worker_threads\";\nimport type { BitJob } from \"../core/hooked-transform.js\";\n\ninterface JobResult {\n ok: boolean;\n element?: string;\n error?: string;\n}\n\n// The worker entry is emitted as a sibling CJS file in dist/ (see tsup config),\n// so a CJS-format worker runs regardless of how the package itself was loaded.\nfunction workerPath(): string {\n return fileURLToPath(new URL(\"./worker-entry.cjs\", import.meta.url));\n}\n\n/**\n * Run `jobs` across up to `workers` worker threads, returning the rendered\n * element for each job in the **same order** as `jobs`. Rejects on the first\n * worker error or job error.\n */\nexport function runJobsParallel(jobs: BitJob[], workers: number): Promise<string[]> {\n if (jobs.length === 0) return Promise.resolve([]);\n const poolSize = Math.max(1, Math.min(workers, jobs.length));\n const path = workerPath();\n\n return new Promise<string[]>((resolve, reject) => {\n const results = new Array<string>(jobs.length);\n let next = 0;\n let settled = 0;\n let done = false;\n const pool: Worker[] = [];\n\n const shutdown = () => {\n for (const w of pool) void w.terminate();\n };\n const fail = (err: Error) => {\n if (done) return;\n done = true;\n shutdown();\n reject(err);\n };\n\n const dispatch = (w: Worker) => {\n if (done) return;\n if (next >= jobs.length) return; // no more work for this worker\n const id = next++;\n w.postMessage({ id, job: jobs[id] });\n };\n\n for (let i = 0; i < poolSize; i++) {\n const w = new Worker(path);\n pool.push(w);\n w.on(\"message\", (res: JobResult & { id: number }) => {\n if (done) return;\n if (!res.ok) {\n fail(new Error(res.error ?? \"worker job failed\"));\n return;\n }\n results[res.id] = res.element as string;\n settled++;\n if (settled === jobs.length) {\n done = true;\n shutdown();\n resolve(results);\n return;\n }\n dispatch(w);\n });\n w.on(\"error\", fail);\n w.on(\"exit\", (code) => {\n if (!done && code !== 0) fail(new Error(`worker exited with code ${code}`));\n });\n }\n\n // Prime each worker with one job.\n for (const w of pool) dispatch(w);\n });\n}\n","// @zen-component: TS-TransformParallel\n//\n// Node-only parallel transform: the main-thread half (split + preHook +\n// recombine + postHook) is shared with the synchronous driver and the browser\n// pool via orchestrateParallel; only the per-bit WASM compute is fanned out\n// across a worker_threads pool.\n\nimport { orchestrateParallel } from \"../core/parallel.js\";\nimport type { HookedWasm } from \"../core/hooked-transform.js\";\nimport type { TransformOptions } from \"../types.js\";\nimport { runJobsParallel } from \"./pool.js\";\n\n/**\n * Parallel counterpart of `transform` on Node. `preHook`/`postHook` run on the\n * calling thread; only data-only jobs cross to the worker_threads pool.\n */\nexport function runParallelTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): Promise<string> {\n return orchestrateParallel(wasm, input, options, runJobsParallel);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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AAAA,IACA,QAAQ,eAAe;AAAA,IACvB,QAAQ,gBAAgB;AAAA,IACxB,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA,QAAQ,UAAU;AAAA,IAClB,QAAQ,UAAU;AAAA,IAClB,QAAQ,sBAAsB;AAAA,EAChC;AACF;AAYO,SAAS,kBAAkB,OAAe,UAA4B,CAAC,GAAoB;AAChG,SAAO,qBAAqB,MAA+B,OAAO,OAAO;AAC3E;AASO,SAAS,eAAe,OAAe,UAA6B,CAAC,GAAW;AACrF,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,WAAW,QAAQ,YAAY;AACrC,SAAO,KAAK,gBAAgB,OAAO,QAAQ,QAAQ;AACrD;AASO,SAAS,iBAAiB,OAAe,UAA6B,CAAC,GAAW;AACvF,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,WAAW,QAAQ,YAAY;AACrC,SAAO,KAAK,kBAAkB,OAAO,QAAQ,QAAQ;AACvD;AAQO,SAAS,KAAK,UAAuB,CAAC,GAAW;AACtD,QAAM,WAAW,QAAQ,YAAY;AACrC,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,MAAM,QAAQ,OAAO;AAC3B,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,SAAS,QAAQ,UAAU;AACjC,SAAO,KAAK,KAAK,UAAU,QAAQ,KAAK,QAAQ,MAAM;AACxD;AAWO,SAAS,SAAS,OAAe,UAAwB,CAAC,GAAW;AAC1E,SAAO,KAAK,QAAQ,OAAO,QAAQ,WAAW,QAAQ,QAAQ,aAAa,OAAO,GAAG,CAAC;AACxF;","names":["wasm","out","wasm","wasm","require"]}
1
+ {"version":3,"sources":["../src/index.ts","../../../node_modules/tsup/assets/cjs_shims.js","../src/generated/package_info.ts","../src/core/hooked-transform.ts","../src/core/parallel.ts","../src/node/pool.ts","../src/node/transform-parallel.ts"],"sourcesContent":["// @zen-component: WASM-TSBindings\n\nimport { createRequire } from \"node:module\";\nimport { PACKAGE_INFO } from \"./generated/package_info.js\";\nimport { runHookedTransform, type HookedWasm } from \"./core/hooked-transform.js\";\nimport { runParallelTransform } from \"./node/transform-parallel.js\";\nimport type { LexOptions, ParseOptions, ConvertOptions, BreakscapeOptions, InfoOptions, NormalizeOptions, TransformOptions, BitSlice } from \"./types.js\";\nconst require = createRequire(import.meta.url);\nconst wasm = require(\"../wasm/bitmark_wasm.js\") as typeof import(\"../wasm/bitmark_wasm.js\");\n\nexport type { LexOptions, LexStage, ParseOptions, ConvertOptions, OutputMode, BreakscapeOptions, TextFormat, TextLocation, InfoOptions, InfoType, InfoFormat, InputFormat, OutputFormat, NormalizeOptions, TransformOptions, PatchOp, PatchEntry, BitSlice, BitView, PreHook, PostHook, PreHookResult } from \"./types.js\";\n\n/**\n * Get the version of the @gmb/bitmark-parser library.\n *\n * @returns Version string (e.g. \"3.0.0\").\n */\nexport function version(): string {\n return PACKAGE_INFO.version;\n}\n\n/**\n * Lex bitmark input text, returning one line per token.\n *\n * @param input - The bitmark source text.\n * @param options - Lex options (e.g. `{ stage: \"lex\" }`).\n * @returns Token dump string (one token per line).\n */\nexport function lex(input: string, options: LexOptions = {}): string {\n return wasm.lex(input, options.stage ?? \"lex\");\n}\n\n/**\n * Parse bitmark input text and return structured JSON entries.\n *\n * Each entry contains `bit`, `parser`, and `bitmark` fields.\n *\n * @param input - The bitmark source text.\n * @param options - Parse options (e.g. `{ mode: \"full\" }`).\n * @returns JSON string array of structured parsed entries.\n */\nexport function parse(input: string, options: ParseOptions = {}): string {\n return wasm.parse(input, options.mode ?? \"optimized\");\n}\n\n/**\n * Auto-detect input format and convert between bitmark and JSON.\n *\n * @param input - Bitmark or JSON input text.\n * @param options - Convert options (e.g. `{ mode: \"full\", warnings: true }`).\n * @returns Converted output string. For bitmark input, this is a JSON string\n * array of structured parsed entries (`bit`, `parser`, `bitmark`).\n */\nexport function convert(input: string, options: ConvertOptions = {}): string {\n return wasm.convert(\n input,\n options.inputFormat ?? \"auto\",\n options.outputFormat ?? \"auto\",\n options.mode ?? \"optimized\",\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Re-emit input in its own format at optimized mode.\n *\n * @param input - Input text (bitmark, JSON, or a markup format such as html/xml).\n * @param options - `inputFormat` selects the format (default: `\"auto\"`); the\n * output is re-emitted in that same format.\n * @returns Optimized output in the same format as the input.\n */\nexport function optimize(input: string, options: NormalizeOptions = {}): string {\n return wasm.optimize(input, options.inputFormat ?? \"auto\", options.pretty ?? false, options.indent ?? 2);\n}\n\n/**\n * Re-emit input in its own format at full mode (all keys). Aliased as\n * {@link expand}. `options.inputFormat` selects the format (default: `\"auto\"`).\n */\nexport function fullize(input: string, options: NormalizeOptions = {}): string {\n return wasm.fullize(input, options.inputFormat ?? \"auto\", options.pretty ?? false, options.indent ?? 2);\n}\n\n/** Alias of {@link fullize}. */\nexport const expand = fullize;\n\n/**\n * Re-emit input in its own format in canonical form. `options.inputFormat`\n * selects the format (default: `\"auto\"`).\n */\nexport function canonicalize(input: string, options: NormalizeOptions = {}): string {\n return wasm.canonicalize(\n input,\n options.inputFormat ?? \"auto\",\n options.mode ?? \"optimized\",\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Count the bits in `input`, auto-detecting bitmark vs JSON.\n *\n * @throws If the input cannot be parsed.\n */\nexport function countBits(input: string): number {\n const out = wasm.count_bits(input);\n if (out.startsWith(\"error:\")) throw new Error(out);\n return Number.parseInt(out, 10);\n}\n\n/**\n * Split a bitmark document into per-bit source slices.\n *\n * @returns Array of `{ index, byteStart, byteEnd, source }`.\n */\nexport function splitBits(input: string): BitSlice[] {\n return JSON.parse(wasm.split_bits(input)) as BitSlice[];\n}\n\n/**\n * Transform a document bit-by-bit: apply an optional static `patch` and/or\n * per-bit `preHook`/`postHook`, then re-emit.\n *\n * With neither hook, the whole document is transformed in a single WASM pass\n * (the fast path). When a `preHook` or `postHook` is supplied, `transform`\n * drives the bits one at a time on the calling thread — the hook inspects each\n * bit, may return patches / an output-format override / `drop`, and only data\n * crosses into WASM. The patch may be an array of entries or a JSON string.\n *\n * @returns The transformed document, or an `error:`-prefixed string on failure.\n */\nexport function transform(input: string, options: TransformOptions = {}): string {\n if (options.preHook || options.postHook) {\n return runHookedTransform(wasm as unknown as HookedWasm, input, options);\n }\n const patchJson =\n options.patch === undefined\n ? \"\"\n : typeof options.patch === \"string\"\n ? options.patch\n : JSON.stringify(options.patch);\n return wasm.transform(\n input,\n options.inputFormat ?? \"auto\",\n options.outputFormat ?? \"json\",\n options.mode ?? \"optimized\",\n patchJson,\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Parallel counterpart of {@link transform} (Node only). Fans the per-bit WASM\n * compute across a `worker_threads` pool (`options.workers`, default `4`),\n * while `preHook`/`postHook` still run on the calling thread. Output is\n * identical to {@link transform}; this trades startup cost for throughput on\n * large documents.\n *\n * @returns A Promise of the transformed document, or an `error:`-prefixed\n * string on failure.\n */\nexport function transformParallel(input: string, options: TransformOptions = {}): Promise<string> {\n return runParallelTransform(wasm as unknown as HookedWasm, input, options);\n}\n\n/**\n * Breakscape text (escape bitmark special characters).\n *\n * @param input - The text to breakscape.\n * @param options - Breakscape options (e.g. `{ format: \"plainText\", location: \"tag\" }`).\n * @returns Breakscaped text.\n */\nexport function breakscapeText(input: string, options: BreakscapeOptions = {}): string {\n const format = options.format ?? \"bitmark++\";\n const location = options.location ?? \"body\";\n return wasm.breakscape_text(input, format, location);\n}\n\n/**\n * Unbreakscape text (unescape bitmark special characters).\n *\n * @param input - The text to unbreakscape.\n * @param options - Unbreakscape options (e.g. `{ format: \"plainText\", location: \"tag\" }`).\n * @returns Unbreakscaped text.\n */\nexport function unbreakscapeText(input: string, options: BreakscapeOptions = {}): string {\n const format = options.format ?? \"bitmark++\";\n const location = options.location ?? \"body\";\n return wasm.unbreakscape_text(input, format, location);\n}\n\n/**\n * Query information about supported bit types.\n *\n * @param options - Info options (e.g. `{ infoType: \"bit\", format: \"json\", bit: \"cloze\" }`).\n * @returns Information string.\n */\nexport function info(options: InfoOptions = {}): string {\n const infoType = options.infoType ?? \"list\";\n const format = options.format ?? \"text\";\n const bit = options.bit ?? \"\";\n const pretty = options.pretty ?? false;\n const indent = options.indent ?? 2;\n return wasm.info(infoType, format, bit, pretty, indent);\n}\n\n/**\n * Generate bitmark text from a JSON AST.\n *\n * The reverse pipeline: `JSON → json_to_ast → AST → ast_to_bitmark`.\n *\n * @param input - JSON string of the parsed bit entries (forward output shape).\n * @param options - Generate options (e.g. `{ mode: \"full\" }`).\n * @returns Bitmark text. On failure, an `error:`-prefixed string.\n */\nexport function generate(input: string, options: ParseOptions = {}): string {\n return wasm.convert(input, \"json\", \"bitmark\", options.mode ?? \"optimized\", false, 2, 1);\n}\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","// This file is automatically generated. DO NOT EDIT.\n\n/* eslint-disable */\n\nexport const PACKAGE_INFO = {\n \"name\": \"@gmb/bitmark-parser\",\n \"version\": \"6.1.3\",\n \"author\": \"Get More Brain Ltd <info@getmorebrain.com>\",\n \"license\": \"ISC\",\n \"description\": \"A parser for bitmark text, powered by WebAssembly.\"\n};\n","// @zen-component: TS-HookedTransform\n\nimport type { BitView, OutputFormat, PatchEntry, TransformOptions } from \"../types.js\";\n\n/**\n * The minimal WASM surface the per-bit hook driver needs. Both the Node and\n * browser entry points satisfy this with their loaded module.\n */\nexport interface HookedWasm {\n is_bitmark(input: string): boolean;\n split_bits(input: string): string;\n split_json_bits(input: string): string;\n prettify(json: string, indent: number): string;\n transform(\n input: string,\n inputFormat: string,\n outputFormat: string,\n mode: string,\n patchJson: string,\n pretty: boolean,\n indent: number,\n spacesAroundValues: number,\n ): string;\n}\n\n/** A single bit's compute job: data only, safe to ship to a worker thread. */\nexport interface BitJob {\n index: number;\n source: string;\n inputFormat: \"bitmark\" | \"json\";\n outputFormat: OutputFormat;\n mode: string;\n patchJson: string;\n spacesAroundValues: number;\n}\n\n/**\n * The result of running `preHook` over a document's bits: the compute `jobs`\n * for the bits that survived (in document order) and the matching `views`\n * (so `postHook` can be called per surviving bit), plus the document-level\n * recombination settings.\n */\nexport interface TransformPlan {\n jobs: BitJob[];\n views: BitView[];\n output: OutputFormat;\n pretty: boolean;\n indent: number;\n}\n\nexport function isError(s: string): boolean {\n return s.startsWith(\"error:\");\n}\n\n/**\n * Normalise a thrown value to an `error:`-prefixed string, without\n * double-prefixing a message that already carries the prefix (split helpers\n * surface WASM `error:` strings as thrown `Error`s).\n */\nexport function errorString(e: unknown): string {\n const m = e instanceof Error ? e.message : String(e);\n return m.startsWith(\"error:\") ? m : `error: ${m}`;\n}\n\n/** Strip the outer `[ … ]` of a compact one-element JSON array. */\nexport function stripArray(doc: string): string {\n const t = doc.trim();\n return t.startsWith(\"[\") && t.endsWith(\"]\") ? t.slice(1, -1) : doc;\n}\n\nfunction normalisePatch(patch: TransformOptions[\"patch\"]): PatchEntry[] {\n if (patch === undefined) return [];\n if (typeof patch === \"string\") {\n const trimmed = patch.trim();\n return trimmed === \"\" ? [] : (JSON.parse(trimmed) as PatchEntry[]);\n }\n return patch;\n}\n\nfunction buildUnits(\n wasm: HookedWasm,\n input: string,\n inputIsBitmark: boolean,\n): { view: BitView; source: string }[] {\n if (inputIsBitmark) {\n const out = wasm.split_bits(input);\n if (isError(out)) throw new Error(out);\n const slices = JSON.parse(out) as { index: number; source: string }[];\n return slices.map((s) => ({\n view: { format: \"bitmark\", index: s.index, total: slices.length, source: s.source },\n source: s.source,\n }));\n }\n const out = wasm.split_json_bits(input);\n if (isError(out)) throw new Error(out);\n const envelopes = JSON.parse(out) as { bit?: unknown }[];\n return envelopes.map((env, index) => ({\n view: { format: \"json\", index, total: envelopes.length, bit: env.bit },\n // Per-bit transform consumes a one-bit JSON document.\n source: JSON.stringify([env]),\n }));\n}\n\n/**\n * Split the document and run `preHook` (on the calling thread) for each bit,\n * producing the surviving compute jobs + their views. This is the main-thread\n * half shared by the sync and worker-pool drivers — only the resulting\n * data-only {@link BitJob}s ever cross to a worker.\n */\nexport function planTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): TransformPlan {\n const mode = options.mode ?? \"optimized\";\n const output: OutputFormat = options.outputFormat ?? \"json\";\n const spacesAroundValues = options.spacesAroundValues ?? 1;\n const indent = options.indent ?? 2;\n const pretty = options.pretty ?? false;\n\n const sel = options.inputFormat ?? \"auto\";\n const inputIsBitmark = sel === \"bitmark\" || (sel !== \"json\" && wasm.is_bitmark(input));\n const inputFormat = inputIsBitmark ? \"bitmark\" : \"json\";\n\n const staticPatch = normalisePatch(options.patch);\n const units = buildUnits(wasm, input, inputIsBitmark);\n const total = units.length;\n\n const jobs: BitJob[] = [];\n const views: BitView[] = [];\n for (let index = 0; index < total; index++) {\n const { view, source } = units[index];\n view.index = index;\n view.total = total;\n\n const result = options.preHook ? options.preHook(view) || {} : {};\n if (result.drop) continue;\n\n const patches = result.patches ? [...staticPatch, ...result.patches] : staticPatch;\n jobs.push({\n index,\n source,\n inputFormat,\n outputFormat: result.outputFormat ?? output,\n mode,\n patchJson: JSON.stringify(patches),\n spacesAroundValues,\n });\n views.push(view);\n }\n return { jobs, views, output, pretty, indent };\n}\n\n/**\n * Compute one bit's rendered element synchronously via WASM. The per-bit\n * element is always compact JSON (the document is prettified once on\n * recombination). Returns an `error:`-prefixed string on failure.\n */\nexport function computeBit(wasm: HookedWasm, job: BitJob): string {\n const out = wasm.transform(\n job.source,\n job.inputFormat,\n job.outputFormat,\n job.mode,\n job.patchJson,\n false,\n 2,\n job.spacesAroundValues,\n );\n if (isError(out)) return out;\n return job.outputFormat === \"json\" ? stripArray(out) : out;\n}\n\n/** Recombine per-bit elements into the final document, in document order. */\nexport function recombine(\n wasm: HookedWasm,\n elements: string[],\n output: OutputFormat,\n pretty: boolean,\n indent: number,\n): string {\n // Bitmark and plain-text bits both join with newlines; only JSON wraps as an\n // array. (`text` is output-only, lossy plain-text extraction.)\n if (output === \"bitmark\" || output === \"text\") return elements.join(\"\\n\");\n const arr = `[${elements.join(\",\")}]`;\n return pretty ? wasm.prettify(arr, indent) : arr;\n}\n\n/**\n * Per-bit transform driver (synchronous, in-process): split the document, run\n * `preHook` for each bit on the calling thread, apply the static patch + any\n * hook patches, re-emit the bit, run `postHook`, then recombine in document\n * order.\n *\n * Hooks run synchronously on the calling thread; only data crosses into WASM.\n * Used when a `preHook`/`postHook` is supplied; the hookless path stays a\n * single `wasm.transform` call. Returns the document, or an `error:`-prefixed\n * string on failure.\n */\nexport function runHookedTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): string {\n let plan: TransformPlan;\n try {\n plan = planTransform(wasm, input, options);\n } catch (e) {\n return errorString(e);\n }\n\n const rendered: string[] = [];\n for (let i = 0; i < plan.jobs.length; i++) {\n const element = computeBit(wasm, plan.jobs[i]);\n if (isError(element)) return element;\n options.postHook?.(plan.views[i], element);\n rendered.push(element);\n }\n return recombine(wasm, rendered, plan.output, plan.pretty, plan.indent);\n}\n","// @zen-component: TS-ParallelOrchestrator\n\nimport type { TransformOptions } from \"../types.js\";\nimport { type BitJob, errorString, type HookedWasm, isError, planTransform, recombine } from \"./hooked-transform.js\";\n\n/**\n * A platform pool: compute `jobs` across up to `workers` workers, returning the\n * rendered element per job in submission order. Node and browser supply their\n * own (worker_threads / Worker); the orchestration around it is shared.\n */\nexport type RunJobs = (jobs: BitJob[], workers: number) => Promise<string[]>;\n\n/**\n * Shared parallel transform orchestration. The main-thread half — split +\n * `preHook` + recombine + `postHook` — is identical to the sync driver; only\n * the data-only per-bit jobs cross to `runJobs` (the platform pool). Closures\n * (`preHook`/`postHook`) never leave the calling thread.\n *\n * Returns the document, or an `error:`-prefixed string on failure.\n */\nexport async function orchestrateParallel(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n runJobs: RunJobs,\n): Promise<string> {\n let plan;\n try {\n plan = planTransform(wasm, input, options);\n } catch (e) {\n return errorString(e);\n }\n\n let elements: string[];\n try {\n elements = await runJobs(plan.jobs, options.workers ?? 4);\n } catch (e) {\n return errorString(e);\n }\n\n for (let i = 0; i < elements.length; i++) {\n if (isError(elements[i])) return elements[i];\n options.postHook?.(plan.views[i], elements[i]);\n }\n return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);\n}\n","// @zen-component: TS-WorkerPool\n//\n// A fixed-size Node worker_threads pool that computes per-bit transform jobs in\n// parallel. Jobs are dispatched to idle workers; results are matched by id and\n// returned in submission order. The pool is short-lived (created per\n// transformParallel call) and terminated when all jobs settle.\n\nimport { fileURLToPath } from \"node:url\";\nimport { Worker } from \"node:worker_threads\";\nimport type { BitJob } from \"../core/hooked-transform.js\";\n\ninterface JobResult {\n ok: boolean;\n element?: string;\n error?: string;\n}\n\n// The worker entry is emitted as a sibling CJS file in dist/ (see tsup config),\n// so a CJS-format worker runs regardless of how the package itself was loaded.\nfunction workerPath(): string {\n return fileURLToPath(new URL(\"./worker-entry.cjs\", import.meta.url));\n}\n\n/**\n * Run `jobs` across up to `workers` worker threads, returning the rendered\n * element for each job in the **same order** as `jobs`. Rejects on the first\n * worker error or job error.\n */\nexport function runJobsParallel(jobs: BitJob[], workers: number): Promise<string[]> {\n if (jobs.length === 0) return Promise.resolve([]);\n const poolSize = Math.max(1, Math.min(workers, jobs.length));\n const path = workerPath();\n\n return new Promise<string[]>((resolve, reject) => {\n const results = new Array<string>(jobs.length);\n let next = 0;\n let settled = 0;\n let done = false;\n const pool: Worker[] = [];\n\n const shutdown = () => {\n for (const w of pool) void w.terminate();\n };\n const fail = (err: Error) => {\n if (done) return;\n done = true;\n shutdown();\n reject(err);\n };\n\n const dispatch = (w: Worker) => {\n if (done) return;\n if (next >= jobs.length) return; // no more work for this worker\n const id = next++;\n w.postMessage({ id, job: jobs[id] });\n };\n\n for (let i = 0; i < poolSize; i++) {\n const w = new Worker(path);\n pool.push(w);\n w.on(\"message\", (res: JobResult & { id: number }) => {\n if (done) return;\n if (!res.ok) {\n fail(new Error(res.error ?? \"worker job failed\"));\n return;\n }\n results[res.id] = res.element as string;\n settled++;\n if (settled === jobs.length) {\n done = true;\n shutdown();\n resolve(results);\n return;\n }\n dispatch(w);\n });\n w.on(\"error\", fail);\n w.on(\"exit\", (code) => {\n if (!done && code !== 0) fail(new Error(`worker exited with code ${code}`));\n });\n }\n\n // Prime each worker with one job.\n for (const w of pool) dispatch(w);\n });\n}\n","// @zen-component: TS-TransformParallel\n//\n// Node-only parallel transform: the main-thread half (split + preHook +\n// recombine + postHook) is shared with the synchronous driver and the browser\n// pool via orchestrateParallel; only the per-bit WASM compute is fanned out\n// across a worker_threads pool.\n\nimport { orchestrateParallel } from \"../core/parallel.js\";\nimport type { HookedWasm } from \"../core/hooked-transform.js\";\nimport type { TransformOptions } from \"../types.js\";\nimport { runJobsParallel } from \"./pool.js\";\n\n/**\n * Parallel counterpart of `transform` on Node. `preHook`/`postHook` run on the\n * calling thread; only data-only jobs cross to the worker_threads pool.\n */\nexport function runParallelTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): Promise<string> {\n return orchestrateParallel(wasm, input, options, runJobsParallel);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ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U;AAAA,IAClB,QAAQ,UAAU;AAAA,IAClB,QAAQ,sBAAsB;AAAA,EAChC;AACF;AAYO,SAAS,kBAAkB,OAAe,UAA4B,CAAC,GAAoB;AAChG,SAAO,qBAAqB,MAA+B,OAAO,OAAO;AAC3E;AASO,SAAS,eAAe,OAAe,UAA6B,CAAC,GAAW;AACrF,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,WAAW,QAAQ,YAAY;AACrC,SAAO,KAAK,gBAAgB,OAAO,QAAQ,QAAQ;AACrD;AASO,SAAS,iBAAiB,OAAe,UAA6B,CAAC,GAAW;AACvF,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,WAAW,QAAQ,YAAY;AACrC,SAAO,KAAK,kBAAkB,OAAO,QAAQ,QAAQ;AACvD;AAQO,SAAS,KAAK,UAAuB,CAAC,GAAW;AACtD,QAAM,WAAW,QAAQ,YAAY;AACrC,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,MAAM,QAAQ,OAAO;AAC3B,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,SAAS,QAAQ,UAAU;AACjC,SAAO,KAAK,KAAK,UAAU,QAAQ,KAAK,QAAQ,MAAM;AACxD;AAWO,SAAS,SAAS,OAAe,UAAwB,CAAC,GAAW;AAC1E,SAAO,KAAK,QAAQ,OAAO,QAAQ,WAAW,QAAQ,QAAQ,aAAa,OAAO,GAAG,CAAC;AACxF;","names":["wasm","out","wasm","wasm","require"]}
package/dist/index.d.cts CHANGED
@@ -22,8 +22,15 @@ interface ParseOptions {
22
22
  /** JSON output mode (default: `"optimized"`). */
23
23
  mode?: OutputMode;
24
24
  }
25
- /** Input format selector (adds auto-detection). */
26
- type InputFormat = "auto" | "bitmark" | "json";
25
+ /**
26
+ * Input format selector (adds auto-detection).
27
+ *
28
+ * `"auto"` sniffs bitmark-vs-JSON from the content; `"bitmark"` / `"json"` are
29
+ * explicit; any config mapping id (e.g. `"html"`, `"xml"`) selects a markup
30
+ * input that is reversed to the AST. The `(string & {})` arm admits those
31
+ * config-driven mapping ids while keeping literal autocompletion.
32
+ */
33
+ type InputFormat = "auto" | "bitmark" | "json" | (string & {});
27
34
  /** Concrete output format. `"text"` is lossy plain-text extraction and is
28
35
  * output-only (it cannot be used as an input format). */
29
36
  type OutputFormat = "bitmark" | "json" | "text";
@@ -48,6 +55,11 @@ interface ConvertOptions {
48
55
  }
49
56
  /** Options for the {@link optimize}, {@link fullize}, and {@link canonicalize} functions. */
50
57
  interface NormalizeOptions {
58
+ /**
59
+ * Input format (default: `"auto"`). The output is re-emitted in this same
60
+ * format — e.g. `"html"` in, html out. `"auto"` sniffs bitmark vs JSON.
61
+ */
62
+ inputFormat?: InputFormat;
51
63
  /** Output mode — used by {@link canonicalize} only (default: `"optimized"`). */
52
64
  mode?: OutputMode;
53
65
  /** Prettify JSON output (default: `false`). */
@@ -205,21 +217,24 @@ declare function parse(input: string, options?: ParseOptions): string;
205
217
  */
206
218
  declare function convert(input: string, options?: ConvertOptions): string;
207
219
  /**
208
- * Re-emit input in its own (auto-detected) format at optimized mode.
220
+ * Re-emit input in its own format at optimized mode.
209
221
  *
210
- * @param input - Bitmark or JSON input text.
222
+ * @param input - Input text (bitmark, JSON, or a markup format such as html/xml).
223
+ * @param options - `inputFormat` selects the format (default: `"auto"`); the
224
+ * output is re-emitted in that same format.
211
225
  * @returns Optimized output in the same format as the input.
212
226
  */
213
227
  declare function optimize(input: string, options?: NormalizeOptions): string;
214
228
  /**
215
- * Re-emit input in its own (auto-detected) format at full mode (all keys).
216
- * Aliased as {@link expand}.
229
+ * Re-emit input in its own format at full mode (all keys). Aliased as
230
+ * {@link expand}. `options.inputFormat` selects the format (default: `"auto"`).
217
231
  */
218
232
  declare function fullize(input: string, options?: NormalizeOptions): string;
219
233
  /** Alias of {@link fullize}. */
220
234
  declare const expand: typeof fullize;
221
235
  /**
222
- * Re-emit input in its own (auto-detected) format in canonical form.
236
+ * Re-emit input in its own format in canonical form. `options.inputFormat`
237
+ * selects the format (default: `"auto"`).
223
238
  */
224
239
  declare function canonicalize(input: string, options?: NormalizeOptions): string;
225
240
  /**
package/dist/index.d.ts CHANGED
@@ -22,8 +22,15 @@ interface ParseOptions {
22
22
  /** JSON output mode (default: `"optimized"`). */
23
23
  mode?: OutputMode;
24
24
  }
25
- /** Input format selector (adds auto-detection). */
26
- type InputFormat = "auto" | "bitmark" | "json";
25
+ /**
26
+ * Input format selector (adds auto-detection).
27
+ *
28
+ * `"auto"` sniffs bitmark-vs-JSON from the content; `"bitmark"` / `"json"` are
29
+ * explicit; any config mapping id (e.g. `"html"`, `"xml"`) selects a markup
30
+ * input that is reversed to the AST. The `(string & {})` arm admits those
31
+ * config-driven mapping ids while keeping literal autocompletion.
32
+ */
33
+ type InputFormat = "auto" | "bitmark" | "json" | (string & {});
27
34
  /** Concrete output format. `"text"` is lossy plain-text extraction and is
28
35
  * output-only (it cannot be used as an input format). */
29
36
  type OutputFormat = "bitmark" | "json" | "text";
@@ -48,6 +55,11 @@ interface ConvertOptions {
48
55
  }
49
56
  /** Options for the {@link optimize}, {@link fullize}, and {@link canonicalize} functions. */
50
57
  interface NormalizeOptions {
58
+ /**
59
+ * Input format (default: `"auto"`). The output is re-emitted in this same
60
+ * format — e.g. `"html"` in, html out. `"auto"` sniffs bitmark vs JSON.
61
+ */
62
+ inputFormat?: InputFormat;
51
63
  /** Output mode — used by {@link canonicalize} only (default: `"optimized"`). */
52
64
  mode?: OutputMode;
53
65
  /** Prettify JSON output (default: `false`). */
@@ -205,21 +217,24 @@ declare function parse(input: string, options?: ParseOptions): string;
205
217
  */
206
218
  declare function convert(input: string, options?: ConvertOptions): string;
207
219
  /**
208
- * Re-emit input in its own (auto-detected) format at optimized mode.
220
+ * Re-emit input in its own format at optimized mode.
209
221
  *
210
- * @param input - Bitmark or JSON input text.
222
+ * @param input - Input text (bitmark, JSON, or a markup format such as html/xml).
223
+ * @param options - `inputFormat` selects the format (default: `"auto"`); the
224
+ * output is re-emitted in that same format.
211
225
  * @returns Optimized output in the same format as the input.
212
226
  */
213
227
  declare function optimize(input: string, options?: NormalizeOptions): string;
214
228
  /**
215
- * Re-emit input in its own (auto-detected) format at full mode (all keys).
216
- * Aliased as {@link expand}.
229
+ * Re-emit input in its own format at full mode (all keys). Aliased as
230
+ * {@link expand}. `options.inputFormat` selects the format (default: `"auto"`).
217
231
  */
218
232
  declare function fullize(input: string, options?: NormalizeOptions): string;
219
233
  /** Alias of {@link fullize}. */
220
234
  declare const expand: typeof fullize;
221
235
  /**
222
- * Re-emit input in its own (auto-detected) format in canonical form.
236
+ * Re-emit input in its own format in canonical form. `options.inputFormat`
237
+ * selects the format (default: `"auto"`).
223
238
  */
224
239
  declare function canonicalize(input: string, options?: NormalizeOptions): string;
225
240
  /**
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { createRequire } from "module";
4
4
  // src/generated/package_info.ts
5
5
  var PACKAGE_INFO = {
6
6
  "name": "@gmb/bitmark-parser",
7
- "version": "6.1.1",
7
+ "version": "6.1.3",
8
8
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
9
9
  "license": "ISC",
10
10
  "description": "A parser for bitmark text, powered by WebAssembly."
@@ -228,15 +228,16 @@ function convert(input, options = {}) {
228
228
  );
229
229
  }
230
230
  function optimize(input, options = {}) {
231
- return wasm.optimize(input, options.pretty ?? false, options.indent ?? 2);
231
+ return wasm.optimize(input, options.inputFormat ?? "auto", options.pretty ?? false, options.indent ?? 2);
232
232
  }
233
233
  function fullize(input, options = {}) {
234
- return wasm.fullize(input, options.pretty ?? false, options.indent ?? 2);
234
+ return wasm.fullize(input, options.inputFormat ?? "auto", options.pretty ?? false, options.indent ?? 2);
235
235
  }
236
236
  var expand = fullize;
237
237
  function canonicalize(input, options = {}) {
238
238
  return wasm.canonicalize(
239
239
  input,
240
+ options.inputFormat ?? "auto",
240
241
  options.mode ?? "optimized",
241
242
  options.pretty ?? false,
242
243
  options.indent ?? 2,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/generated/package_info.ts","../src/core/hooked-transform.ts","../src/core/parallel.ts","../src/node/pool.ts","../src/node/transform-parallel.ts"],"sourcesContent":["// @zen-component: WASM-TSBindings\n\nimport { createRequire } from \"node:module\";\nimport { PACKAGE_INFO } from \"./generated/package_info.js\";\nimport { runHookedTransform, type HookedWasm } from \"./core/hooked-transform.js\";\nimport { runParallelTransform } from \"./node/transform-parallel.js\";\nimport type { LexOptions, ParseOptions, ConvertOptions, BreakscapeOptions, InfoOptions, NormalizeOptions, TransformOptions, BitSlice } from \"./types.js\";\nconst require = createRequire(import.meta.url);\nconst wasm = require(\"../wasm/bitmark_wasm.js\") as typeof import(\"../wasm/bitmark_wasm.js\");\n\nexport type { LexOptions, LexStage, ParseOptions, ConvertOptions, OutputMode, BreakscapeOptions, TextFormat, TextLocation, InfoOptions, InfoType, InfoFormat, InputFormat, OutputFormat, NormalizeOptions, TransformOptions, PatchOp, PatchEntry, BitSlice, BitView, PreHook, PostHook, PreHookResult } from \"./types.js\";\n\n/**\n * Get the version of the @gmb/bitmark-parser library.\n *\n * @returns Version string (e.g. \"3.0.0\").\n */\nexport function version(): string {\n return PACKAGE_INFO.version;\n}\n\n/**\n * Lex bitmark input text, returning one line per token.\n *\n * @param input - The bitmark source text.\n * @param options - Lex options (e.g. `{ stage: \"lex\" }`).\n * @returns Token dump string (one token per line).\n */\nexport function lex(input: string, options: LexOptions = {}): string {\n return wasm.lex(input, options.stage ?? \"lex\");\n}\n\n/**\n * Parse bitmark input text and return structured JSON entries.\n *\n * Each entry contains `bit`, `parser`, and `bitmark` fields.\n *\n * @param input - The bitmark source text.\n * @param options - Parse options (e.g. `{ mode: \"full\" }`).\n * @returns JSON string array of structured parsed entries.\n */\nexport function parse(input: string, options: ParseOptions = {}): string {\n return wasm.parse(input, options.mode ?? \"optimized\");\n}\n\n/**\n * Auto-detect input format and convert between bitmark and JSON.\n *\n * @param input - Bitmark or JSON input text.\n * @param options - Convert options (e.g. `{ mode: \"full\", warnings: true }`).\n * @returns Converted output string. For bitmark input, this is a JSON string\n * array of structured parsed entries (`bit`, `parser`, `bitmark`).\n */\nexport function convert(input: string, options: ConvertOptions = {}): string {\n return wasm.convert(\n input,\n options.inputFormat ?? \"auto\",\n options.outputFormat ?? \"auto\",\n options.mode ?? \"optimized\",\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Re-emit input in its own (auto-detected) format at optimized mode.\n *\n * @param input - Bitmark or JSON input text.\n * @returns Optimized output in the same format as the input.\n */\nexport function optimize(input: string, options: NormalizeOptions = {}): string {\n return wasm.optimize(input, options.pretty ?? false, options.indent ?? 2);\n}\n\n/**\n * Re-emit input in its own (auto-detected) format at full mode (all keys).\n * Aliased as {@link expand}.\n */\nexport function fullize(input: string, options: NormalizeOptions = {}): string {\n return wasm.fullize(input, options.pretty ?? false, options.indent ?? 2);\n}\n\n/** Alias of {@link fullize}. */\nexport const expand = fullize;\n\n/**\n * Re-emit input in its own (auto-detected) format in canonical form.\n */\nexport function canonicalize(input: string, options: NormalizeOptions = {}): string {\n return wasm.canonicalize(\n input,\n options.mode ?? \"optimized\",\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Count the bits in `input`, auto-detecting bitmark vs JSON.\n *\n * @throws If the input cannot be parsed.\n */\nexport function countBits(input: string): number {\n const out = wasm.count_bits(input);\n if (out.startsWith(\"error:\")) throw new Error(out);\n return Number.parseInt(out, 10);\n}\n\n/**\n * Split a bitmark document into per-bit source slices.\n *\n * @returns Array of `{ index, byteStart, byteEnd, source }`.\n */\nexport function splitBits(input: string): BitSlice[] {\n return JSON.parse(wasm.split_bits(input)) as BitSlice[];\n}\n\n/**\n * Transform a document bit-by-bit: apply an optional static `patch` and/or\n * per-bit `preHook`/`postHook`, then re-emit.\n *\n * With neither hook, the whole document is transformed in a single WASM pass\n * (the fast path). When a `preHook` or `postHook` is supplied, `transform`\n * drives the bits one at a time on the calling thread — the hook inspects each\n * bit, may return patches / an output-format override / `drop`, and only data\n * crosses into WASM. The patch may be an array of entries or a JSON string.\n *\n * @returns The transformed document, or an `error:`-prefixed string on failure.\n */\nexport function transform(input: string, options: TransformOptions = {}): string {\n if (options.preHook || options.postHook) {\n return runHookedTransform(wasm as unknown as HookedWasm, input, options);\n }\n const patchJson =\n options.patch === undefined\n ? \"\"\n : typeof options.patch === \"string\"\n ? options.patch\n : JSON.stringify(options.patch);\n return wasm.transform(\n input,\n options.inputFormat ?? \"auto\",\n options.outputFormat ?? \"json\",\n options.mode ?? \"optimized\",\n patchJson,\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Parallel counterpart of {@link transform} (Node only). Fans the per-bit WASM\n * compute across a `worker_threads` pool (`options.workers`, default `4`),\n * while `preHook`/`postHook` still run on the calling thread. Output is\n * identical to {@link transform}; this trades startup cost for throughput on\n * large documents.\n *\n * @returns A Promise of the transformed document, or an `error:`-prefixed\n * string on failure.\n */\nexport function transformParallel(input: string, options: TransformOptions = {}): Promise<string> {\n return runParallelTransform(wasm as unknown as HookedWasm, input, options);\n}\n\n/**\n * Breakscape text (escape bitmark special characters).\n *\n * @param input - The text to breakscape.\n * @param options - Breakscape options (e.g. `{ format: \"plainText\", location: \"tag\" }`).\n * @returns Breakscaped text.\n */\nexport function breakscapeText(input: string, options: BreakscapeOptions = {}): string {\n const format = options.format ?? \"bitmark++\";\n const location = options.location ?? \"body\";\n return wasm.breakscape_text(input, format, location);\n}\n\n/**\n * Unbreakscape text (unescape bitmark special characters).\n *\n * @param input - The text to unbreakscape.\n * @param options - Unbreakscape options (e.g. `{ format: \"plainText\", location: \"tag\" }`).\n * @returns Unbreakscaped text.\n */\nexport function unbreakscapeText(input: string, options: BreakscapeOptions = {}): string {\n const format = options.format ?? \"bitmark++\";\n const location = options.location ?? \"body\";\n return wasm.unbreakscape_text(input, format, location);\n}\n\n/**\n * Query information about supported bit types.\n *\n * @param options - Info options (e.g. `{ infoType: \"bit\", format: \"json\", bit: \"cloze\" }`).\n * @returns Information string.\n */\nexport function info(options: InfoOptions = {}): string {\n const infoType = options.infoType ?? \"list\";\n const format = options.format ?? \"text\";\n const bit = options.bit ?? \"\";\n const pretty = options.pretty ?? false;\n const indent = options.indent ?? 2;\n return wasm.info(infoType, format, bit, pretty, indent);\n}\n\n/**\n * Generate bitmark text from a JSON AST.\n *\n * The reverse pipeline: `JSON → json_to_ast → AST → ast_to_bitmark`.\n *\n * @param input - JSON string of the parsed bit entries (forward output shape).\n * @param options - Generate options (e.g. `{ mode: \"full\" }`).\n * @returns Bitmark text. On failure, an `error:`-prefixed string.\n */\nexport function generate(input: string, options: ParseOptions = {}): string {\n return wasm.convert(input, \"json\", \"bitmark\", options.mode ?? \"optimized\", false, 2, 1);\n}\n","// This file is automatically generated. DO NOT EDIT.\n\n/* eslint-disable */\n\nexport const PACKAGE_INFO = {\n \"name\": \"@gmb/bitmark-parser\",\n \"version\": \"6.1.1\",\n \"author\": \"Get More Brain Ltd <info@getmorebrain.com>\",\n \"license\": \"ISC\",\n \"description\": \"A parser for bitmark text, powered by WebAssembly.\"\n};\n","// @zen-component: TS-HookedTransform\n\nimport type { BitView, OutputFormat, PatchEntry, TransformOptions } from \"../types.js\";\n\n/**\n * The minimal WASM surface the per-bit hook driver needs. Both the Node and\n * browser entry points satisfy this with their loaded module.\n */\nexport interface HookedWasm {\n is_bitmark(input: string): boolean;\n split_bits(input: string): string;\n split_json_bits(input: string): string;\n prettify(json: string, indent: number): string;\n transform(\n input: string,\n inputFormat: string,\n outputFormat: string,\n mode: string,\n patchJson: string,\n pretty: boolean,\n indent: number,\n spacesAroundValues: number,\n ): string;\n}\n\n/** A single bit's compute job: data only, safe to ship to a worker thread. */\nexport interface BitJob {\n index: number;\n source: string;\n inputFormat: \"bitmark\" | \"json\";\n outputFormat: OutputFormat;\n mode: string;\n patchJson: string;\n spacesAroundValues: number;\n}\n\n/**\n * The result of running `preHook` over a document's bits: the compute `jobs`\n * for the bits that survived (in document order) and the matching `views`\n * (so `postHook` can be called per surviving bit), plus the document-level\n * recombination settings.\n */\nexport interface TransformPlan {\n jobs: BitJob[];\n views: BitView[];\n output: OutputFormat;\n pretty: boolean;\n indent: number;\n}\n\nexport function isError(s: string): boolean {\n return s.startsWith(\"error:\");\n}\n\n/**\n * Normalise a thrown value to an `error:`-prefixed string, without\n * double-prefixing a message that already carries the prefix (split helpers\n * surface WASM `error:` strings as thrown `Error`s).\n */\nexport function errorString(e: unknown): string {\n const m = e instanceof Error ? e.message : String(e);\n return m.startsWith(\"error:\") ? m : `error: ${m}`;\n}\n\n/** Strip the outer `[ … ]` of a compact one-element JSON array. */\nexport function stripArray(doc: string): string {\n const t = doc.trim();\n return t.startsWith(\"[\") && t.endsWith(\"]\") ? t.slice(1, -1) : doc;\n}\n\nfunction normalisePatch(patch: TransformOptions[\"patch\"]): PatchEntry[] {\n if (patch === undefined) return [];\n if (typeof patch === \"string\") {\n const trimmed = patch.trim();\n return trimmed === \"\" ? [] : (JSON.parse(trimmed) as PatchEntry[]);\n }\n return patch;\n}\n\nfunction buildUnits(\n wasm: HookedWasm,\n input: string,\n inputIsBitmark: boolean,\n): { view: BitView; source: string }[] {\n if (inputIsBitmark) {\n const out = wasm.split_bits(input);\n if (isError(out)) throw new Error(out);\n const slices = JSON.parse(out) as { index: number; source: string }[];\n return slices.map((s) => ({\n view: { format: \"bitmark\", index: s.index, total: slices.length, source: s.source },\n source: s.source,\n }));\n }\n const out = wasm.split_json_bits(input);\n if (isError(out)) throw new Error(out);\n const envelopes = JSON.parse(out) as { bit?: unknown }[];\n return envelopes.map((env, index) => ({\n view: { format: \"json\", index, total: envelopes.length, bit: env.bit },\n // Per-bit transform consumes a one-bit JSON document.\n source: JSON.stringify([env]),\n }));\n}\n\n/**\n * Split the document and run `preHook` (on the calling thread) for each bit,\n * producing the surviving compute jobs + their views. This is the main-thread\n * half shared by the sync and worker-pool drivers — only the resulting\n * data-only {@link BitJob}s ever cross to a worker.\n */\nexport function planTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): TransformPlan {\n const mode = options.mode ?? \"optimized\";\n const output: OutputFormat = options.outputFormat ?? \"json\";\n const spacesAroundValues = options.spacesAroundValues ?? 1;\n const indent = options.indent ?? 2;\n const pretty = options.pretty ?? false;\n\n const sel = options.inputFormat ?? \"auto\";\n const inputIsBitmark = sel === \"bitmark\" || (sel !== \"json\" && wasm.is_bitmark(input));\n const inputFormat = inputIsBitmark ? \"bitmark\" : \"json\";\n\n const staticPatch = normalisePatch(options.patch);\n const units = buildUnits(wasm, input, inputIsBitmark);\n const total = units.length;\n\n const jobs: BitJob[] = [];\n const views: BitView[] = [];\n for (let index = 0; index < total; index++) {\n const { view, source } = units[index];\n view.index = index;\n view.total = total;\n\n const result = options.preHook ? options.preHook(view) || {} : {};\n if (result.drop) continue;\n\n const patches = result.patches ? [...staticPatch, ...result.patches] : staticPatch;\n jobs.push({\n index,\n source,\n inputFormat,\n outputFormat: result.outputFormat ?? output,\n mode,\n patchJson: JSON.stringify(patches),\n spacesAroundValues,\n });\n views.push(view);\n }\n return { jobs, views, output, pretty, indent };\n}\n\n/**\n * Compute one bit's rendered element synchronously via WASM. The per-bit\n * element is always compact JSON (the document is prettified once on\n * recombination). Returns an `error:`-prefixed string on failure.\n */\nexport function computeBit(wasm: HookedWasm, job: BitJob): string {\n const out = wasm.transform(\n job.source,\n job.inputFormat,\n job.outputFormat,\n job.mode,\n job.patchJson,\n false,\n 2,\n job.spacesAroundValues,\n );\n if (isError(out)) return out;\n return job.outputFormat === \"json\" ? stripArray(out) : out;\n}\n\n/** Recombine per-bit elements into the final document, in document order. */\nexport function recombine(\n wasm: HookedWasm,\n elements: string[],\n output: OutputFormat,\n pretty: boolean,\n indent: number,\n): string {\n // Bitmark and plain-text bits both join with newlines; only JSON wraps as an\n // array. (`text` is output-only, lossy plain-text extraction.)\n if (output === \"bitmark\" || output === \"text\") return elements.join(\"\\n\");\n const arr = `[${elements.join(\",\")}]`;\n return pretty ? wasm.prettify(arr, indent) : arr;\n}\n\n/**\n * Per-bit transform driver (synchronous, in-process): split the document, run\n * `preHook` for each bit on the calling thread, apply the static patch + any\n * hook patches, re-emit the bit, run `postHook`, then recombine in document\n * order.\n *\n * Hooks run synchronously on the calling thread; only data crosses into WASM.\n * Used when a `preHook`/`postHook` is supplied; the hookless path stays a\n * single `wasm.transform` call. Returns the document, or an `error:`-prefixed\n * string on failure.\n */\nexport function runHookedTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): string {\n let plan: TransformPlan;\n try {\n plan = planTransform(wasm, input, options);\n } catch (e) {\n return errorString(e);\n }\n\n const rendered: string[] = [];\n for (let i = 0; i < plan.jobs.length; i++) {\n const element = computeBit(wasm, plan.jobs[i]);\n if (isError(element)) return element;\n options.postHook?.(plan.views[i], element);\n rendered.push(element);\n }\n return recombine(wasm, rendered, plan.output, plan.pretty, plan.indent);\n}\n","// @zen-component: TS-ParallelOrchestrator\n\nimport type { TransformOptions } from \"../types.js\";\nimport { type BitJob, errorString, type HookedWasm, isError, planTransform, recombine } from \"./hooked-transform.js\";\n\n/**\n * A platform pool: compute `jobs` across up to `workers` workers, returning the\n * rendered element per job in submission order. Node and browser supply their\n * own (worker_threads / Worker); the orchestration around it is shared.\n */\nexport type RunJobs = (jobs: BitJob[], workers: number) => Promise<string[]>;\n\n/**\n * Shared parallel transform orchestration. The main-thread half — split +\n * `preHook` + recombine + `postHook` — is identical to the sync driver; only\n * the data-only per-bit jobs cross to `runJobs` (the platform pool). Closures\n * (`preHook`/`postHook`) never leave the calling thread.\n *\n * Returns the document, or an `error:`-prefixed string on failure.\n */\nexport async function orchestrateParallel(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n runJobs: RunJobs,\n): Promise<string> {\n let plan;\n try {\n plan = planTransform(wasm, input, options);\n } catch (e) {\n return errorString(e);\n }\n\n let elements: string[];\n try {\n elements = await runJobs(plan.jobs, options.workers ?? 4);\n } catch (e) {\n return errorString(e);\n }\n\n for (let i = 0; i < elements.length; i++) {\n if (isError(elements[i])) return elements[i];\n options.postHook?.(plan.views[i], elements[i]);\n }\n return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);\n}\n","// @zen-component: TS-WorkerPool\n//\n// A fixed-size Node worker_threads pool that computes per-bit transform jobs in\n// parallel. Jobs are dispatched to idle workers; results are matched by id and\n// returned in submission order. The pool is short-lived (created per\n// transformParallel call) and terminated when all jobs settle.\n\nimport { fileURLToPath } from \"node:url\";\nimport { Worker } from \"node:worker_threads\";\nimport type { BitJob } from \"../core/hooked-transform.js\";\n\ninterface JobResult {\n ok: boolean;\n element?: string;\n error?: string;\n}\n\n// The worker entry is emitted as a sibling CJS file in dist/ (see tsup config),\n// so a CJS-format worker runs regardless of how the package itself was loaded.\nfunction workerPath(): string {\n return fileURLToPath(new URL(\"./worker-entry.cjs\", import.meta.url));\n}\n\n/**\n * Run `jobs` across up to `workers` worker threads, returning the rendered\n * element for each job in the **same order** as `jobs`. Rejects on the first\n * worker error or job error.\n */\nexport function runJobsParallel(jobs: BitJob[], workers: number): Promise<string[]> {\n if (jobs.length === 0) return Promise.resolve([]);\n const poolSize = Math.max(1, Math.min(workers, jobs.length));\n const path = workerPath();\n\n return new Promise<string[]>((resolve, reject) => {\n const results = new Array<string>(jobs.length);\n let next = 0;\n let settled = 0;\n let done = false;\n const pool: Worker[] = [];\n\n const shutdown = () => {\n for (const w of pool) void w.terminate();\n };\n const fail = (err: Error) => {\n if (done) return;\n done = true;\n shutdown();\n reject(err);\n };\n\n const dispatch = (w: Worker) => {\n if (done) return;\n if (next >= jobs.length) return; // no more work for this worker\n const id = next++;\n w.postMessage({ id, job: jobs[id] });\n };\n\n for (let i = 0; i < poolSize; i++) {\n const w = new Worker(path);\n pool.push(w);\n w.on(\"message\", (res: JobResult & { id: number }) => {\n if (done) return;\n if (!res.ok) {\n fail(new Error(res.error ?? \"worker job failed\"));\n return;\n }\n results[res.id] = res.element as string;\n settled++;\n if (settled === jobs.length) {\n done = true;\n shutdown();\n resolve(results);\n return;\n }\n dispatch(w);\n });\n w.on(\"error\", fail);\n w.on(\"exit\", (code) => {\n if (!done && code !== 0) fail(new Error(`worker exited with code ${code}`));\n });\n }\n\n // Prime each worker with one job.\n for (const w of pool) dispatch(w);\n });\n}\n","// @zen-component: TS-TransformParallel\n//\n// Node-only parallel transform: the main-thread half (split + preHook +\n// recombine + postHook) is shared with the synchronous driver and the browser\n// pool via orchestrateParallel; only the per-bit WASM compute is fanned out\n// across a worker_threads pool.\n\nimport { orchestrateParallel } from \"../core/parallel.js\";\nimport type { HookedWasm } from \"../core/hooked-transform.js\";\nimport type { TransformOptions } from \"../types.js\";\nimport { runJobsParallel } from \"./pool.js\";\n\n/**\n * Parallel counterpart of `transform` on Node. `preHook`/`postHook` run on the\n * calling thread; only data-only jobs cross to the worker_threads pool.\n */\nexport function runParallelTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): Promise<string> {\n return orchestrateParallel(wasm, input, options, runJobsParallel);\n}\n"],"mappings":";AAEA,SAAS,qBAAqB;;;ACEvB,IAAM,eAAe;AAAA,EAC1B,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,WAAW;AAAA,EACX,eAAe;AACjB;;;ACwCO,SAAS,QAAQ,GAAoB;AAC1C,SAAO,EAAE,WAAW,QAAQ;AAC9B;AAOO,SAAS,YAAY,GAAoB;AAC9C,QAAM,IAAI,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;AACnD,SAAO,EAAE,WAAW,QAAQ,IAAI,IAAI,UAAU,CAAC;AACjD;AAGO,SAAS,WAAW,KAAqB;AAC9C,QAAM,IAAI,IAAI,KAAK;AACnB,SAAO,EAAE,WAAW,GAAG,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,MAAM,GAAG,EAAE,IAAI;AACjE;AAEA,SAAS,eAAe,OAAgD;AACtE,MAAI,UAAU,OAAW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K,UAAU,QAAQ,KAAK,QAAQ,MAAM;AACxD;AAWO,SAAS,SAAS,OAAe,UAAwB,CAAC,GAAW;AAC1E,SAAO,KAAK,QAAQ,OAAO,QAAQ,WAAW,QAAQ,QAAQ,aAAa,OAAO,GAAG,CAAC;AACxF;","names":["wasm","out","wasm","wasm","require"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/generated/package_info.ts","../src/core/hooked-transform.ts","../src/core/parallel.ts","../src/node/pool.ts","../src/node/transform-parallel.ts"],"sourcesContent":["// @zen-component: WASM-TSBindings\n\nimport { createRequire } from \"node:module\";\nimport { PACKAGE_INFO } from \"./generated/package_info.js\";\nimport { runHookedTransform, type HookedWasm } from \"./core/hooked-transform.js\";\nimport { runParallelTransform } from \"./node/transform-parallel.js\";\nimport type { LexOptions, ParseOptions, ConvertOptions, BreakscapeOptions, InfoOptions, NormalizeOptions, TransformOptions, BitSlice } from \"./types.js\";\nconst require = createRequire(import.meta.url);\nconst wasm = require(\"../wasm/bitmark_wasm.js\") as typeof import(\"../wasm/bitmark_wasm.js\");\n\nexport type { LexOptions, LexStage, ParseOptions, ConvertOptions, OutputMode, BreakscapeOptions, TextFormat, TextLocation, InfoOptions, InfoType, InfoFormat, InputFormat, OutputFormat, NormalizeOptions, TransformOptions, PatchOp, PatchEntry, BitSlice, BitView, PreHook, PostHook, PreHookResult } from \"./types.js\";\n\n/**\n * Get the version of the @gmb/bitmark-parser library.\n *\n * @returns Version string (e.g. \"3.0.0\").\n */\nexport function version(): string {\n return PACKAGE_INFO.version;\n}\n\n/**\n * Lex bitmark input text, returning one line per token.\n *\n * @param input - The bitmark source text.\n * @param options - Lex options (e.g. `{ stage: \"lex\" }`).\n * @returns Token dump string (one token per line).\n */\nexport function lex(input: string, options: LexOptions = {}): string {\n return wasm.lex(input, options.stage ?? \"lex\");\n}\n\n/**\n * Parse bitmark input text and return structured JSON entries.\n *\n * Each entry contains `bit`, `parser`, and `bitmark` fields.\n *\n * @param input - The bitmark source text.\n * @param options - Parse options (e.g. `{ mode: \"full\" }`).\n * @returns JSON string array of structured parsed entries.\n */\nexport function parse(input: string, options: ParseOptions = {}): string {\n return wasm.parse(input, options.mode ?? \"optimized\");\n}\n\n/**\n * Auto-detect input format and convert between bitmark and JSON.\n *\n * @param input - Bitmark or JSON input text.\n * @param options - Convert options (e.g. `{ mode: \"full\", warnings: true }`).\n * @returns Converted output string. For bitmark input, this is a JSON string\n * array of structured parsed entries (`bit`, `parser`, `bitmark`).\n */\nexport function convert(input: string, options: ConvertOptions = {}): string {\n return wasm.convert(\n input,\n options.inputFormat ?? \"auto\",\n options.outputFormat ?? \"auto\",\n options.mode ?? \"optimized\",\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Re-emit input in its own format at optimized mode.\n *\n * @param input - Input text (bitmark, JSON, or a markup format such as html/xml).\n * @param options - `inputFormat` selects the format (default: `\"auto\"`); the\n * output is re-emitted in that same format.\n * @returns Optimized output in the same format as the input.\n */\nexport function optimize(input: string, options: NormalizeOptions = {}): string {\n return wasm.optimize(input, options.inputFormat ?? \"auto\", options.pretty ?? false, options.indent ?? 2);\n}\n\n/**\n * Re-emit input in its own format at full mode (all keys). Aliased as\n * {@link expand}. `options.inputFormat` selects the format (default: `\"auto\"`).\n */\nexport function fullize(input: string, options: NormalizeOptions = {}): string {\n return wasm.fullize(input, options.inputFormat ?? \"auto\", options.pretty ?? false, options.indent ?? 2);\n}\n\n/** Alias of {@link fullize}. */\nexport const expand = fullize;\n\n/**\n * Re-emit input in its own format in canonical form. `options.inputFormat`\n * selects the format (default: `\"auto\"`).\n */\nexport function canonicalize(input: string, options: NormalizeOptions = {}): string {\n return wasm.canonicalize(\n input,\n options.inputFormat ?? \"auto\",\n options.mode ?? \"optimized\",\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Count the bits in `input`, auto-detecting bitmark vs JSON.\n *\n * @throws If the input cannot be parsed.\n */\nexport function countBits(input: string): number {\n const out = wasm.count_bits(input);\n if (out.startsWith(\"error:\")) throw new Error(out);\n return Number.parseInt(out, 10);\n}\n\n/**\n * Split a bitmark document into per-bit source slices.\n *\n * @returns Array of `{ index, byteStart, byteEnd, source }`.\n */\nexport function splitBits(input: string): BitSlice[] {\n return JSON.parse(wasm.split_bits(input)) as BitSlice[];\n}\n\n/**\n * Transform a document bit-by-bit: apply an optional static `patch` and/or\n * per-bit `preHook`/`postHook`, then re-emit.\n *\n * With neither hook, the whole document is transformed in a single WASM pass\n * (the fast path). When a `preHook` or `postHook` is supplied, `transform`\n * drives the bits one at a time on the calling thread — the hook inspects each\n * bit, may return patches / an output-format override / `drop`, and only data\n * crosses into WASM. The patch may be an array of entries or a JSON string.\n *\n * @returns The transformed document, or an `error:`-prefixed string on failure.\n */\nexport function transform(input: string, options: TransformOptions = {}): string {\n if (options.preHook || options.postHook) {\n return runHookedTransform(wasm as unknown as HookedWasm, input, options);\n }\n const patchJson =\n options.patch === undefined\n ? \"\"\n : typeof options.patch === \"string\"\n ? options.patch\n : JSON.stringify(options.patch);\n return wasm.transform(\n input,\n options.inputFormat ?? \"auto\",\n options.outputFormat ?? \"json\",\n options.mode ?? \"optimized\",\n patchJson,\n options.pretty ?? false,\n options.indent ?? 2,\n options.spacesAroundValues ?? 1,\n );\n}\n\n/**\n * Parallel counterpart of {@link transform} (Node only). Fans the per-bit WASM\n * compute across a `worker_threads` pool (`options.workers`, default `4`),\n * while `preHook`/`postHook` still run on the calling thread. Output is\n * identical to {@link transform}; this trades startup cost for throughput on\n * large documents.\n *\n * @returns A Promise of the transformed document, or an `error:`-prefixed\n * string on failure.\n */\nexport function transformParallel(input: string, options: TransformOptions = {}): Promise<string> {\n return runParallelTransform(wasm as unknown as HookedWasm, input, options);\n}\n\n/**\n * Breakscape text (escape bitmark special characters).\n *\n * @param input - The text to breakscape.\n * @param options - Breakscape options (e.g. `{ format: \"plainText\", location: \"tag\" }`).\n * @returns Breakscaped text.\n */\nexport function breakscapeText(input: string, options: BreakscapeOptions = {}): string {\n const format = options.format ?? \"bitmark++\";\n const location = options.location ?? \"body\";\n return wasm.breakscape_text(input, format, location);\n}\n\n/**\n * Unbreakscape text (unescape bitmark special characters).\n *\n * @param input - The text to unbreakscape.\n * @param options - Unbreakscape options (e.g. `{ format: \"plainText\", location: \"tag\" }`).\n * @returns Unbreakscaped text.\n */\nexport function unbreakscapeText(input: string, options: BreakscapeOptions = {}): string {\n const format = options.format ?? \"bitmark++\";\n const location = options.location ?? \"body\";\n return wasm.unbreakscape_text(input, format, location);\n}\n\n/**\n * Query information about supported bit types.\n *\n * @param options - Info options (e.g. `{ infoType: \"bit\", format: \"json\", bit: \"cloze\" }`).\n * @returns Information string.\n */\nexport function info(options: InfoOptions = {}): string {\n const infoType = options.infoType ?? \"list\";\n const format = options.format ?? \"text\";\n const bit = options.bit ?? \"\";\n const pretty = options.pretty ?? false;\n const indent = options.indent ?? 2;\n return wasm.info(infoType, format, bit, pretty, indent);\n}\n\n/**\n * Generate bitmark text from a JSON AST.\n *\n * The reverse pipeline: `JSON → json_to_ast → AST → ast_to_bitmark`.\n *\n * @param input - JSON string of the parsed bit entries (forward output shape).\n * @param options - Generate options (e.g. `{ mode: \"full\" }`).\n * @returns Bitmark text. On failure, an `error:`-prefixed string.\n */\nexport function generate(input: string, options: ParseOptions = {}): string {\n return wasm.convert(input, \"json\", \"bitmark\", options.mode ?? \"optimized\", false, 2, 1);\n}\n","// This file is automatically generated. DO NOT EDIT.\n\n/* eslint-disable */\n\nexport const PACKAGE_INFO = {\n \"name\": \"@gmb/bitmark-parser\",\n \"version\": \"6.1.3\",\n \"author\": \"Get More Brain Ltd <info@getmorebrain.com>\",\n \"license\": \"ISC\",\n \"description\": \"A parser for bitmark text, powered by WebAssembly.\"\n};\n","// @zen-component: TS-HookedTransform\n\nimport type { BitView, OutputFormat, PatchEntry, TransformOptions } from \"../types.js\";\n\n/**\n * The minimal WASM surface the per-bit hook driver needs. Both the Node and\n * browser entry points satisfy this with their loaded module.\n */\nexport interface HookedWasm {\n is_bitmark(input: string): boolean;\n split_bits(input: string): string;\n split_json_bits(input: string): string;\n prettify(json: string, indent: number): string;\n transform(\n input: string,\n inputFormat: string,\n outputFormat: string,\n mode: string,\n patchJson: string,\n pretty: boolean,\n indent: number,\n spacesAroundValues: number,\n ): string;\n}\n\n/** A single bit's compute job: data only, safe to ship to a worker thread. */\nexport interface BitJob {\n index: number;\n source: string;\n inputFormat: \"bitmark\" | \"json\";\n outputFormat: OutputFormat;\n mode: string;\n patchJson: string;\n spacesAroundValues: number;\n}\n\n/**\n * The result of running `preHook` over a document's bits: the compute `jobs`\n * for the bits that survived (in document order) and the matching `views`\n * (so `postHook` can be called per surviving bit), plus the document-level\n * recombination settings.\n */\nexport interface TransformPlan {\n jobs: BitJob[];\n views: BitView[];\n output: OutputFormat;\n pretty: boolean;\n indent: number;\n}\n\nexport function isError(s: string): boolean {\n return s.startsWith(\"error:\");\n}\n\n/**\n * Normalise a thrown value to an `error:`-prefixed string, without\n * double-prefixing a message that already carries the prefix (split helpers\n * surface WASM `error:` strings as thrown `Error`s).\n */\nexport function errorString(e: unknown): string {\n const m = e instanceof Error ? e.message : String(e);\n return m.startsWith(\"error:\") ? m : `error: ${m}`;\n}\n\n/** Strip the outer `[ … ]` of a compact one-element JSON array. */\nexport function stripArray(doc: string): string {\n const t = doc.trim();\n return t.startsWith(\"[\") && t.endsWith(\"]\") ? t.slice(1, -1) : doc;\n}\n\nfunction normalisePatch(patch: TransformOptions[\"patch\"]): PatchEntry[] {\n if (patch === undefined) return [];\n if (typeof patch === \"string\") {\n const trimmed = patch.trim();\n return trimmed === \"\" ? [] : (JSON.parse(trimmed) as PatchEntry[]);\n }\n return patch;\n}\n\nfunction buildUnits(\n wasm: HookedWasm,\n input: string,\n inputIsBitmark: boolean,\n): { view: BitView; source: string }[] {\n if (inputIsBitmark) {\n const out = wasm.split_bits(input);\n if (isError(out)) throw new Error(out);\n const slices = JSON.parse(out) as { index: number; source: string }[];\n return slices.map((s) => ({\n view: { format: \"bitmark\", index: s.index, total: slices.length, source: s.source },\n source: s.source,\n }));\n }\n const out = wasm.split_json_bits(input);\n if (isError(out)) throw new Error(out);\n const envelopes = JSON.parse(out) as { bit?: unknown }[];\n return envelopes.map((env, index) => ({\n view: { format: \"json\", index, total: envelopes.length, bit: env.bit },\n // Per-bit transform consumes a one-bit JSON document.\n source: JSON.stringify([env]),\n }));\n}\n\n/**\n * Split the document and run `preHook` (on the calling thread) for each bit,\n * producing the surviving compute jobs + their views. This is the main-thread\n * half shared by the sync and worker-pool drivers — only the resulting\n * data-only {@link BitJob}s ever cross to a worker.\n */\nexport function planTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): TransformPlan {\n const mode = options.mode ?? \"optimized\";\n const output: OutputFormat = options.outputFormat ?? \"json\";\n const spacesAroundValues = options.spacesAroundValues ?? 1;\n const indent = options.indent ?? 2;\n const pretty = options.pretty ?? false;\n\n const sel = options.inputFormat ?? \"auto\";\n const inputIsBitmark = sel === \"bitmark\" || (sel !== \"json\" && wasm.is_bitmark(input));\n const inputFormat = inputIsBitmark ? \"bitmark\" : \"json\";\n\n const staticPatch = normalisePatch(options.patch);\n const units = buildUnits(wasm, input, inputIsBitmark);\n const total = units.length;\n\n const jobs: BitJob[] = [];\n const views: BitView[] = [];\n for (let index = 0; index < total; index++) {\n const { view, source } = units[index];\n view.index = index;\n view.total = total;\n\n const result = options.preHook ? options.preHook(view) || {} : {};\n if (result.drop) continue;\n\n const patches = result.patches ? [...staticPatch, ...result.patches] : staticPatch;\n jobs.push({\n index,\n source,\n inputFormat,\n outputFormat: result.outputFormat ?? output,\n mode,\n patchJson: JSON.stringify(patches),\n spacesAroundValues,\n });\n views.push(view);\n }\n return { jobs, views, output, pretty, indent };\n}\n\n/**\n * Compute one bit's rendered element synchronously via WASM. The per-bit\n * element is always compact JSON (the document is prettified once on\n * recombination). Returns an `error:`-prefixed string on failure.\n */\nexport function computeBit(wasm: HookedWasm, job: BitJob): string {\n const out = wasm.transform(\n job.source,\n job.inputFormat,\n job.outputFormat,\n job.mode,\n job.patchJson,\n false,\n 2,\n job.spacesAroundValues,\n );\n if (isError(out)) return out;\n return job.outputFormat === \"json\" ? stripArray(out) : out;\n}\n\n/** Recombine per-bit elements into the final document, in document order. */\nexport function recombine(\n wasm: HookedWasm,\n elements: string[],\n output: OutputFormat,\n pretty: boolean,\n indent: number,\n): string {\n // Bitmark and plain-text bits both join with newlines; only JSON wraps as an\n // array. (`text` is output-only, lossy plain-text extraction.)\n if (output === \"bitmark\" || output === \"text\") return elements.join(\"\\n\");\n const arr = `[${elements.join(\",\")}]`;\n return pretty ? wasm.prettify(arr, indent) : arr;\n}\n\n/**\n * Per-bit transform driver (synchronous, in-process): split the document, run\n * `preHook` for each bit on the calling thread, apply the static patch + any\n * hook patches, re-emit the bit, run `postHook`, then recombine in document\n * order.\n *\n * Hooks run synchronously on the calling thread; only data crosses into WASM.\n * Used when a `preHook`/`postHook` is supplied; the hookless path stays a\n * single `wasm.transform` call. Returns the document, or an `error:`-prefixed\n * string on failure.\n */\nexport function runHookedTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): string {\n let plan: TransformPlan;\n try {\n plan = planTransform(wasm, input, options);\n } catch (e) {\n return errorString(e);\n }\n\n const rendered: string[] = [];\n for (let i = 0; i < plan.jobs.length; i++) {\n const element = computeBit(wasm, plan.jobs[i]);\n if (isError(element)) return element;\n options.postHook?.(plan.views[i], element);\n rendered.push(element);\n }\n return recombine(wasm, rendered, plan.output, plan.pretty, plan.indent);\n}\n","// @zen-component: TS-ParallelOrchestrator\n\nimport type { TransformOptions } from \"../types.js\";\nimport { type BitJob, errorString, type HookedWasm, isError, planTransform, recombine } from \"./hooked-transform.js\";\n\n/**\n * A platform pool: compute `jobs` across up to `workers` workers, returning the\n * rendered element per job in submission order. Node and browser supply their\n * own (worker_threads / Worker); the orchestration around it is shared.\n */\nexport type RunJobs = (jobs: BitJob[], workers: number) => Promise<string[]>;\n\n/**\n * Shared parallel transform orchestration. The main-thread half — split +\n * `preHook` + recombine + `postHook` — is identical to the sync driver; only\n * the data-only per-bit jobs cross to `runJobs` (the platform pool). Closures\n * (`preHook`/`postHook`) never leave the calling thread.\n *\n * Returns the document, or an `error:`-prefixed string on failure.\n */\nexport async function orchestrateParallel(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n runJobs: RunJobs,\n): Promise<string> {\n let plan;\n try {\n plan = planTransform(wasm, input, options);\n } catch (e) {\n return errorString(e);\n }\n\n let elements: string[];\n try {\n elements = await runJobs(plan.jobs, options.workers ?? 4);\n } catch (e) {\n return errorString(e);\n }\n\n for (let i = 0; i < elements.length; i++) {\n if (isError(elements[i])) return elements[i];\n options.postHook?.(plan.views[i], elements[i]);\n }\n return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);\n}\n","// @zen-component: TS-WorkerPool\n//\n// A fixed-size Node worker_threads pool that computes per-bit transform jobs in\n// parallel. Jobs are dispatched to idle workers; results are matched by id and\n// returned in submission order. The pool is short-lived (created per\n// transformParallel call) and terminated when all jobs settle.\n\nimport { fileURLToPath } from \"node:url\";\nimport { Worker } from \"node:worker_threads\";\nimport type { BitJob } from \"../core/hooked-transform.js\";\n\ninterface JobResult {\n ok: boolean;\n element?: string;\n error?: string;\n}\n\n// The worker entry is emitted as a sibling CJS file in dist/ (see tsup config),\n// so a CJS-format worker runs regardless of how the package itself was loaded.\nfunction workerPath(): string {\n return fileURLToPath(new URL(\"./worker-entry.cjs\", import.meta.url));\n}\n\n/**\n * Run `jobs` across up to `workers` worker threads, returning the rendered\n * element for each job in the **same order** as `jobs`. Rejects on the first\n * worker error or job error.\n */\nexport function runJobsParallel(jobs: BitJob[], workers: number): Promise<string[]> {\n if (jobs.length === 0) return Promise.resolve([]);\n const poolSize = Math.max(1, Math.min(workers, jobs.length));\n const path = workerPath();\n\n return new Promise<string[]>((resolve, reject) => {\n const results = new Array<string>(jobs.length);\n let next = 0;\n let settled = 0;\n let done = false;\n const pool: Worker[] = [];\n\n const shutdown = () => {\n for (const w of pool) void w.terminate();\n };\n const fail = (err: Error) => {\n if (done) return;\n done = true;\n shutdown();\n reject(err);\n };\n\n const dispatch = (w: Worker) => {\n if (done) return;\n if (next >= jobs.length) return; // no more work for this worker\n const id = next++;\n w.postMessage({ id, job: jobs[id] });\n };\n\n for (let i = 0; i < poolSize; i++) {\n const w = new Worker(path);\n pool.push(w);\n w.on(\"message\", (res: JobResult & { id: number }) => {\n if (done) return;\n if (!res.ok) {\n fail(new Error(res.error ?? \"worker job failed\"));\n return;\n }\n results[res.id] = res.element as string;\n settled++;\n if (settled === jobs.length) {\n done = true;\n shutdown();\n resolve(results);\n return;\n }\n dispatch(w);\n });\n w.on(\"error\", fail);\n w.on(\"exit\", (code) => {\n if (!done && code !== 0) fail(new Error(`worker exited with code ${code}`));\n });\n }\n\n // Prime each worker with one job.\n for (const w of pool) dispatch(w);\n });\n}\n","// @zen-component: TS-TransformParallel\n//\n// Node-only parallel transform: the main-thread half (split + preHook +\n// recombine + postHook) is shared with the synchronous driver and the browser\n// pool via orchestrateParallel; only the per-bit WASM compute is fanned out\n// across a worker_threads pool.\n\nimport { orchestrateParallel } from \"../core/parallel.js\";\nimport type { HookedWasm } from \"../core/hooked-transform.js\";\nimport type { TransformOptions } from \"../types.js\";\nimport { runJobsParallel } from \"./pool.js\";\n\n/**\n * Parallel counterpart of `transform` on Node. `preHook`/`postHook` run on the\n * calling thread; only data-only jobs cross to the worker_threads pool.\n */\nexport function runParallelTransform(\n wasm: HookedWasm,\n input: string,\n options: TransformOptions,\n): Promise<string> {\n return orchestrateParallel(wasm, input, options, runJobsParallel);\n}\n"],"mappings":";AAEA,SAAS,qBAAqB;;;ACEvB,IAAM,eAAe;AAAA,EAC1B,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,WAAW;AAAA,EACX,eAAe;AACjB;;;ACwCO,SAAS,QAAQ,GAAoB;A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AAW,QAAQ,YAAY;AACrC,SAAO,KAAK,gBAAgB,OAAO,QAAQ,QAAQ;AACrD;AASO,SAAS,iBAAiB,OAAe,UAA6B,CAAC,GAAW;AACvF,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,WAAW,QAAQ,YAAY;AACrC,SAAO,KAAK,kBAAkB,OAAO,QAAQ,QAAQ;AACvD;AAQO,SAAS,KAAK,UAAuB,CAAC,GAAW;AACtD,QAAM,WAAW,QAAQ,YAAY;AACrC,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,MAAM,QAAQ,OAAO;AAC3B,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,SAAS,QAAQ,UAAU;AACjC,SAAO,KAAK,KAAK,UAAU,QAAQ,KAAK,QAAQ,MAAM;AACxD;AAWO,SAAS,SAAS,OAAe,UAAwB,CAAC,GAAW;AAC1E,SAAO,KAAK,QAAQ,OAAO,QAAQ,WAAW,QAAQ,QAAQ,aAAa,OAAO,GAAG,CAAC;AACxF;","names":["wasm","out","wasm","wasm","require"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@gmb/bitmark-parser",
3
- "version": "6.1.1",
3
+ "version": "6.1.3",
4
4
  "description": "A parser for bitmark text, powered by WebAssembly.",
5
5
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
6
6
  "license": "ISC",
7
7
  "homepage": "https://github.com/getMoreBrain/bitmark-parser#readme",
8
8
  "bin": {
9
- "bitmark-parser-wasm": "./dist/cli.js"
9
+ "bitmark": "bin/bitmark"
10
10
  },
11
11
  "type": "module",
12
12
  "browser": "./dist/browser/esm/index.js",
@@ -47,6 +47,7 @@
47
47
  "files": [
48
48
  "dist",
49
49
  "wasm",
50
+ "bin",
50
51
  "README.md",
51
52
  "LICENSE"
52
53
  ],
@@ -55,16 +56,21 @@
55
56
  "version:check": "bash scripts/version-check.sh",
56
57
  "build:wasm": "bash scripts/build-wasm.sh",
57
58
  "build:ts": "npm run init && tsup",
58
- "build": "npm run version:check && npm run build:wasm && npm run build:ts",
59
- "test": "node test/smoke.mjs && node --test test/cross-validate.mjs && node --test test/cli.test.mjs && node --test test/unified.test.mjs && node --test test/parallel.test.mjs",
59
+ "build:binaries": "bash scripts/build-binaries.sh",
60
+ "build": "npm run version:check && npm run build:wasm && npm run build:ts && npm run build:binaries",
61
+ "test": "node --test test/launcher-e2e.mjs && node test/smoke.mjs && node --test test/cross-validate.mjs && node --test test/cli.test.mjs && node --test test/unified.test.mjs && node --test test/parallel.test.mjs",
60
62
  "test:browser": "bash scripts/run-browser-tests.sh",
61
63
  "test:browser-smoke": "bash scripts/launch-browser-smoke.sh",
62
64
  "test:browser-perf": "bash scripts/launch-browser-perf.sh",
63
65
  "test:cli-perf": "bash scripts/launch-cli-perf.sh",
64
66
  "prepublishOnly": "npm run build && npm test"
65
67
  },
66
- "dependencies": {
67
- "commander": "^14.0.0"
68
+ "optionalDependencies": {
69
+ "@gmb/bitmark-parser-linux-x64": "6.1.3",
70
+ "@gmb/bitmark-parser-linux-arm64": "6.1.3",
71
+ "@gmb/bitmark-parser-darwin-x64": "6.1.3",
72
+ "@gmb/bitmark-parser-darwin-arm64": "6.1.3",
73
+ "@gmb/bitmark-parser-win32-x64": "6.1.3"
68
74
  },
69
75
  "devDependencies": {
70
76
  "@types/node": "^25.2.2",