@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.cjs CHANGED
@@ -35,6 +35,7 @@ __export(src_exports, {
35
35
  CompletionItemTag: () => CompletionItemTag,
36
36
  DiagnosticSeverity: () => DiagnosticSeverity,
37
37
  NotInitializedError: () => NotInitializedError,
38
+ PatchError: () => PatchError,
38
39
  RegisterError: () => RegisterError,
39
40
  UnsupportedFeatureError: () => UnsupportedFeatureError,
40
41
  bitmarkToObjects: () => bitmarkToObjects,
@@ -75,7 +76,7 @@ var import_node_module = require("module");
75
76
  // src/generated/package_info.ts
76
77
  var PACKAGE_INFO = {
77
78
  "name": "@gmb/bitmark-parser",
78
- "version": "7.1.0",
79
+ "version": "7.3.0",
79
80
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
80
81
  "license": "ISC",
81
82
  "description": "A parser for bitmark text, powered by WebAssembly."
@@ -95,6 +96,18 @@ var RegisterError = class extends Error {
95
96
  this.name = "RegisterError";
96
97
  }
97
98
  };
99
+ var PatchError = class extends Error {
100
+ diagnostics;
101
+ constructor(diagnostics2) {
102
+ const lines = diagnostics2.map((d) => `${d.kind} at ${d.path}: ${d.message}`);
103
+ super(
104
+ `${diagnostics2.length} patch ${diagnostics2.length === 1 ? "entry was" : "entries were"} skipped:
105
+ ` + lines.join("\n")
106
+ );
107
+ this.name = "PatchError";
108
+ this.diagnostics = diagnostics2;
109
+ }
110
+ };
98
111
  var UnsupportedFeatureError = class extends Error {
99
112
  constructor(what, active2) {
100
113
  super(
@@ -204,6 +217,18 @@ function planTransform(wasm, input, options) {
204
217
  spacesAroundValues
205
218
  });
206
219
  views.push(units[item.source].view);
220
+ } else if (typeof item.bit === "string") {
221
+ const index = jobs.length;
222
+ jobs.push({
223
+ index,
224
+ source: item.bit,
225
+ inputFormat: "bitmark",
226
+ outputFormat: output,
227
+ mode,
228
+ patchJson: JSON.stringify(item.patch),
229
+ spacesAroundValues
230
+ });
231
+ views.push({ format: "bitmark", index, total, source: item.bit });
207
232
  } else {
208
233
  const bit = item.bit ?? {};
209
234
  const index = jobs.length;
@@ -221,18 +246,24 @@ function planTransform(wasm, input, options) {
221
246
  }
222
247
  return { jobs, views, output, pretty, indent };
223
248
  }
249
+ function bitOutput(envelopeJson, outputFormat) {
250
+ const { data, diagnostics: diagnostics2 } = JSON.parse(envelopeJson);
251
+ return { element: outputFormat === "json" ? stripArray(data) : data, diagnostics: diagnostics2 };
252
+ }
224
253
  function computeBit(wasm, job) {
225
- const out = wasm.transform(
226
- job.source,
227
- job.inputFormat,
228
- job.outputFormat,
229
- job.mode,
230
- job.patchJson,
231
- false,
232
- 2,
233
- job.spacesAroundValues
254
+ return bitOutput(
255
+ wasm.transform(
256
+ job.source,
257
+ job.inputFormat,
258
+ job.outputFormat,
259
+ job.mode,
260
+ job.patchJson,
261
+ false,
262
+ 2,
263
+ job.spacesAroundValues
264
+ ),
265
+ job.outputFormat
234
266
  );
235
- return job.outputFormat === "json" ? stripArray(out) : out;
236
267
  }
237
268
  function recombine(wasm, elements, output, pretty, indent) {
238
269
  if (output !== "json") return elements.join("\n");
@@ -242,21 +273,29 @@ function recombine(wasm, elements, output, pretty, indent) {
242
273
  function runHookedTransform(wasm, input, options) {
243
274
  const plan = planTransform(wasm, input, options);
244
275
  const rendered = [];
276
+ const skipped = [];
245
277
  for (let i = 0; i < plan.jobs.length; i++) {
246
- const element = computeBit(wasm, plan.jobs[i]);
278
+ const { element, diagnostics: diagnostics2 } = computeBit(wasm, plan.jobs[i]);
279
+ skipped.push(...diagnostics2);
247
280
  options.postHook?.(plan.views[i], element);
248
281
  rendered.push(element);
249
282
  }
283
+ if (skipped.length > 0) throw new PatchError(skipped);
250
284
  return recombine(wasm, rendered, plan.output, plan.pretty, plan.indent);
251
285
  }
252
286
 
253
287
  // src/core/parallel.ts
254
288
  async function orchestrateParallel(wasm, input, options, runJobs) {
255
289
  const plan = planTransform(wasm, input, options);
256
- const elements = await runJobs(plan.jobs, options.workers ?? 4);
257
- for (let i = 0; i < elements.length; i++) {
258
- options.postHook?.(plan.views[i], elements[i]);
290
+ const outputs = await runJobs(plan.jobs, options.workers ?? 4);
291
+ const elements = [];
292
+ const skipped = [];
293
+ for (let i = 0; i < outputs.length; i++) {
294
+ elements.push(outputs[i].element);
295
+ skipped.push(...outputs[i].diagnostics);
296
+ options.postHook?.(plan.views[i], outputs[i].element);
259
297
  }
298
+ if (skipped.length > 0) throw new PatchError(skipped);
260
299
  return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);
261
300
  }
262
301
 
@@ -290,7 +329,7 @@ function runJobsWithPool(jobs, workers, spawn) {
290
329
  const w = spawn((res) => {
291
330
  if (done) return;
292
331
  if (!res.ok) return finish(new Error(res.error ?? "worker job failed"));
293
- results[res.id] = res.element;
332
+ results[res.id] = { element: res.element, diagnostics: res.diagnostics ?? [] };
294
333
  if (++settled === jobs.length) finish();
295
334
  else dispatch(w);
296
335
  }, finish);
@@ -687,7 +726,7 @@ var Builder = class {
687
726
  }
688
727
  /**
689
728
  * Look up the bit's config (`wasm.info`); throws bpg's exact
690
- * unknown-bit-type error (`Config.getBitConfig` parity).
729
+ * bit-type-invalid error (`Config.getBitConfig` parity).
691
730
  */
692
731
  getBitConfig(bitType) {
693
732
  const wasm = getLegacyWasm();
@@ -1264,7 +1303,8 @@ var BodyTextFormat = {
1264
1303
  };
1265
1304
  var TextLocation = {
1266
1305
  tag: "tag",
1267
- body: "body"
1306
+ body: "body",
1307
+ cardBody: "cardBody"
1268
1308
  };
1269
1309
 
1270
1310
  // src/legacy/enums-extra.ts
@@ -1576,16 +1616,20 @@ function transform(input, options = {}) {
1576
1616
  return runHookedTransform(wasm, input, options);
1577
1617
  }
1578
1618
  const patchJson = options.patch === void 0 ? "" : typeof options.patch === "string" ? options.patch : JSON.stringify(options.patch);
1579
- return wasm.transform(
1580
- input,
1581
- options.inputFormat ?? "auto",
1582
- options.outputFormat ?? "json",
1583
- options.mode ?? "optimized",
1584
- patchJson,
1585
- options.pretty ?? false,
1586
- options.indent ?? 2,
1587
- options.spacesAroundValues ?? 1
1619
+ const { data, diagnostics: diagnostics2 } = JSON.parse(
1620
+ wasm.transform(
1621
+ input,
1622
+ options.inputFormat ?? "auto",
1623
+ options.outputFormat ?? "json",
1624
+ options.mode ?? "optimized",
1625
+ patchJson,
1626
+ options.pretty ?? false,
1627
+ options.indent ?? 2,
1628
+ options.spacesAroundValues ?? 1
1629
+ )
1588
1630
  );
1631
+ if (diagnostics2.length > 0) throw new PatchError(diagnostics2);
1632
+ return data;
1589
1633
  }
1590
1634
  function diff(a, b, options = {}) {
1591
1635
  const wasm = getActive();
@@ -1609,12 +1653,14 @@ function diffBits(a, b, options = {}) {
1609
1653
  function breakscapeText(input, options = {}) {
1610
1654
  const format = options.format ?? "bitmark++";
1611
1655
  const location = options.location ?? "body";
1612
- return getActive().breakscape_text(input, format, location);
1656
+ const subLocation = options.subLocation ?? "text";
1657
+ return getActive().breakscape_text(input, format, location, subLocation);
1613
1658
  }
1614
1659
  function unbreakscapeText(input, options = {}) {
1615
1660
  const format = options.format ?? "bitmark++";
1616
1661
  const location = options.location ?? "body";
1617
- return getActive().unbreakscape_text(input, format, location);
1662
+ const subLocation = options.subLocation ?? "text";
1663
+ return getActive().unbreakscape_text(input, format, location, subLocation);
1618
1664
  }
1619
1665
  function info(options = {}) {
1620
1666
  const infoType = options.infoType ?? "list";
@@ -1687,6 +1733,7 @@ function transformParallel(input, options = {}) {
1687
1733
  CompletionItemTag,
1688
1734
  DiagnosticSeverity,
1689
1735
  NotInitializedError,
1736
+ PatchError,
1690
1737
  RegisterError,
1691
1738
  UnsupportedFeatureError,
1692
1739
  bitmarkToObjects,