@gmb/bitmark-parser 6.1.0 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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.0\",\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 if (output === \"bitmark\") 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,EAA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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","../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,U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Q,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,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmb/bitmark-parser",
3
- "version": "6.1.0",
3
+ "version": "6.1.1",
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",
@@ -1,37 +1,13 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  /**
4
- * Lex bitmark input text, returning one line per token in the same format as
5
- * the Rust CLI: `{kind:?} {span:?} "{text}"`.
6
- *
7
- * `stage` selects the lexer pipeline:
8
- * - `"lex"` — combined (default)
9
- * - `"lex-json"` — combined, JSON array output
10
- */
11
- export function lex(input: string, stage: string): string;
12
- /**
13
- * Pretty-print a compact JSON string with the given indent. Used to format a
14
- * document recombined on the JS side (the per-bit hook path) so its output
15
- * matches the in-Rust recombination byte-for-byte.
16
- */
17
- export function prettify(json: string, indent: number): string;
18
- /**
19
- * Unbreakscape text (unescape bitmark special characters).
20
- *
21
- * `format`: `"bitmark++"` (default) or `"plainText"`
22
- * `location`: `"body"` (default) or `"tag"`
4
+ * Re-emit input in its own format in canonical form at `mode`.
23
5
  */
24
- export function unbreakscape_text(input: string, format: string, location: string): string;
6
+ export function canonicalize(input: string, mode: string, pretty: boolean, indent: number, spaces_around_values: number): string;
25
7
  /**
26
- * Query information about supported bit types.
27
- *
28
- * `info_type`: `"list"`, `"bit"`, `"all"`, or `"deprecated"`
29
- * `format`: `"text"` or `"json"`
30
- * `bit`: bit name (required when `info_type` is `"bit"`)
31
- * `pretty`: whether to pretty-print JSON output
32
- * `indent`: indent size for pretty-printing (default: 2)
8
+ * Re-emit input in its own format at full mode (all keys).
33
9
  */
34
- export function info(info_type: string, format: string, bit: string, pretty: boolean, indent: number): string;
10
+ export function fullize(input: string, pretty: boolean, indent: number): string;
35
11
  /**
36
12
  * Apply a patch (a JSON array of patch entries) to every bit and re-emit.
37
13
  *
@@ -43,9 +19,28 @@ export function info(info_type: string, format: string, bit: string, pretty: boo
43
19
  */
44
20
  export function transform(input: string, input_format_sel: string, output_format_sel: string, mode: string, patch_json: string, pretty: boolean, indent: number, spaces_around_values: number): string;
45
21
  /**
46
- * Re-emit input in its own format in canonical form at `mode`.
22
+ * Split a bitmark document into per-bit source slices.
23
+ *
24
+ * Returns a JSON array of `{ index, byteStart, byteEnd, source }`. Lets a JS
25
+ * caller chunk a document at bit boundaries (e.g. to feed a worker pool).
47
26
  */
48
- export function canonicalize(input: string, mode: string, pretty: boolean, indent: number, spaces_around_values: number): string;
27
+ export function split_bits(input: string): string;
28
+ /**
29
+ * Breakscape text (escape bitmark special characters).
30
+ *
31
+ * `format`: `"bitmark++"` (default) or `"plainText"`
32
+ * `location`: `"body"` (default) or `"tag"`
33
+ */
34
+ export function breakscape_text(input: string, format: string, location: string): string;
35
+ /**
36
+ * Lex bitmark input text, returning one line per token in the same format as
37
+ * the Rust CLI: `{kind:?} {span:?} "{text}"`.
38
+ *
39
+ * `stage` selects the lexer pipeline:
40
+ * - `"lex"` — combined (default)
41
+ * - `"lex-json"` — combined, JSON array output
42
+ */
43
+ export function lex(input: string, stage: string): string;
49
44
  /**
50
45
  * Split a JSON document (a top-level array of bit envelopes) into its per-bit
51
46
  * envelope objects, returned as a JSON array string. Lets a JS caller iterate
@@ -54,30 +49,31 @@ export function canonicalize(input: string, mode: string, pretty: boolean, inden
54
49
  */
55
50
  export function split_json_bits(input: string): string;
56
51
  /**
57
- * Re-emit input in its own format at full mode (all keys).
52
+ * Unbreakscape text (unescape bitmark special characters).
53
+ *
54
+ * `format`: `"bitmark++"` (default) or `"plainText"`
55
+ * `location`: `"body"` (default) or `"tag"`
58
56
  */
59
- export function fullize(input: string, pretty: boolean, indent: number): string;
57
+ export function unbreakscape_text(input: string, format: string, location: string): string;
60
58
  /**
61
- * Convert between bitmark and JSON with explicit input/output formats + mode.
62
- *
63
- * `input_format`: `"auto"` (default) | `"bitmark"` | `"json"`.
64
- * `output_format`: `"auto"` (opposite of input) | `"bitmark"` | `"json"`.
65
- * `mode`: `"optimized"` (default) | `"full"`.
66
- * Returns the converted text/JSON, or a string prefixed `error:` on failure.
59
+ * Count the bits in `input` (auto-detecting bitmark vs JSON).
60
+ * Returns the count as a decimal string, or `error: …`.
67
61
  */
68
- export function convert(input: string, input_format_sel: string, output_format_sel: string, mode: string, pretty: boolean, indent: number, spaces_around_values: number): string;
62
+ export function count_bits(input: string): string;
69
63
  /**
70
- * Whether `input` looks like bitmark (vs JSON). Mirrors the auto-detection
71
- * used across the API so a JS caller can resolve `"auto"` consistently.
64
+ * Re-emit input in its own format at optimized mode (omit natural defaults).
72
65
  */
73
- export function is_bitmark(input: string): boolean;
66
+ export function optimize(input: string, pretty: boolean, indent: number): string;
74
67
  /**
75
- * Breakscape text (escape bitmark special characters).
68
+ * Query information about supported bit types.
76
69
  *
77
- * `format`: `"bitmark++"` (default) or `"plainText"`
78
- * `location`: `"body"` (default) or `"tag"`
70
+ * `info_type`: `"list"`, `"bit"`, `"all"`, or `"deprecated"`
71
+ * `format`: `"text"` or `"json"`
72
+ * `bit`: bit name (required when `info_type` is `"bit"`)
73
+ * `pretty`: whether to pretty-print JSON output
74
+ * `indent`: indent size for pretty-printing (default: 2)
79
75
  */
80
- export function breakscape_text(input: string, format: string, location: string): string;
76
+ export function info(info_type: string, format: string, bit: string, pretty: boolean, indent: number): string;
81
77
  /**
82
78
  * Parse bitmark input text and return the reference JSON format.
83
79
  *
@@ -87,18 +83,22 @@ export function breakscape_text(input: string, format: string, location: string)
87
83
  */
88
84
  export function parse(input: string, mode: string): string;
89
85
  /**
90
- * Re-emit input in its own format at optimized mode (omit natural defaults).
86
+ * Whether `input` looks like bitmark (vs JSON). Mirrors the auto-detection
87
+ * used across the API so a JS caller can resolve `"auto"` consistently.
91
88
  */
92
- export function optimize(input: string, pretty: boolean, indent: number): string;
89
+ export function is_bitmark(input: string): boolean;
93
90
  /**
94
- * Count the bits in `input` (auto-detecting bitmark vs JSON).
95
- * Returns the count as a decimal string, or `error: …`.
91
+ * Pretty-print a compact JSON string with the given indent. Used to format a
92
+ * document recombined on the JS side (the per-bit hook path) so its output
93
+ * matches the in-Rust recombination byte-for-byte.
96
94
  */
97
- export function count_bits(input: string): string;
95
+ export function prettify(json: string, indent: number): string;
98
96
  /**
99
- * Split a bitmark document into per-bit source slices.
97
+ * Convert between bitmark and JSON with explicit input/output formats + mode.
100
98
  *
101
- * Returns a JSON array of `{ index, byteStart, byteEnd, source }`. Lets a JS
102
- * caller chunk a document at bit boundaries (e.g. to feed a worker pool).
99
+ * `input_format`: `"auto"` (default) | `"bitmark"` | `"json"`.
100
+ * `output_format`: `"auto"` (opposite of input) | `"bitmark"` | `"json"`.
101
+ * `mode`: `"optimized"` (default) | `"full"`.
102
+ * Returns the converted text/JSON, or a string prefixed `error:` on failure.
103
103
  */
104
- export function split_bits(input: string): string;
104
+ export function convert(input: string, input_format_sel: string, output_format_sel: string, mode: string, pretty: boolean, indent: number, spaces_around_values: number): string;