@gmb/bitmark-parser 7.1.0 → 7.3.0

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.
Files changed (47) hide show
  1. package/README.md +155 -23
  2. package/config/bitmark-json.tsp +330 -0
  3. package/config/bitmark.json +83394 -0
  4. package/dist/browser/bitmark-parser.min.js +6 -4
  5. package/dist/browser/bitmark-parser.min.js.map +1 -1
  6. package/dist/browser/cjs/index.cjs +140 -72
  7. package/dist/browser/cjs/index.cjs.map +1 -1
  8. package/dist/browser/cjs/index.d.cts +6283 -6798
  9. package/dist/browser/esm/index.d.ts +6283 -6798
  10. package/dist/browser/esm/index.js +139 -72
  11. package/dist/browser/esm/index.js.map +1 -1
  12. package/dist/browser/esm/worker-entry.js +86 -57
  13. package/dist/browser/esm/worker-entry.js.map +1 -1
  14. package/dist/browser/wasm/bitmark_browser_full_wasm_bg.wasm +0 -0
  15. package/dist/browser/wasm/bitmark_json_wasm_bg.wasm +0 -0
  16. package/dist/browser/wasm/bitmark_wasm_bg.wasm +0 -0
  17. package/dist/index.cjs +76 -29
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +6283 -6798
  20. package/dist/index.d.ts +6283 -6798
  21. package/dist/index.js +75 -29
  22. package/dist/index.js.map +1 -1
  23. package/dist/legacy.cjs +4 -3
  24. package/dist/legacy.cjs.map +1 -1
  25. package/dist/legacy.d.cts +2 -1
  26. package/dist/legacy.d.ts +2 -1
  27. package/dist/legacy.js +4 -3
  28. package/dist/legacy.js.map +1 -1
  29. package/dist/worker-entry.cjs +23 -15
  30. package/dist/worker-entry.cjs.map +1 -1
  31. package/package.json +11 -7
  32. package/schema/bitmark.schema.json +10427 -14036
  33. package/wasm/bitmark_wasm.d.ts +12 -3
  34. package/wasm/bitmark_wasm.js +34 -15
  35. package/wasm/bitmark_wasm_bg.wasm +0 -0
  36. package/wasm/bitmark_wasm_bg.wasm.d.ts +2 -2
  37. package/wasm/package.json +1 -1
  38. package/wasm-bitmark-json/bitmark_json_wasm.d.ts +12 -3
  39. package/wasm-bitmark-json/bitmark_json_wasm.js +34 -15
  40. package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
  41. package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +2 -2
  42. package/wasm-bitmark-json/package.json +1 -1
  43. package/wasm-browser-full/bitmark_browser_full_wasm.d.ts +12 -3
  44. package/wasm-browser-full/bitmark_browser_full_wasm.js +34 -15
  45. package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm +0 -0
  46. package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm.d.ts +2 -2
  47. package/wasm-browser-full/package.json +1 -1
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { createRequire } from "module";
10
10
  // src/generated/package_info.ts
11
11
  var PACKAGE_INFO = {
12
12
  "name": "@gmb/bitmark-parser",
13
- "version": "7.1.0",
13
+ "version": "7.3.0",
14
14
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
15
15
  "license": "ISC",
16
16
  "description": "A parser for bitmark text, powered by WebAssembly."
@@ -30,6 +30,18 @@ var RegisterError = class extends Error {
30
30
  this.name = "RegisterError";
31
31
  }
32
32
  };
33
+ var PatchError = class extends Error {
34
+ diagnostics;
35
+ constructor(diagnostics2) {
36
+ const lines = diagnostics2.map((d) => `${d.kind} at ${d.path}: ${d.message}`);
37
+ super(
38
+ `${diagnostics2.length} patch ${diagnostics2.length === 1 ? "entry was" : "entries were"} skipped:
39
+ ` + lines.join("\n")
40
+ );
41
+ this.name = "PatchError";
42
+ this.diagnostics = diagnostics2;
43
+ }
44
+ };
33
45
  var UnsupportedFeatureError = class extends Error {
34
46
  constructor(what, active2) {
35
47
  super(
@@ -139,6 +151,18 @@ function planTransform(wasm, input, options) {
139
151
  spacesAroundValues
140
152
  });
141
153
  views.push(units[item.source].view);
154
+ } else if (typeof item.bit === "string") {
155
+ const index = jobs.length;
156
+ jobs.push({
157
+ index,
158
+ source: item.bit,
159
+ inputFormat: "bitmark",
160
+ outputFormat: output,
161
+ mode,
162
+ patchJson: JSON.stringify(item.patch),
163
+ spacesAroundValues
164
+ });
165
+ views.push({ format: "bitmark", index, total, source: item.bit });
142
166
  } else {
143
167
  const bit = item.bit ?? {};
144
168
  const index = jobs.length;
@@ -156,18 +180,24 @@ function planTransform(wasm, input, options) {
156
180
  }
157
181
  return { jobs, views, output, pretty, indent };
158
182
  }
183
+ function bitOutput(envelopeJson, outputFormat) {
184
+ const { data, diagnostics: diagnostics2 } = JSON.parse(envelopeJson);
185
+ return { element: outputFormat === "json" ? stripArray(data) : data, diagnostics: diagnostics2 };
186
+ }
159
187
  function computeBit(wasm, job) {
160
- const out = wasm.transform(
161
- job.source,
162
- job.inputFormat,
163
- job.outputFormat,
164
- job.mode,
165
- job.patchJson,
166
- false,
167
- 2,
168
- job.spacesAroundValues
188
+ return bitOutput(
189
+ wasm.transform(
190
+ job.source,
191
+ job.inputFormat,
192
+ job.outputFormat,
193
+ job.mode,
194
+ job.patchJson,
195
+ false,
196
+ 2,
197
+ job.spacesAroundValues
198
+ ),
199
+ job.outputFormat
169
200
  );
170
- return job.outputFormat === "json" ? stripArray(out) : out;
171
201
  }
172
202
  function recombine(wasm, elements, output, pretty, indent) {
173
203
  if (output !== "json") return elements.join("\n");
@@ -177,21 +207,29 @@ function recombine(wasm, elements, output, pretty, indent) {
177
207
  function runHookedTransform(wasm, input, options) {
178
208
  const plan = planTransform(wasm, input, options);
179
209
  const rendered = [];
210
+ const skipped = [];
180
211
  for (let i = 0; i < plan.jobs.length; i++) {
181
- const element = computeBit(wasm, plan.jobs[i]);
212
+ const { element, diagnostics: diagnostics2 } = computeBit(wasm, plan.jobs[i]);
213
+ skipped.push(...diagnostics2);
182
214
  options.postHook?.(plan.views[i], element);
183
215
  rendered.push(element);
184
216
  }
217
+ if (skipped.length > 0) throw new PatchError(skipped);
185
218
  return recombine(wasm, rendered, plan.output, plan.pretty, plan.indent);
186
219
  }
187
220
 
188
221
  // src/core/parallel.ts
189
222
  async function orchestrateParallel(wasm, input, options, runJobs) {
190
223
  const plan = planTransform(wasm, input, options);
191
- const elements = await runJobs(plan.jobs, options.workers ?? 4);
192
- for (let i = 0; i < elements.length; i++) {
193
- options.postHook?.(plan.views[i], elements[i]);
224
+ const outputs = await runJobs(plan.jobs, options.workers ?? 4);
225
+ const elements = [];
226
+ const skipped = [];
227
+ for (let i = 0; i < outputs.length; i++) {
228
+ elements.push(outputs[i].element);
229
+ skipped.push(...outputs[i].diagnostics);
230
+ options.postHook?.(plan.views[i], outputs[i].element);
194
231
  }
232
+ if (skipped.length > 0) throw new PatchError(skipped);
195
233
  return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);
196
234
  }
197
235
 
@@ -225,7 +263,7 @@ function runJobsWithPool(jobs, workers, spawn) {
225
263
  const w = spawn((res) => {
226
264
  if (done) return;
227
265
  if (!res.ok) return finish(new Error(res.error ?? "worker job failed"));
228
- results[res.id] = res.element;
266
+ results[res.id] = { element: res.element, diagnostics: res.diagnostics ?? [] };
229
267
  if (++settled === jobs.length) finish();
230
268
  else dispatch(w);
231
269
  }, finish);
@@ -622,7 +660,7 @@ var Builder = class {
622
660
  }
623
661
  /**
624
662
  * Look up the bit's config (`wasm.info`); throws bpg's exact
625
- * unknown-bit-type error (`Config.getBitConfig` parity).
663
+ * bit-type-invalid error (`Config.getBitConfig` parity).
626
664
  */
627
665
  getBitConfig(bitType) {
628
666
  const wasm = getLegacyWasm();
@@ -1199,7 +1237,8 @@ var BodyTextFormat = {
1199
1237
  };
1200
1238
  var TextLocation = {
1201
1239
  tag: "tag",
1202
- body: "body"
1240
+ body: "body",
1241
+ cardBody: "cardBody"
1203
1242
  };
1204
1243
 
1205
1244
  // src/legacy/enums-extra.ts
@@ -1511,16 +1550,20 @@ function transform(input, options = {}) {
1511
1550
  return runHookedTransform(wasm, input, options);
1512
1551
  }
1513
1552
  const patchJson = options.patch === void 0 ? "" : typeof options.patch === "string" ? options.patch : JSON.stringify(options.patch);
1514
- return wasm.transform(
1515
- input,
1516
- options.inputFormat ?? "auto",
1517
- options.outputFormat ?? "json",
1518
- options.mode ?? "optimized",
1519
- patchJson,
1520
- options.pretty ?? false,
1521
- options.indent ?? 2,
1522
- options.spacesAroundValues ?? 1
1553
+ const { data, diagnostics: diagnostics2 } = JSON.parse(
1554
+ wasm.transform(
1555
+ input,
1556
+ options.inputFormat ?? "auto",
1557
+ options.outputFormat ?? "json",
1558
+ options.mode ?? "optimized",
1559
+ patchJson,
1560
+ options.pretty ?? false,
1561
+ options.indent ?? 2,
1562
+ options.spacesAroundValues ?? 1
1563
+ )
1523
1564
  );
1565
+ if (diagnostics2.length > 0) throw new PatchError(diagnostics2);
1566
+ return data;
1524
1567
  }
1525
1568
  function diff(a, b, options = {}) {
1526
1569
  const wasm = getActive();
@@ -1544,12 +1587,14 @@ function diffBits(a, b, options = {}) {
1544
1587
  function breakscapeText(input, options = {}) {
1545
1588
  const format = options.format ?? "bitmark++";
1546
1589
  const location = options.location ?? "body";
1547
- return getActive().breakscape_text(input, format, location);
1590
+ const subLocation = options.subLocation ?? "text";
1591
+ return getActive().breakscape_text(input, format, location, subLocation);
1548
1592
  }
1549
1593
  function unbreakscapeText(input, options = {}) {
1550
1594
  const format = options.format ?? "bitmark++";
1551
1595
  const location = options.location ?? "body";
1552
- return getActive().unbreakscape_text(input, format, location);
1596
+ const subLocation = options.subLocation ?? "text";
1597
+ return getActive().unbreakscape_text(input, format, location, subLocation);
1553
1598
  }
1554
1599
  function info(options = {}) {
1555
1600
  const infoType = options.infoType ?? "list";
@@ -1621,6 +1666,7 @@ export {
1621
1666
  CompletionItemTag,
1622
1667
  DiagnosticSeverity,
1623
1668
  NotInitializedError,
1669
+ PatchError,
1624
1670
  RegisterError,
1625
1671
  UnsupportedFeatureError,
1626
1672
  bitmarkToObjects,