@bcts/envelope-pattern 1.0.0-alpha.22 → 1.0.0-beta.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 (60) hide show
  1. package/dist/index.cjs +1291 -826
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +101 -59
  4. package/dist/index.d.cts.map +1 -1
  5. package/dist/index.d.mts +102 -60
  6. package/dist/index.d.mts.map +1 -1
  7. package/dist/index.iife.js +1643 -1179
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.mjs +1315 -853
  10. package/dist/index.mjs.map +1 -1
  11. package/package.json +13 -11
  12. package/src/error.ts +1 -1
  13. package/src/format.ts +19 -31
  14. package/src/parse/index.ts +17 -1010
  15. package/src/parse/leaf/array-parser.ts +36 -0
  16. package/src/parse/leaf/cbor-parser.ts +43 -0
  17. package/src/parse/leaf/date-parser.ts +81 -0
  18. package/src/parse/leaf/known-value-parser.ts +73 -0
  19. package/src/parse/leaf/null-parser.ts +16 -0
  20. package/src/parse/leaf/number-parser.ts +90 -0
  21. package/src/parse/leaf/tag-parser.ts +160 -0
  22. package/src/parse/meta/and-parser.ts +40 -0
  23. package/src/parse/meta/capture-parser.ts +50 -0
  24. package/src/parse/meta/group-parser.ts +77 -0
  25. package/src/parse/meta/not-parser.ts +30 -0
  26. package/src/parse/meta/or-parser.ts +36 -0
  27. package/src/parse/meta/primary-parser.ts +234 -0
  28. package/src/parse/meta/search-parser.ts +41 -0
  29. package/src/parse/meta/traverse-parser.ts +42 -0
  30. package/src/parse/structure/assertion-obj-parser.ts +44 -0
  31. package/src/parse/structure/assertion-parser.ts +22 -0
  32. package/src/parse/structure/assertion-pred-parser.ts +45 -0
  33. package/src/parse/structure/compressed-parser.ts +17 -0
  34. package/src/parse/structure/digest-parser.ts +132 -0
  35. package/src/parse/structure/elided-parser.ts +17 -0
  36. package/src/parse/structure/encrypted-parser.ts +17 -0
  37. package/src/parse/structure/node-parser.ts +54 -0
  38. package/src/parse/structure/object-parser.ts +32 -0
  39. package/src/parse/structure/obscured-parser.ts +17 -0
  40. package/src/parse/structure/predicate-parser.ts +32 -0
  41. package/src/parse/structure/subject-parser.ts +32 -0
  42. package/src/parse/structure/wrapped-parser.ts +36 -0
  43. package/src/pattern/dcbor-integration.ts +40 -8
  44. package/src/pattern/index.ts +29 -0
  45. package/src/pattern/leaf/array-pattern.ts +67 -169
  46. package/src/pattern/leaf/cbor-pattern.ts +37 -23
  47. package/src/pattern/leaf/index.ts +1 -1
  48. package/src/pattern/leaf/map-pattern.ts +21 -2
  49. package/src/pattern/leaf/tagged-pattern.ts +6 -1
  50. package/src/pattern/meta/search-pattern.ts +13 -38
  51. package/src/pattern/meta/traverse-pattern.ts +2 -2
  52. package/src/pattern/structure/assertions-pattern.ts +19 -53
  53. package/src/pattern/structure/digest-pattern.ts +18 -22
  54. package/src/pattern/structure/index.ts +3 -0
  55. package/src/pattern/structure/node-pattern.ts +10 -29
  56. package/src/pattern/structure/object-pattern.ts +2 -2
  57. package/src/pattern/structure/predicate-pattern.ts +2 -2
  58. package/src/pattern/structure/subject-pattern.ts +31 -4
  59. package/src/pattern/structure/wrapped-pattern.ts +28 -9
  60. package/src/pattern/vm.ts +4 -4
@@ -1,9 +1,7 @@
1
- var bctsEnvelopePattern = (function(exports, _bcts_dcbor_pattern, _bcts_known_values, _bcts_envelope, _bcts_dcbor, _bcts_dcbor_parse) {
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- //#region src/error.ts
6
- /**
1
+ var bctsEnvelopePattern = (function(exports, _bcts_dcbor_pattern, _bcts_known_values, _bcts_dcbor, _bcts_envelope, _bcts_dcbor_parse) {
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ //#region src/error.ts
4
+ /**
7
5
  * Creates a successful result.
8
6
  */
9
7
  function ok(value) {
@@ -216,10 +214,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
216
214
  error
217
215
  };
218
216
  }
219
-
220
- //#endregion
221
- //#region src/format.ts
222
- /**
217
+ //#endregion
218
+ //#region src/format.ts
219
+ /**
223
220
  * Creates a Summary format.
224
221
  */
225
222
  function summaryFormat(maxLength) {
@@ -305,6 +302,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
305
302
  /**
306
303
  * Gets a summary of an envelope for display.
307
304
  *
305
+ * Mirrors Rust `envelope_summary` in `format.rs`: defers to
306
+ * `Envelope::format_flat()` for nodes / wrapped / assertions and to
307
+ * `cbor.envelope_summary(usize::MAX, ...)` for raw CBOR leaves. The
308
+ * obscured cases (`elided` / `encrypted` / `compressed`) emit just the
309
+ * keyword. KnownValue envelopes look up the canonical name via
310
+ * `KnownValue.name()`, matching the Rust call to
311
+ * `KnownValuesStore::known_value_for_raw_value(value, …)`.
312
+ *
308
313
  * @param env - The envelope to summarize
309
314
  * @returns A string summary of the envelope
310
315
  */
@@ -313,25 +318,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
313
318
  const c = env.case();
314
319
  let summary;
315
320
  switch (c.type) {
316
- case "node": {
317
- const subjectSummary = env.subject().summary(Number.MAX_SAFE_INTEGER);
318
- const assertions = env.assertions();
319
- if (assertions.length > 0) summary = `NODE ${subjectSummary} [ ${assertions.map((a) => {
320
- const ac = a.case();
321
- if (ac.type === "assertion") return `${ac.assertion.predicate().summary(Number.MAX_SAFE_INTEGER)}: ${ac.assertion.object().summary(Number.MAX_SAFE_INTEGER)}`;
322
- return a.summary(Number.MAX_SAFE_INTEGER);
323
- }).join(", ")} ]`;
324
- else summary = `NODE ${subjectSummary}`;
321
+ case "node":
322
+ summary = `NODE ${env.formatFlat()}`;
325
323
  break;
326
- }
327
324
  case "leaf":
328
325
  summary = `LEAF ${env.summary(Number.MAX_SAFE_INTEGER)}`;
329
326
  break;
330
327
  case "wrapped":
331
- summary = `WRAPPED ${env.summary(Number.MAX_SAFE_INTEGER)}`;
328
+ summary = `WRAPPED ${env.formatFlat()}`;
332
329
  break;
333
330
  case "assertion":
334
- summary = `ASSERTION ${c.assertion.predicate().summary(Number.MAX_SAFE_INTEGER)}: ${c.assertion.object().summary(Number.MAX_SAFE_INTEGER)}`;
331
+ summary = `ASSERTION ${env.formatFlat()}`;
335
332
  break;
336
333
  case "elided":
337
334
  summary = "ELIDED";
@@ -377,8 +374,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
377
374
  if (element === void 0) return "";
378
375
  switch (opts.elementFormat.type) {
379
376
  case "Summary": return truncateWithEllipsis(envelopeSummary(element), opts.elementFormat.maxLength);
380
- case "EnvelopeUR": return element.digest().toString();
381
- case "DigestUR": return element.digest().toString();
377
+ case "EnvelopeUR": return element.urString();
378
+ case "DigestUR": return element.digest().urString();
382
379
  }
383
380
  }
384
381
  switch (opts.elementFormat.type) {
@@ -393,8 +390,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
393
390
  }
394
391
  return lines.join("\n");
395
392
  }
396
- case "EnvelopeUR": return path.map((element) => element.digest().toString()).join(" ");
397
- case "DigestUR": return path.map((element) => element.digest().toString()).join(" ");
393
+ case "EnvelopeUR": return path.map((element) => element.urString()).join(" ");
394
+ case "DigestUR": return path.map((element) => element.digest().urString()).join(" ");
398
395
  }
399
396
  }
400
397
  /**
@@ -475,19 +472,27 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
475
472
  function formatPaths(paths) {
476
473
  return formatPathsOpt(paths, defaultFormatPathsOpts());
477
474
  }
478
-
479
- //#endregion
480
- //#region src/pattern/matcher.ts
481
- /**
475
+ //#endregion
476
+ //#region src/pattern/matcher.ts
477
+ /**
482
478
  * Default implementations for Matcher methods.
483
479
  */
484
480
  const MatcherDefaults = {
481
+ /**
482
+ * Default implementation of paths() - calls pathsWithCaptures and discards captures.
483
+ */
485
484
  paths(matcher, haystack) {
486
485
  return matcher.pathsWithCaptures(haystack)[0];
487
486
  },
487
+ /**
488
+ * Default implementation of matches() - checks if paths() returns any results.
489
+ */
488
490
  matches(matcher, haystack) {
489
491
  return matcher.paths(haystack).length > 0;
490
492
  },
493
+ /**
494
+ * Default implementation of isComplex() - returns false.
495
+ */
491
496
  isComplex() {
492
497
  return false;
493
498
  }
@@ -575,9 +580,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
575
580
  if (patternToStringFn === void 0) throw new Error("Pattern dispatch functions not registered");
576
581
  return patternToStringFn(pattern);
577
582
  }
578
-
579
- //#endregion
580
- //#region src/pattern/leaf/bool-pattern.ts
583
+ //#endregion
584
+ //#region src/pattern/leaf/bool-pattern.ts
581
585
  let createLeafBoolPattern;
582
586
  function registerBoolPatternFactory(factory) {
583
587
  createLeafBoolPattern = factory;
@@ -659,9 +663,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
659
663
  return hash;
660
664
  }
661
665
  };
662
-
663
- //#endregion
664
- //#region src/pattern/leaf/null-pattern.ts
666
+ //#endregion
667
+ //#region src/pattern/leaf/null-pattern.ts
665
668
  let createLeafNullPattern;
666
669
  function registerNullPatternFactory(factory) {
667
670
  createLeafNullPattern = factory;
@@ -728,9 +731,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
728
731
  return 0;
729
732
  }
730
733
  };
731
-
732
- //#endregion
733
- //#region src/pattern/leaf/number-pattern.ts
734
+ //#endregion
735
+ //#region src/pattern/leaf/number-pattern.ts
734
736
  let createLeafNumberPattern;
735
737
  function registerNumberPatternFactory(factory) {
736
738
  createLeafNumberPattern = factory;
@@ -901,9 +903,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
901
903
  return hash;
902
904
  }
903
905
  };
904
-
905
- //#endregion
906
- //#region src/pattern/leaf/text-pattern.ts
906
+ //#endregion
907
+ //#region src/pattern/leaf/text-pattern.ts
907
908
  let createLeafTextPattern;
908
909
  function registerTextPatternFactory(factory) {
909
910
  createLeafTextPattern = factory;
@@ -1006,9 +1007,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1006
1007
  return hash;
1007
1008
  }
1008
1009
  };
1009
-
1010
- //#endregion
1011
- //#region src/pattern/leaf/byte-string-pattern.ts
1010
+ //#endregion
1011
+ //#region src/pattern/leaf/byte-string-pattern.ts
1012
1012
  let createLeafByteStringPattern;
1013
1013
  function registerByteStringPatternFactory(factory) {
1014
1014
  createLeafByteStringPattern = factory;
@@ -1117,9 +1117,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1117
1117
  return hash;
1118
1118
  }
1119
1119
  };
1120
-
1121
- //#endregion
1122
- //#region src/pattern/leaf/date-pattern.ts
1120
+ //#endregion
1121
+ //#region src/pattern/leaf/date-pattern.ts
1123
1122
  let createLeafDatePattern;
1124
1123
  function registerDatePatternFactory(factory) {
1125
1124
  createLeafDatePattern = factory;
@@ -1232,28 +1231,18 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1232
1231
  return hash;
1233
1232
  }
1234
1233
  };
1235
-
1236
- //#endregion
1237
- //#region src/pattern/leaf/array-pattern.ts
1238
- /**
1239
- * Copyright © 2023-2026 Blockchain Commons, LLC
1240
- * Copyright © 2025-2026 Parity Technologies
1241
- *
1242
- *
1243
- * @bcts/envelope-pattern - Array pattern matching
1244
- *
1245
- * This is a 1:1 TypeScript port of bc-envelope-pattern-rust array_pattern.rs
1246
- *
1247
- * @module envelope-pattern/pattern/leaf/array-pattern
1248
- */
1234
+ //#endregion
1235
+ //#region src/pattern/leaf/array-pattern.ts
1249
1236
  let createLeafArrayPattern;
1250
1237
  function registerArrayPatternFactory(factory) {
1251
1238
  createLeafArrayPattern = factory;
1252
1239
  }
1253
1240
  /**
1254
- * Pattern for matching array values in envelope leaf nodes.
1241
+ * Pattern for matching arrays.
1255
1242
  *
1256
- * Corresponds to the Rust `ArrayPattern` struct in array_pattern.rs
1243
+ * Mirrors Rust `ArrayPattern(dcbor_pattern::ArrayPattern)` from
1244
+ * `bc-envelope-pattern-rust/src/pattern/leaf/array_pattern.rs`. All
1245
+ * matching, display, and equality is delegated to dcbor-pattern.
1257
1246
  */
1258
1247
  var ArrayPattern = class ArrayPattern {
1259
1248
  _pattern;
@@ -1264,93 +1253,54 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1264
1253
  * Creates a new ArrayPattern that matches any array.
1265
1254
  */
1266
1255
  static any() {
1267
- return new ArrayPattern({ type: "Any" });
1256
+ return new ArrayPattern((0, _bcts_dcbor_pattern.arrayPatternAny)());
1268
1257
  }
1269
1258
  /**
1270
1259
  * Creates a new ArrayPattern that matches arrays with a specific length.
1271
1260
  */
1272
1261
  static count(count) {
1273
- return new ArrayPattern({
1274
- type: "Interval",
1275
- interval: _bcts_dcbor_pattern.Interval.exactly(count)
1276
- });
1262
+ return new ArrayPattern((0, _bcts_dcbor_pattern.arrayPatternWithLength)(count));
1277
1263
  }
1278
1264
  /**
1279
1265
  * Creates a new ArrayPattern that matches arrays within a length range.
1280
1266
  */
1281
1267
  static interval(min, max) {
1282
- return new ArrayPattern({
1283
- type: "Interval",
1284
- interval: max !== void 0 ? _bcts_dcbor_pattern.Interval.from(min, max) : _bcts_dcbor_pattern.Interval.atLeast(min)
1285
- });
1268
+ return new ArrayPattern((0, _bcts_dcbor_pattern.arrayPatternWithLengthRange)(min, max));
1286
1269
  }
1287
1270
  /**
1288
- * Creates a new ArrayPattern from a dcbor-pattern.
1271
+ * Creates a new ArrayPattern from a length Interval.
1289
1272
  */
1290
- static fromDcborPattern(dcborPattern) {
1291
- return new ArrayPattern({
1292
- type: "DCBORPattern",
1293
- pattern: dcborPattern
1294
- });
1273
+ static fromInterval(interval) {
1274
+ return new ArrayPattern((0, _bcts_dcbor_pattern.arrayPatternWithLengthInterval)(interval));
1295
1275
  }
1296
1276
  /**
1297
- * Creates a new ArrayPattern with envelope patterns for element matching.
1277
+ * Creates a new ArrayPattern from a top-level dcbor-pattern.
1278
+ *
1279
+ * Mirrors Rust `ArrayPattern::from_dcbor_pattern`, which constructs an
1280
+ * `ArrayPattern::Elements`-style dcbor array pattern.
1298
1281
  */
1299
- static withPatterns(patterns) {
1300
- return new ArrayPattern({
1301
- type: "WithPatterns",
1302
- patterns
1303
- });
1282
+ static fromDcborPattern(pattern) {
1283
+ return new ArrayPattern((0, _bcts_dcbor_pattern.arrayPatternWithElements)(pattern));
1304
1284
  }
1305
1285
  /**
1306
- * Gets the pattern type.
1286
+ * Creates a new ArrayPattern from an existing dcbor-pattern ArrayPattern.
1287
+ *
1288
+ * Mirrors Rust `ArrayPattern::from_dcbor_array_pattern`.
1307
1289
  */
1308
- get pattern() {
1290
+ static fromDcborArrayPattern(arrayPattern) {
1291
+ return new ArrayPattern(arrayPattern);
1292
+ }
1293
+ /**
1294
+ * Returns the underlying dcbor-pattern ArrayPattern.
1295
+ */
1296
+ inner() {
1309
1297
  return this._pattern;
1310
1298
  }
1311
1299
  pathsWithCaptures(haystack) {
1312
1300
  const cbor = haystack.subject().asLeaf();
1313
1301
  if (cbor === void 0) return [[], /* @__PURE__ */ new Map()];
1314
- const array = (0, _bcts_dcbor.asCborArray)(cbor);
1315
- if (array === void 0) return [[], /* @__PURE__ */ new Map()];
1316
- switch (this._pattern.type) {
1317
- case "Any": return [[[haystack]], /* @__PURE__ */ new Map()];
1318
- case "Interval": {
1319
- const length = array.length;
1320
- if (this._pattern.interval.contains(length)) return [[[haystack]], /* @__PURE__ */ new Map()];
1321
- return [[], /* @__PURE__ */ new Map()];
1322
- }
1323
- case "DCBORPattern": {
1324
- const { paths: dcborPaths, captures: dcborCaptures } = (0, _bcts_dcbor_pattern.patternPathsWithCaptures)(this._pattern.pattern, cbor);
1325
- if (dcborPaths.length > 0) {
1326
- const envelopePaths = dcborPaths.map((dcborPath) => {
1327
- const envPath = [haystack];
1328
- for (let i = 1; i < dcborPath.length; i++) {
1329
- const elem = dcborPath[i];
1330
- if (elem !== void 0) envPath.push(_bcts_envelope.Envelope.newLeaf(elem));
1331
- }
1332
- return envPath;
1333
- });
1334
- const envelopeCaptures = /* @__PURE__ */ new Map();
1335
- for (const [name, capturePaths] of dcborCaptures) {
1336
- const envCapturePaths = capturePaths.map((dcborPath) => {
1337
- const envPath = [haystack];
1338
- for (let i = 1; i < dcborPath.length; i++) {
1339
- const elem = dcborPath[i];
1340
- if (elem !== void 0) envPath.push(_bcts_envelope.Envelope.newLeaf(elem));
1341
- }
1342
- return envPath;
1343
- });
1344
- envelopeCaptures.set(name, envCapturePaths);
1345
- }
1346
- return [envelopePaths, envelopeCaptures];
1347
- }
1348
- return [[], /* @__PURE__ */ new Map()];
1349
- }
1350
- case "WithPatterns":
1351
- if (array.length === this._pattern.patterns.length) return [[[haystack]], /* @__PURE__ */ new Map()];
1352
- return [[], /* @__PURE__ */ new Map()];
1353
- }
1302
+ if ((0, _bcts_dcbor_pattern.arrayPatternMatches)(this._pattern, cbor)) return [[[haystack]], /* @__PURE__ */ new Map()];
1303
+ return [[], /* @__PURE__ */ new Map()];
1354
1304
  }
1355
1305
  paths(haystack) {
1356
1306
  return this.pathsWithCaptures(haystack)[0];
@@ -1366,57 +1316,33 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1366
1316
  return false;
1367
1317
  }
1368
1318
  toString() {
1369
- switch (this._pattern.type) {
1370
- case "Any": return "[*]";
1371
- case "Interval": return `[{${this._pattern.interval.toString()}}]`;
1372
- case "DCBORPattern": return (0, _bcts_dcbor_pattern.patternDisplay)(this._pattern.pattern);
1373
- case "WithPatterns": return `[${this._pattern.patterns.map(String).join(", ")}]`;
1374
- }
1319
+ return (0, _bcts_dcbor_pattern.arrayPatternDisplay)(this._pattern, _bcts_dcbor_pattern.patternDisplay);
1375
1320
  }
1376
1321
  /**
1377
- * Equality comparison.
1322
+ * Equality comparison. Delegates to dcbor-pattern's structural equality
1323
+ * with a display-string fallback for pattern-equality (mirrors Rust's
1324
+ * `Hash` impl that hashes the display, since dcbor `ArrayPattern`
1325
+ * itself does not derive `Hash`).
1378
1326
  */
1379
1327
  equals(other) {
1380
- if (this._pattern.type !== other._pattern.type) return false;
1381
- switch (this._pattern.type) {
1382
- case "Any": return true;
1383
- case "Interval": return this._pattern.interval.equals(other._pattern.interval);
1384
- case "DCBORPattern": return (0, _bcts_dcbor_pattern.patternDisplay)(this._pattern.pattern) === (0, _bcts_dcbor_pattern.patternDisplay)(other._pattern.pattern);
1385
- case "WithPatterns": {
1386
- const otherPatterns = other._pattern.patterns;
1387
- if (this._pattern.patterns.length !== otherPatterns.length) return false;
1388
- for (let i = 0; i < this._pattern.patterns.length; i++) if (this._pattern.patterns[i] !== otherPatterns[i]) return false;
1389
- return true;
1390
- }
1391
- }
1328
+ return (0, _bcts_dcbor_pattern.arrayPatternEquals)(this._pattern, other._pattern, (a, b) => (0, _bcts_dcbor_pattern.patternDisplay)(a) === (0, _bcts_dcbor_pattern.patternDisplay)(b));
1392
1329
  }
1393
1330
  /**
1394
- * Hash code for use in Maps/Sets.
1331
+ * Hash code for use in Maps/Sets. Mirrors Rust's
1332
+ * "hash the string representation" approach.
1395
1333
  */
1396
1334
  hashCode() {
1397
- switch (this._pattern.type) {
1398
- case "Any": return 0;
1399
- case "Interval": return this._pattern.interval.min() * 31 + (this._pattern.interval.max() ?? 0);
1400
- case "DCBORPattern": return simpleStringHash$3((0, _bcts_dcbor_pattern.patternDisplay)(this._pattern.pattern));
1401
- case "WithPatterns": return this._pattern.patterns.length;
1335
+ let hash = 0;
1336
+ const str = this.toString();
1337
+ for (let i = 0; i < str.length; i++) {
1338
+ hash = (hash << 5) - hash + str.charCodeAt(i);
1339
+ hash = hash & hash;
1402
1340
  }
1341
+ return hash;
1403
1342
  }
1404
1343
  };
1405
- /**
1406
- * Simple string hash function for hashCode implementations.
1407
- */
1408
- function simpleStringHash$3(str) {
1409
- let hash = 0;
1410
- for (let i = 0; i < str.length; i++) {
1411
- const char = str.charCodeAt(i);
1412
- hash = (hash << 5) - hash + char;
1413
- hash = hash & hash;
1414
- }
1415
- return hash;
1416
- }
1417
-
1418
- //#endregion
1419
- //#region src/pattern/leaf/map-pattern.ts
1344
+ //#endregion
1345
+ //#region src/pattern/leaf/map-pattern.ts
1420
1346
  let createLeafMapPattern;
1421
1347
  function registerMapPatternFactory(factory) {
1422
1348
  createLeafMapPattern = factory;
@@ -1447,6 +1373,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1447
1373
  });
1448
1374
  }
1449
1375
  /**
1376
+ * Creates a new MapPattern from a length Interval.
1377
+ *
1378
+ * Mirrors Rust `MapPattern::from_interval`. Used by the
1379
+ * dcbor-pattern → envelope-pattern bridge to preserve `{{n,m}}`
1380
+ * length info.
1381
+ */
1382
+ static fromInterval(interval) {
1383
+ return new MapPattern({
1384
+ type: "Interval",
1385
+ interval
1386
+ });
1387
+ }
1388
+ /**
1450
1389
  * Gets the pattern type.
1451
1390
  */
1452
1391
  get pattern() {
@@ -1481,8 +1420,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1481
1420
  }
1482
1421
  toString() {
1483
1422
  switch (this._pattern.type) {
1484
- case "Any": return "{*}";
1485
- case "Interval": return `{{${this._pattern.interval.toString()}}}`;
1423
+ case "Any": return "map";
1424
+ case "Interval": return `{${this._pattern.interval.toString()}}`;
1486
1425
  }
1487
1426
  }
1488
1427
  /**
@@ -1505,9 +1444,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1505
1444
  }
1506
1445
  }
1507
1446
  };
1508
-
1509
- //#endregion
1510
- //#region src/pattern/leaf/known-value-pattern.ts
1447
+ //#endregion
1448
+ //#region src/pattern/leaf/known-value-pattern.ts
1511
1449
  let createLeafKnownValuePattern;
1512
1450
  function registerKnownValuePatternFactory(factory) {
1513
1451
  createLeafKnownValuePattern = factory;
@@ -1626,10 +1564,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1626
1564
  }
1627
1565
  return hash;
1628
1566
  }
1629
-
1630
- //#endregion
1631
- //#region src/pattern/leaf/tagged-pattern.ts
1632
- /**
1567
+ //#endregion
1568
+ //#region src/pattern/leaf/tagged-pattern.ts
1569
+ /**
1633
1570
  * Copyright © 2023-2026 Blockchain Commons, LLC
1634
1571
  * Copyright © 2025-2026 Parity Technologies
1635
1572
  *
@@ -1737,7 +1674,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1737
1674
  return false;
1738
1675
  }
1739
1676
  toString() {
1740
- return (0, _bcts_dcbor_pattern.taggedPatternDisplay)(this._inner, _bcts_dcbor_pattern.patternDisplay);
1677
+ return (0, _bcts_dcbor_pattern.taggedPatternDisplay)(this._inner, _bcts_dcbor_pattern.patternDisplay).replace(", ", ", ");
1741
1678
  }
1742
1679
  /**
1743
1680
  * Equality comparison.
@@ -1784,10 +1721,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1784
1721
  }
1785
1722
  return hash;
1786
1723
  }
1787
-
1788
- //#endregion
1789
- //#region src/pattern/leaf/cbor-pattern.ts
1790
- /**
1724
+ //#endregion
1725
+ //#region src/pattern/leaf/cbor-pattern.ts
1726
+ /**
1791
1727
  * Copyright © 2023-2026 Blockchain Commons, LLC
1792
1728
  * Copyright © 2025-2026 Parity Technologies
1793
1729
  *
@@ -1864,10 +1800,18 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1864
1800
  }
1865
1801
  /**
1866
1802
  * Convert a single dcbor path to an envelope path.
1803
+ *
1804
+ * Uses canonical CBOR-byte equality (`cborEquals`) for the "skip the
1805
+ * dcbor root if it duplicates our base envelope" check, mirroring
1806
+ * Rust's `dcbor_path.first().map(|first| first == &base_cbor)`. The
1807
+ * earlier port compared diagnostic strings, which collapses values
1808
+ * that share a textual representation but differ structurally
1809
+ * (e.g. NaN payloads).
1867
1810
  */
1868
1811
  _convertDcborPathToEnvelopePath(dcborPath, baseEnvelope, baseCbor) {
1869
1812
  const envelopePath = [baseEnvelope];
1870
- const elementsToAdd = dcborPath.length > 0 && dcborPath[0]?.toDiagnostic() === baseCbor.toDiagnostic() ? dcborPath.slice(1) : dcborPath;
1813
+ const first = dcborPath[0];
1814
+ const elementsToAdd = first !== void 0 && (0, _bcts_dcbor.cborEquals)(first, baseCbor) ? dcborPath.slice(1) : dcborPath;
1871
1815
  for (const cborElement of elementsToAdd) envelopePath.push(_bcts_envelope.Envelope.newLeaf(cborElement));
1872
1816
  return envelopePath;
1873
1817
  }
@@ -1894,7 +1838,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1894
1838
  switch (this._pattern.type) {
1895
1839
  case "Any": return [[[haystack]], /* @__PURE__ */ new Map()];
1896
1840
  case "Value":
1897
- if (knownValueCbor.toDiagnostic() === this._pattern.cbor.toDiagnostic()) return [[[haystack]], /* @__PURE__ */ new Map()];
1841
+ if ((0, _bcts_dcbor.cborEquals)(knownValueCbor, this._pattern.cbor)) return [[[haystack]], /* @__PURE__ */ new Map()];
1898
1842
  return [[], /* @__PURE__ */ new Map()];
1899
1843
  case "Pattern": {
1900
1844
  const { paths: dcborPaths, captures: dcborCaptures } = (0, _bcts_dcbor_pattern.patternPathsWithCaptures)(this._pattern.pattern, knownValueCbor);
@@ -1918,7 +1862,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1918
1862
  switch (this._pattern.type) {
1919
1863
  case "Any": return [[[haystack]], /* @__PURE__ */ new Map()];
1920
1864
  case "Value":
1921
- if (leafCbor.toDiagnostic() === this._pattern.cbor.toDiagnostic()) return [[[haystack]], /* @__PURE__ */ new Map()];
1865
+ if ((0, _bcts_dcbor.cborEquals)(leafCbor, this._pattern.cbor)) return [[[haystack]], /* @__PURE__ */ new Map()];
1922
1866
  return [[], /* @__PURE__ */ new Map()];
1923
1867
  case "Pattern": {
1924
1868
  const { paths: dcborPaths, captures: dcborCaptures } = (0, _bcts_dcbor_pattern.patternPathsWithCaptures)(this._pattern.pattern, leafCbor);
@@ -1926,7 +1870,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1926
1870
  const basePath = [haystack];
1927
1871
  return [dcborPaths.map((dcborPath) => {
1928
1872
  const extendedPath = [...basePath];
1929
- const elementsToAdd = dcborPath.length > 0 && dcborPath[0]?.toDiagnostic() === leafCbor.toDiagnostic() ? dcborPath.slice(1) : dcborPath;
1873
+ const first = dcborPath[0];
1874
+ const elementsToAdd = first !== void 0 && (0, _bcts_dcbor.cborEquals)(first, leafCbor) ? dcborPath.slice(1) : dcborPath;
1930
1875
  for (const cborElement of elementsToAdd) extendedPath.push(_bcts_envelope.Envelope.newLeaf(cborElement));
1931
1876
  return extendedPath;
1932
1877
  }), this._convertDcborCapturesToEnvelopeCaptures(dcborCaptures, haystack, leafCbor)];
@@ -1961,13 +1906,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1961
1906
  }
1962
1907
  }
1963
1908
  /**
1964
- * Equality comparison.
1909
+ * Equality comparison. `Value` variants compare by canonical CBOR
1910
+ * byte sequence (mirrors Rust `==` on `CBOR`); `Pattern` variants fall
1911
+ * back to display-string compare since `DCBORPattern` doesn't expose
1912
+ * structural equality outside the crate.
1965
1913
  */
1966
1914
  equals(other) {
1967
1915
  if (this._pattern.type !== other._pattern.type) return false;
1968
1916
  switch (this._pattern.type) {
1969
1917
  case "Any": return true;
1970
- case "Value": return this._pattern.cbor.toDiagnostic() === other._pattern.cbor.toDiagnostic();
1918
+ case "Value": return (0, _bcts_dcbor.cborEquals)(this._pattern.cbor, other._pattern.cbor);
1971
1919
  case "Pattern": return (0, _bcts_dcbor_pattern.patternDisplay)(this._pattern.pattern) === (0, _bcts_dcbor_pattern.patternDisplay)(other._pattern.pattern);
1972
1920
  }
1973
1921
  }
@@ -1977,7 +1925,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1977
1925
  hashCode() {
1978
1926
  switch (this._pattern.type) {
1979
1927
  case "Any": return 0;
1980
- case "Value": return simpleStringHash(this._pattern.cbor.toDiagnostic());
1928
+ case "Value": {
1929
+ const bytes = (0, _bcts_dcbor.cborData)(this._pattern.cbor);
1930
+ let hash = 0;
1931
+ for (const byte of bytes) hash = hash * 31 + byte | 0;
1932
+ return hash;
1933
+ }
1981
1934
  case "Pattern": return simpleStringHash((0, _bcts_dcbor_pattern.patternDisplay)(this._pattern.pattern));
1982
1935
  }
1983
1936
  }
@@ -1993,10 +1946,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1993
1946
  }
1994
1947
  return hash;
1995
1948
  }
1996
-
1997
- //#endregion
1998
- //#region src/pattern/leaf/index.ts
1999
- /**
1949
+ //#endregion
1950
+ //#region src/pattern/leaf/index.ts
1951
+ /**
2000
1952
  * Creates a CBOR leaf pattern.
2001
1953
  */
2002
1954
  function leafCbor(pattern) {
@@ -2195,9 +2147,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2195
2147
  case "KnownValue": return pattern.pattern.toString();
2196
2148
  }
2197
2149
  }
2198
-
2199
- //#endregion
2200
- //#region src/pattern/structure/leaf-structure-pattern.ts
2150
+ //#endregion
2151
+ //#region src/pattern/structure/leaf-structure-pattern.ts
2201
2152
  let createStructureLeafPattern;
2202
2153
  function registerLeafStructurePatternFactory(factory) {
2203
2154
  createStructureLeafPattern = factory;
@@ -2248,12 +2199,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2248
2199
  return 0;
2249
2200
  }
2250
2201
  };
2251
-
2252
- //#endregion
2253
- //#region src/pattern/structure/subject-pattern.ts
2254
- let createStructureSubjectPattern;
2255
- function registerSubjectPatternFactory(factory) {
2256
- createStructureSubjectPattern = factory;
2202
+ let dispatchPatternCompile$1;
2203
+ let dispatchPatternToString$3;
2204
+ function registerSubjectPatternFactory(factory) {}
2205
+ function registerSubjectPatternDispatch(dispatch) {
2206
+ dispatchPatternCompile$1 = dispatch.compile;
2207
+ dispatchPatternToString$3 = dispatch.toString;
2257
2208
  }
2258
2209
  /**
2259
2210
  * Pattern for matching subjects in envelopes.
@@ -2318,9 +2269,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2318
2269
  code.push({ type: "NavigateSubject" });
2319
2270
  break;
2320
2271
  case "Pattern":
2272
+ if (dispatchPatternCompile$1 === void 0) throw new Error("SubjectPattern.compile requires the top-level Pattern compile dispatch; not registered");
2321
2273
  code.push({ type: "NavigateSubject" });
2322
2274
  code.push({ type: "ExtendTraversal" });
2323
- this._pattern.pattern.compile(code, literals, captures);
2275
+ dispatchPatternCompile$1(this._pattern.pattern, code, literals, captures);
2324
2276
  code.push({ type: "CombineTraversal" });
2325
2277
  break;
2326
2278
  }
@@ -2331,7 +2283,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2331
2283
  toString() {
2332
2284
  switch (this._pattern.type) {
2333
2285
  case "Any": return "subj";
2334
- case "Pattern": return `subj(${this._pattern.pattern.toString()})`;
2286
+ case "Pattern": {
2287
+ const fmt = dispatchPatternToString$3;
2288
+ return `subj(${fmt !== void 0 ? fmt(this._pattern.pattern) : "?"})`;
2289
+ }
2335
2290
  }
2336
2291
  }
2337
2292
  /**
@@ -2349,9 +2304,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2349
2304
  return this._pattern.type === "Any" ? 0 : 1;
2350
2305
  }
2351
2306
  };
2352
-
2353
- //#endregion
2354
- //#region src/pattern/structure/predicate-pattern.ts
2307
+ //#endregion
2308
+ //#region src/pattern/structure/predicate-pattern.ts
2355
2309
  let createStructurePredicatePattern;
2356
2310
  function registerPredicatePatternFactory(factory) {
2357
2311
  createStructurePredicatePattern = factory;
@@ -2429,7 +2383,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2429
2383
  toString() {
2430
2384
  switch (this._pattern.type) {
2431
2385
  case "Any": return "pred";
2432
- case "Pattern": return `pred(${this._pattern.pattern.toString()})`;
2386
+ case "Pattern": return `pred(${dispatchPatternToString(this._pattern.pattern)})`;
2433
2387
  }
2434
2388
  }
2435
2389
  /**
@@ -2447,9 +2401,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2447
2401
  return this._pattern.type === "Any" ? 0 : 1;
2448
2402
  }
2449
2403
  };
2450
-
2451
- //#endregion
2452
- //#region src/pattern/structure/object-pattern.ts
2404
+ //#endregion
2405
+ //#region src/pattern/structure/object-pattern.ts
2453
2406
  let createStructureObjectPattern;
2454
2407
  function registerObjectPatternFactory(factory) {
2455
2408
  createStructureObjectPattern = factory;
@@ -2527,7 +2480,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2527
2480
  toString() {
2528
2481
  switch (this._pattern.type) {
2529
2482
  case "Any": return "obj";
2530
- case "Pattern": return `obj(${this._pattern.pattern.toString()})`;
2483
+ case "Pattern": return `obj(${dispatchPatternToString(this._pattern.pattern)})`;
2531
2484
  }
2532
2485
  }
2533
2486
  /**
@@ -2545,13 +2498,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2545
2498
  return this._pattern.type === "Any" ? 0 : 1;
2546
2499
  }
2547
2500
  };
2548
-
2549
- //#endregion
2550
- //#region src/pattern/structure/assertions-pattern.ts
2501
+ //#endregion
2502
+ //#region src/pattern/structure/assertions-pattern.ts
2551
2503
  let createStructureAssertionsPattern;
2504
+ let dispatchPatternToString$2;
2552
2505
  function registerAssertionsPatternFactory(factory) {
2553
2506
  createStructureAssertionsPattern = factory;
2554
2507
  }
2508
+ function registerAssertionsPatternToStringDispatch(fn) {
2509
+ dispatchPatternToString$2 = fn;
2510
+ }
2555
2511
  /**
2556
2512
  * Pattern for matching assertions in envelopes.
2557
2513
  *
@@ -2589,17 +2545,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2589
2545
  });
2590
2546
  }
2591
2547
  /**
2592
- * Creates a new AssertionsPattern that matches assertions with both
2593
- * predicate and object patterns.
2594
- */
2595
- static withBoth(predicatePattern, objectPattern) {
2596
- return new AssertionsPattern({
2597
- type: "WithBoth",
2598
- predicatePattern,
2599
- objectPattern
2600
- });
2601
- }
2602
- /**
2603
2548
  * Gets the pattern type.
2604
2549
  */
2605
2550
  get patternType() {
@@ -2610,14 +2555,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2610
2555
  */
2611
2556
  predicatePattern() {
2612
2557
  if (this._pattern.type === "WithPredicate") return this._pattern.pattern;
2613
- if (this._pattern.type === "WithBoth") return this._pattern.predicatePattern;
2614
2558
  }
2615
2559
  /**
2616
2560
  * Gets the object pattern if this has one, undefined otherwise.
2617
2561
  */
2618
2562
  objectPattern() {
2619
2563
  if (this._pattern.type === "WithObject") return this._pattern.pattern;
2620
- if (this._pattern.type === "WithBoth") return this._pattern.objectPattern;
2621
2564
  }
2622
2565
  pathsWithCaptures(haystack) {
2623
2566
  const paths = [];
@@ -2639,14 +2582,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2639
2582
  }
2640
2583
  break;
2641
2584
  }
2642
- case "WithBoth": {
2643
- const predicate = assertion.asPredicate?.();
2644
- const object = assertion.asObject?.();
2645
- if (predicate !== void 0 && object !== void 0) {
2646
- if (matchPattern(this._pattern.predicatePattern, predicate) && matchPattern(this._pattern.objectPattern, object)) paths.push([assertion]);
2647
- }
2648
- break;
2649
- }
2650
2585
  }
2651
2586
  return [paths, /* @__PURE__ */ new Map()];
2652
2587
  }
@@ -2669,11 +2604,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2669
2604
  return false;
2670
2605
  }
2671
2606
  toString() {
2607
+ const fmt = dispatchPatternToString$2;
2672
2608
  switch (this._pattern.type) {
2673
2609
  case "Any": return "assert";
2674
- case "WithPredicate": return `assertpred(${this._pattern.pattern.toString()})`;
2675
- case "WithObject": return `assertobj(${this._pattern.pattern.toString()})`;
2676
- case "WithBoth": return `assert(${this._pattern.predicatePattern.toString()}, ${this._pattern.objectPattern.toString()})`;
2610
+ case "WithPredicate": return `assertpred(${fmt !== void 0 ? fmt(this._pattern.pattern) : "?"})`;
2611
+ case "WithObject": return `assertobj(${fmt !== void 0 ? fmt(this._pattern.pattern) : "?"})`;
2677
2612
  }
2678
2613
  }
2679
2614
  /**
@@ -2685,10 +2620,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2685
2620
  case "Any": return true;
2686
2621
  case "WithPredicate":
2687
2622
  case "WithObject": return this._pattern.pattern === other._pattern.pattern;
2688
- case "WithBoth": {
2689
- const otherBoth = other._pattern;
2690
- return this._pattern.predicatePattern === otherBoth.predicatePattern && this._pattern.objectPattern === otherBoth.objectPattern;
2691
- }
2692
2623
  }
2693
2624
  }
2694
2625
  /**
@@ -2699,13 +2630,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2699
2630
  case "Any": return 0;
2700
2631
  case "WithPredicate": return 1;
2701
2632
  case "WithObject": return 2;
2702
- case "WithBoth": return 3;
2703
2633
  }
2704
2634
  }
2705
2635
  };
2706
-
2707
- //#endregion
2708
- //#region src/pattern/structure/digest-pattern.ts
2636
+ //#endregion
2637
+ //#region src/pattern/structure/digest-pattern.ts
2709
2638
  let createStructureDigestPattern;
2710
2639
  function registerDigestPatternFactory(factory) {
2711
2640
  createStructureDigestPattern = factory;
@@ -2729,12 +2658,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2729
2658
  this._pattern = pattern;
2730
2659
  }
2731
2660
  /**
2732
- * Creates a new DigestPattern that matches any digest.
2733
- */
2734
- static any() {
2735
- return new DigestPattern({ type: "Any" });
2736
- }
2737
- /**
2738
2661
  * Creates a new DigestPattern that matches the exact digest.
2739
2662
  */
2740
2663
  static digest(digest) {
@@ -2772,9 +2695,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2772
2695
  const digestData = digest.data();
2773
2696
  let isHit = false;
2774
2697
  switch (this._pattern.type) {
2775
- case "Any":
2776
- isHit = true;
2777
- break;
2778
2698
  case "Digest":
2779
2699
  isHit = digest.equals(this._pattern.digest);
2780
2700
  break;
@@ -2812,7 +2732,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2812
2732
  }
2813
2733
  toString() {
2814
2734
  switch (this._pattern.type) {
2815
- case "Any": return "digest";
2816
2735
  case "Digest": return `digest(${this._pattern.digest.hex()})`;
2817
2736
  case "Prefix": return `digest(${(0, _bcts_dcbor.bytesToHex)(this._pattern.prefix)})`;
2818
2737
  case "BinaryRegex": return `digest(/${this._pattern.regex.source}/)`;
@@ -2820,17 +2739,26 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2820
2739
  }
2821
2740
  /**
2822
2741
  * Equality comparison.
2742
+ *
2743
+ * `Prefix` comparison is case-insensitive on the *hex representation* to
2744
+ * mirror Rust's `eq_ignore_ascii_case` (which compares the underlying
2745
+ * `Vec<u8>` of hex bytes byte-for-byte modulo ASCII case). For raw byte
2746
+ * prefixes that happen to be ASCII, this is an ordinary byte compare.
2823
2747
  */
2824
2748
  equals(other) {
2825
2749
  if (this._pattern.type !== other._pattern.type) return false;
2826
2750
  switch (this._pattern.type) {
2827
- case "Any": return true;
2828
2751
  case "Digest": return this._pattern.digest.equals(other._pattern.digest);
2829
2752
  case "Prefix": {
2830
2753
  const thisPrefix = this._pattern.prefix;
2831
2754
  const otherPrefix = other._pattern.prefix;
2832
2755
  if (thisPrefix.length !== otherPrefix.length) return false;
2833
- for (let i = 0; i < thisPrefix.length; i++) if (thisPrefix[i] !== otherPrefix[i]) return false;
2756
+ for (let i = 0; i < thisPrefix.length; i++) {
2757
+ const a = thisPrefix[i];
2758
+ const b = otherPrefix[i];
2759
+ if (a === b) continue;
2760
+ if ((a >= 65 && a <= 90 ? a + 32 : a) !== (b >= 65 && b <= 90 ? b + 32 : b)) return false;
2761
+ }
2834
2762
  return true;
2835
2763
  }
2836
2764
  case "BinaryRegex": return this._pattern.regex.source === other._pattern.regex.source;
@@ -2841,7 +2769,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2841
2769
  */
2842
2770
  hashCode() {
2843
2771
  switch (this._pattern.type) {
2844
- case "Any": return 0;
2845
2772
  case "Digest": {
2846
2773
  const data = this._pattern.digest.data().slice(0, 8);
2847
2774
  let hash = 0;
@@ -2850,7 +2777,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2850
2777
  }
2851
2778
  case "Prefix": {
2852
2779
  let hash = 0;
2853
- for (const byte of this._pattern.prefix) hash = hash * 31 + byte | 0;
2780
+ for (const byte of this._pattern.prefix) {
2781
+ const folded = byte >= 65 && byte <= 90 ? byte + 32 : byte;
2782
+ hash = hash * 31 + folded | 0;
2783
+ }
2854
2784
  return hash;
2855
2785
  }
2856
2786
  case "BinaryRegex": {
@@ -2861,9 +2791,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2861
2791
  }
2862
2792
  }
2863
2793
  };
2864
-
2865
- //#endregion
2866
- //#region src/pattern/structure/node-pattern.ts
2794
+ //#endregion
2795
+ //#region src/pattern/structure/node-pattern.ts
2867
2796
  let createStructureNodePattern;
2868
2797
  function registerNodePatternFactory(factory) {
2869
2798
  createStructureNodePattern = factory;
@@ -2903,28 +2832,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2903
2832
  });
2904
2833
  }
2905
2834
  /**
2906
- * Creates a new NodePattern with a subject pattern constraint.
2907
- */
2908
- static withSubject(subjectPattern) {
2909
- return new NodePattern({
2910
- type: "WithSubject",
2911
- subjectPattern
2912
- });
2913
- }
2914
- /**
2915
2835
  * Gets the pattern type.
2916
2836
  */
2917
2837
  get patternType() {
2918
2838
  return this._pattern;
2919
2839
  }
2920
2840
  /**
2921
- * Gets the subject pattern if this is a WithSubject type, undefined otherwise.
2841
+ * Returns the subject pattern, if any. Rust's `NodePattern` does not carry
2842
+ * subject patterns, so this always returns `undefined`.
2922
2843
  */
2923
- subjectPattern() {
2924
- return this._pattern.type === "WithSubject" ? this._pattern.subjectPattern : void 0;
2925
- }
2844
+ subjectPattern() {}
2926
2845
  /**
2927
- * Gets the assertion patterns (empty array if none).
2846
+ * Returns the assertion patterns. Rust's `NodePattern` does not carry
2847
+ * assertion sub-patterns, so this always returns an empty array.
2928
2848
  */
2929
2849
  assertionPatterns() {
2930
2850
  return [];
@@ -2939,9 +2859,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2939
2859
  case "AssertionsInterval":
2940
2860
  isHit = this._pattern.interval.contains(haystack.assertions().length);
2941
2861
  break;
2942
- case "WithSubject":
2943
- isHit = true;
2944
- break;
2945
2862
  }
2946
2863
  return [isHit ? [[haystack]] : [], /* @__PURE__ */ new Map()];
2947
2864
  }
@@ -2962,7 +2879,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2962
2879
  switch (this._pattern.type) {
2963
2880
  case "Any": return "node";
2964
2881
  case "AssertionsInterval": return `node(${this._pattern.interval.toString()})`;
2965
- case "WithSubject": return `node(${this._pattern.subjectPattern.toString()})`;
2966
2882
  }
2967
2883
  }
2968
2884
  /**
@@ -2973,7 +2889,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2973
2889
  switch (this._pattern.type) {
2974
2890
  case "Any": return true;
2975
2891
  case "AssertionsInterval": return this._pattern.interval.equals(other._pattern.interval);
2976
- case "WithSubject": return this._pattern.subjectPattern === other._pattern.subjectPattern;
2977
2892
  }
2978
2893
  }
2979
2894
  /**
@@ -2983,13 +2898,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2983
2898
  switch (this._pattern.type) {
2984
2899
  case "Any": return 0;
2985
2900
  case "AssertionsInterval": return this._pattern.interval.min() * 31 + (this._pattern.interval.max() ?? 0);
2986
- case "WithSubject": return 1;
2987
2901
  }
2988
2902
  }
2989
2903
  };
2990
-
2991
- //#endregion
2992
- //#region src/pattern/structure/obscured-pattern.ts
2904
+ //#endregion
2905
+ //#region src/pattern/structure/obscured-pattern.ts
2993
2906
  let createStructureObscuredPattern;
2994
2907
  function registerObscuredPatternFactory(factory) {
2995
2908
  createStructureObscuredPattern = factory;
@@ -3091,16 +3004,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3091
3004
  }
3092
3005
  }
3093
3006
  };
3094
-
3095
- //#endregion
3096
- //#region src/pattern/structure/wrapped-pattern.ts
3007
+ //#endregion
3008
+ //#region src/pattern/structure/wrapped-pattern.ts
3097
3009
  let createStructureWrappedPattern;
3010
+ let createAnyPattern;
3098
3011
  let dispatchPatternPathsWithCaptures;
3099
3012
  let dispatchPatternCompile;
3100
3013
  let dispatchPatternToString$1;
3101
3014
  function registerWrappedPatternFactory(factory) {
3102
3015
  createStructureWrappedPattern = factory;
3103
3016
  }
3017
+ function registerWrappedPatternAny(factory) {
3018
+ createAnyPattern = factory;
3019
+ }
3104
3020
  function registerWrappedPatternDispatch(dispatch) {
3105
3021
  dispatchPatternPathsWithCaptures = dispatch.pathsWithCaptures;
3106
3022
  dispatchPatternCompile = dispatch.compile;
@@ -3134,10 +3050,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3134
3050
  }
3135
3051
  /**
3136
3052
  * Creates a new WrappedPattern that matches any wrapped envelope and descends into it.
3137
- * Note: This requires Pattern.any() to be available, so it's set up during registration.
3053
+ *
3054
+ * Mirrors Rust `WrappedPattern::unwrap()` which delegates to
3055
+ * `Self::unwrap_matching(Pattern::any())`. The `any` factory is wired in
3056
+ * during module-load registration to break the circular import on the
3057
+ * top-level `Pattern` type.
3138
3058
  */
3139
3059
  static unwrap() {
3140
- return new WrappedPattern({ type: "Any" });
3060
+ if (createAnyPattern === void 0) throw new Error("WrappedPattern.unwrap() requires Pattern.any factory; not registered");
3061
+ return WrappedPattern.unwrapMatching(createAnyPattern());
3141
3062
  }
3142
3063
  /**
3143
3064
  * Gets the pattern type.
@@ -3213,9 +3134,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3213
3134
  switch (this._pattern.type) {
3214
3135
  case "Any": return "wrapped";
3215
3136
  case "Unwrap": {
3216
- const patternStr = dispatchPatternToString$1 !== void 0 ? dispatchPatternToString$1(this._pattern.pattern) : "*";
3217
- if (patternStr === "*") return "unwrap";
3218
- return `unwrap(${patternStr})`;
3137
+ const inner = this._pattern.pattern;
3138
+ if (inner.type === "Meta" && inner.pattern.type === "Any") return "unwrap";
3139
+ return `unwrap(${dispatchPatternToString$1 !== void 0 ? dispatchPatternToString$1(inner) : "?"})`;
3219
3140
  }
3220
3141
  }
3221
3142
  }
@@ -3234,10 +3155,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3234
3155
  return this._pattern.type === "Any" ? 0 : 1;
3235
3156
  }
3236
3157
  };
3237
-
3238
- //#endregion
3239
- //#region src/pattern/structure/index.ts
3240
- /**
3158
+ //#endregion
3159
+ //#region src/pattern/structure/index.ts
3160
+ /**
3241
3161
  * Creates a Leaf structure pattern.
3242
3162
  */
3243
3163
  function structureLeaf(pattern) {
@@ -3406,9 +3326,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3406
3326
  case "Wrapped": return pattern.pattern.toString();
3407
3327
  }
3408
3328
  }
3409
-
3410
- //#endregion
3411
- //#region src/pattern/vm.ts
3329
+ //#endregion
3330
+ //#region src/pattern/vm.ts
3412
3331
  let _patternPathsWithCaptures$1;
3413
3332
  let _patternMatches;
3414
3333
  let _patternPaths;
@@ -3441,10 +3360,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3441
3360
  case "Wrapped":
3442
3361
  if (envCase.type === "node") {
3443
3362
  const subject = envCase.subject;
3444
- if (subject.isWrapped()) {
3445
- const unwrapped = subject.unwrap();
3446
- if (unwrapped !== void 0) return [[unwrapped, "Content"]];
3447
- }
3363
+ if (subject.isWrapped()) return [[subject.tryUnwrap(), "Content"]];
3448
3364
  } else if (envCase.type === "wrapped") return [[envCase.envelope, "Content"]];
3449
3365
  return [];
3450
3366
  }
@@ -4053,9 +3969,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4053
3969
  }
4054
3970
  }
4055
3971
  }
4056
-
4057
- //#endregion
4058
- //#region src/pattern/meta/any-pattern.ts
3972
+ //#endregion
3973
+ //#region src/pattern/meta/any-pattern.ts
4059
3974
  let createMetaAnyPattern;
4060
3975
  function registerAnyPatternFactory(factory) {
4061
3976
  createMetaAnyPattern = factory;
@@ -4105,13 +4020,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4105
4020
  return 0;
4106
4021
  }
4107
4022
  };
4108
-
4109
- //#endregion
4110
- //#region src/pattern/meta/and-pattern.ts
4111
- let createMetaAndPattern;
4112
- function registerAndPatternFactory(factory) {
4113
- createMetaAndPattern = factory;
4114
- }
4023
+ function registerAndPatternFactory(factory) {}
4115
4024
  /**
4116
4025
  * A pattern that matches if all contained patterns match.
4117
4026
  *
@@ -4167,13 +4076,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4167
4076
  return this._patterns.length;
4168
4077
  }
4169
4078
  };
4170
-
4171
- //#endregion
4172
- //#region src/pattern/meta/or-pattern.ts
4173
- let createMetaOrPattern;
4174
- function registerOrPatternFactory(factory) {
4175
- createMetaOrPattern = factory;
4176
- }
4079
+ function registerOrPatternFactory(factory) {}
4177
4080
  /**
4178
4081
  * A pattern that matches if any contained pattern matches.
4179
4082
  *
@@ -4267,13 +4170,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4267
4170
  return this._patterns.length;
4268
4171
  }
4269
4172
  };
4270
-
4271
- //#endregion
4272
- //#region src/pattern/meta/not-pattern.ts
4273
- let createMetaNotPattern;
4274
- function registerNotPatternFactory(factory) {
4275
- createMetaNotPattern = factory;
4276
- }
4173
+ function registerNotPatternFactory(factory) {}
4277
4174
  /**
4278
4175
  * A pattern that negates another pattern; matches when the inner pattern does not match.
4279
4176
  *
@@ -4332,13 +4229,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4332
4229
  return 1;
4333
4230
  }
4334
4231
  };
4335
-
4336
- //#endregion
4337
- //#region src/pattern/meta/capture-pattern.ts
4338
- let createMetaCapturePattern;
4339
- function registerCapturePatternFactory(factory) {
4340
- createMetaCapturePattern = factory;
4341
- }
4232
+ function registerCapturePatternFactory(factory) {}
4342
4233
  /**
4343
4234
  * A pattern that captures a match with a name.
4344
4235
  *
@@ -4417,13 +4308,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4417
4308
  return hash;
4418
4309
  }
4419
4310
  };
4420
-
4421
- //#endregion
4422
- //#region src/pattern/meta/search-pattern.ts
4423
- let createMetaSearchPattern;
4424
- function registerSearchPatternFactory(factory) {
4425
- createMetaSearchPattern = factory;
4426
- }
4311
+ function registerSearchPatternFactory(factory) {}
4427
4312
  /**
4428
4313
  * A pattern that searches the entire envelope tree for matches.
4429
4314
  *
@@ -4473,30 +4358,20 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4473
4358
  return [uniquePaths, /* @__PURE__ */ new Map()];
4474
4359
  }
4475
4360
  /**
4476
- * Walk the envelope tree recursively.
4361
+ * Walk the envelope tree using the canonical `Envelope.walk` traversal.
4362
+ *
4363
+ * Mirrors Rust `bc_envelope::Envelope::walk(false, vec![], visitor)`
4364
+ * which is what `SearchPattern::paths_with_captures` uses. The earlier
4365
+ * port hand-rolled a recursion that double-recursed assertions and
4366
+ * stepped through wrapped subjects manually, producing a different
4367
+ * path order (and extra duplicates that the digest-set deduplication
4368
+ * would partially mask).
4477
4369
  */
4478
4370
  _walkEnvelope(envelope, pathToCurrent, visitor) {
4479
- visitor(envelope, pathToCurrent);
4480
- const subject = envelope.subject();
4481
- const newPath = [...pathToCurrent, envelope];
4482
- if (!subject.digest().equals(envelope.digest())) this._walkEnvelope(subject, newPath, visitor);
4483
- for (const assertion of envelope.assertions()) {
4484
- this._walkEnvelope(assertion, newPath, visitor);
4485
- const predicate = assertion.asPredicate?.();
4486
- if (predicate !== void 0) {
4487
- const assertionPath = [...newPath, assertion];
4488
- this._walkEnvelope(predicate, assertionPath, visitor);
4489
- }
4490
- const object = assertion.asObject?.();
4491
- if (object !== void 0) {
4492
- const assertionPath = [...newPath, assertion];
4493
- this._walkEnvelope(object, assertionPath, visitor);
4494
- }
4495
- }
4496
- if (subject.isWrapped()) {
4497
- const unwrapped = subject.tryUnwrap?.();
4498
- if (unwrapped !== void 0) this._walkEnvelope(unwrapped, newPath, visitor);
4499
- }
4371
+ envelope.walk(false, pathToCurrent, (current, _level, _edge, state) => {
4372
+ visitor(current, state);
4373
+ return [[...state, current], false];
4374
+ });
4500
4375
  }
4501
4376
  paths(haystack) {
4502
4377
  return this.pathsWithCaptures(haystack)[0];
@@ -4550,13 +4425,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4550
4425
  const p = pattern;
4551
4426
  if (p.collectCaptureNames !== void 0) p.collectCaptureNames(out);
4552
4427
  }
4553
-
4554
- //#endregion
4555
- //#region src/pattern/meta/traverse-pattern.ts
4556
- let createMetaTraversePattern;
4557
- function registerTraversePatternFactory(factory) {
4558
- createMetaTraversePattern = factory;
4559
- }
4428
+ function registerTraversePatternFactory(factory) {}
4560
4429
  let _patternPathsWithCaptures;
4561
4430
  let _patternCompile;
4562
4431
  let _patternIsComplex;
@@ -4631,7 +4500,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4631
4500
  return _patternIsComplex(this._first) || this._rest !== void 0;
4632
4501
  }
4633
4502
  toString() {
4634
- return this.patterns().map((p) => p.toString()).join(" -> ");
4503
+ return this.patterns().map((p) => dispatchPatternToString(p)).join(" -> ");
4635
4504
  }
4636
4505
  /**
4637
4506
  * Equality comparison.
@@ -4650,13 +4519,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4650
4519
  return this.patterns().length;
4651
4520
  }
4652
4521
  };
4653
-
4654
- //#endregion
4655
- //#region src/pattern/meta/group-pattern.ts
4656
- let createMetaGroupPattern;
4657
- function registerGroupPatternFactory(factory) {
4658
- createMetaGroupPattern = factory;
4659
- }
4522
+ function registerGroupPatternFactory(factory) {}
4660
4523
  /**
4661
4524
  * A pattern that matches with repetition.
4662
4525
  *
@@ -4732,10 +4595,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4732
4595
  return this._quantifier.min() * 31 + (this._quantifier.max() ?? 0);
4733
4596
  }
4734
4597
  };
4735
-
4736
- //#endregion
4737
- //#region src/pattern/meta/index.ts
4738
- /**
4598
+ //#endregion
4599
+ //#region src/pattern/meta/index.ts
4600
+ /**
4739
4601
  * Creates an Any meta pattern.
4740
4602
  */
4741
4603
  function metaAny(pattern) {
@@ -4922,10 +4784,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4922
4784
  const p = pattern;
4923
4785
  if (p.collectCaptureNames !== void 0) p.collectCaptureNames(out);
4924
4786
  }
4925
-
4926
- //#endregion
4927
- //#region src/pattern/dcbor-integration.ts
4928
- /**
4787
+ //#endregion
4788
+ //#region src/pattern/dcbor-integration.ts
4789
+ /**
4929
4790
  * Convert a dcbor-pattern Pattern to a bc-envelope-pattern Pattern.
4930
4791
  *
4931
4792
  * This function serves as the bridge between the two pattern systems,
@@ -4988,17 +4849,44 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4988
4849
  */
4989
4850
  function convertStructurePatternToEnvelopePattern(structurePattern) {
4990
4851
  switch (structurePattern.type) {
4991
- case "Array": return ok({
4992
- type: "Leaf",
4993
- pattern: leafArray(ArrayPattern.fromDcborPattern({
4994
- kind: "Structure",
4995
- pattern: structurePattern
4996
- }))
4997
- });
4998
- case "Map": return ok({
4999
- type: "Leaf",
5000
- pattern: leafMap(MapPattern.any())
5001
- });
4852
+ case "Array": {
4853
+ const inner = structurePattern.pattern;
4854
+ let arrayPattern;
4855
+ switch (inner.variant) {
4856
+ case "Any":
4857
+ arrayPattern = ArrayPattern.any();
4858
+ break;
4859
+ case "Length":
4860
+ arrayPattern = ArrayPattern.fromInterval(inner.length);
4861
+ break;
4862
+ case "Elements":
4863
+ arrayPattern = ArrayPattern.fromDcborArrayPattern(inner);
4864
+ break;
4865
+ }
4866
+ return ok({
4867
+ type: "Leaf",
4868
+ pattern: leafArray(arrayPattern)
4869
+ });
4870
+ }
4871
+ case "Map": {
4872
+ const inner = structurePattern.pattern;
4873
+ let mapPattern;
4874
+ switch (inner.variant) {
4875
+ case "Any":
4876
+ mapPattern = MapPattern.any();
4877
+ break;
4878
+ case "Length":
4879
+ mapPattern = MapPattern.fromInterval(inner.length);
4880
+ break;
4881
+ case "Constraints":
4882
+ mapPattern = MapPattern.any();
4883
+ break;
4884
+ }
4885
+ return ok({
4886
+ type: "Leaf",
4887
+ pattern: leafMap(mapPattern)
4888
+ });
4889
+ }
5002
4890
  case "Tagged": return ok({
5003
4891
  type: "Leaf",
5004
4892
  pattern: leafTag(TaggedPattern.fromDcborPattern(structurePattern.pattern))
@@ -5055,10 +4943,172 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5055
4943
  });
5056
4944
  }
5057
4945
  }
5058
-
5059
- //#endregion
5060
- //#region src/pattern/index.ts
5061
- /**
4946
+ //#endregion
4947
+ //#region src/parse/utils.ts
4948
+ let createCborPattern;
4949
+ let createCborPatternFromDcbor;
4950
+ let createAnyArray;
4951
+ let createArrayWithCount;
4952
+ let createArrayWithRange;
4953
+ let createArrayFromDcborPattern;
4954
+ /**
4955
+ * Register pattern factory functions.
4956
+ * This is called by the pattern module to avoid circular dependencies.
4957
+ */
4958
+ function registerPatternFactories(factories) {
4959
+ createCborPattern = factories.cborPattern;
4960
+ createCborPatternFromDcbor = factories.cborPatternFromDcbor;
4961
+ createAnyArray = factories.anyArray;
4962
+ createArrayWithCount = factories.arrayWithCount;
4963
+ createArrayWithRange = factories.arrayWithRange;
4964
+ createArrayFromDcborPattern = factories.arrayFromDcborPattern;
4965
+ }
4966
+ /**
4967
+ * Skips whitespace in the source string.
4968
+ *
4969
+ * @param src - The source string
4970
+ * @param pos - The current position (modified in place)
4971
+ */
4972
+ function skipWs$1(src, pos) {
4973
+ while (pos.value < src.length) {
4974
+ const ch = src[pos.value];
4975
+ if (ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f") pos.value++;
4976
+ else break;
4977
+ }
4978
+ }
4979
+ /**
4980
+ * Parses a CBOR value or dcbor-pattern expression.
4981
+ *
4982
+ * @param src - The source string
4983
+ * @returns The parsed pattern and consumed character count, or an error
4984
+ */
4985
+ function parseCborInner(src) {
4986
+ if (createCborPattern === void 0 || createCborPatternFromDcbor === void 0) return err(unknown());
4987
+ const pos = { value: 0 };
4988
+ skipWs$1(src, pos);
4989
+ if (src[pos.value] === "/") {
4990
+ pos.value++;
4991
+ const start = pos.value;
4992
+ let escape = false;
4993
+ while (pos.value < src.length) {
4994
+ const b = src[pos.value];
4995
+ pos.value++;
4996
+ if (escape) {
4997
+ escape = false;
4998
+ continue;
4999
+ }
5000
+ if (b === "\\") {
5001
+ escape = true;
5002
+ continue;
5003
+ }
5004
+ if (b === "/") {
5005
+ const parseResult = (0, _bcts_dcbor_pattern.parse)(src.slice(start, pos.value - 1));
5006
+ if (!parseResult.ok) return err(invalidPattern({
5007
+ start,
5008
+ end: pos.value - 1
5009
+ }));
5010
+ skipWs$1(src, pos);
5011
+ return ok([createCborPatternFromDcbor(parseResult.value), pos.value]);
5012
+ }
5013
+ }
5014
+ return err(unterminatedRegex({
5015
+ start: start - 1,
5016
+ end: pos.value
5017
+ }));
5018
+ }
5019
+ if (src.slice(pos.value, pos.value + 3) === "ur:") {
5020
+ const parseResult = (0, _bcts_dcbor_parse.parseDcborItemPartial)(src.slice(pos.value));
5021
+ if (!parseResult.ok) return err(unknown());
5022
+ const [cborValue, consumed] = parseResult.value;
5023
+ return ok([createCborPattern(cborValue), pos.value + consumed]);
5024
+ }
5025
+ const parseResult = (0, _bcts_dcbor_parse.parseDcborItemPartial)(src.slice(pos.value));
5026
+ if (!parseResult.ok) return err(unknown());
5027
+ const [cborValue, consumed] = parseResult.value;
5028
+ return ok([createCborPattern(cborValue), pos.value + consumed]);
5029
+ }
5030
+ /**
5031
+ * Parses an array pattern inner content.
5032
+ *
5033
+ * @param src - The source string (content between [ and ])
5034
+ * @returns The parsed pattern and consumed character count, or an error
5035
+ */
5036
+ function parseArrayInner(src) {
5037
+ if (createAnyArray === void 0 || createArrayWithCount === void 0 || createArrayWithRange === void 0 || createArrayFromDcborPattern === void 0) return err(unknown());
5038
+ const pos = { value: 0 };
5039
+ skipWs$1(src, pos);
5040
+ if (src[pos.value] === "*") {
5041
+ pos.value++;
5042
+ skipWs$1(src, pos);
5043
+ return ok([createAnyArray(), pos.value]);
5044
+ }
5045
+ if (src[pos.value] === "{") {
5046
+ pos.value++;
5047
+ skipWs$1(src, pos);
5048
+ const startPos = pos.value;
5049
+ while (pos.value < src.length && src[pos.value] !== void 0 && /\d/.test(src[pos.value])) pos.value++;
5050
+ if (startPos === pos.value) return err(invalidRange({
5051
+ start: pos.value,
5052
+ end: pos.value
5053
+ }));
5054
+ const firstNum = parseInt(src.slice(startPos, pos.value), 10);
5055
+ if (Number.isNaN(firstNum)) return err(invalidNumberFormat({
5056
+ start: startPos,
5057
+ end: pos.value
5058
+ }));
5059
+ skipWs$1(src, pos);
5060
+ if (pos.value >= src.length) return err(unexpectedEndOfInput());
5061
+ const ch = src[pos.value];
5062
+ if (ch === "}") {
5063
+ pos.value++;
5064
+ skipWs$1(src, pos);
5065
+ return ok([createArrayWithCount(firstNum), pos.value]);
5066
+ }
5067
+ if (ch === ",") {
5068
+ pos.value++;
5069
+ skipWs$1(src, pos);
5070
+ if (pos.value >= src.length) return err(unexpectedEndOfInput());
5071
+ const nextCh = src[pos.value];
5072
+ if (nextCh === "}") {
5073
+ pos.value++;
5074
+ skipWs$1(src, pos);
5075
+ return ok([createArrayWithRange(firstNum, void 0), pos.value]);
5076
+ }
5077
+ if (nextCh !== void 0 && /\d/.test(nextCh)) {
5078
+ const secondStart = pos.value;
5079
+ while (pos.value < src.length && src[pos.value] !== void 0 && /\d/.test(src[pos.value])) pos.value++;
5080
+ const secondNum = parseInt(src.slice(secondStart, pos.value), 10);
5081
+ if (Number.isNaN(secondNum)) return err(invalidNumberFormat({
5082
+ start: secondStart,
5083
+ end: pos.value
5084
+ }));
5085
+ skipWs$1(src, pos);
5086
+ if (pos.value >= src.length || src[pos.value] !== "}") return err(unexpectedEndOfInput());
5087
+ pos.value++;
5088
+ skipWs$1(src, pos);
5089
+ return ok([createArrayWithRange(firstNum, secondNum), pos.value]);
5090
+ }
5091
+ return err(invalidRange({
5092
+ start: pos.value,
5093
+ end: pos.value
5094
+ }));
5095
+ }
5096
+ return err(invalidRange({
5097
+ start: pos.value,
5098
+ end: pos.value
5099
+ }));
5100
+ }
5101
+ const parseResult = (0, _bcts_dcbor_pattern.parse)(`[${src.slice(pos.value)}]`);
5102
+ if (!parseResult.ok) return err(invalidPattern({
5103
+ start: pos.value,
5104
+ end: src.length
5105
+ }));
5106
+ const consumed = src.length - pos.value;
5107
+ return ok([createArrayFromDcborPattern(parseResult.value), consumed]);
5108
+ }
5109
+ //#endregion
5110
+ //#region src/pattern/index.ts
5111
+ /**
5062
5112
  * Creates a Leaf pattern.
5063
5113
  */
5064
5114
  function patternLeaf(leaf) {
@@ -5571,6 +5621,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5571
5621
  compile: patternCompile,
5572
5622
  toString: patternToString
5573
5623
  });
5624
+ registerWrappedPatternAny(any);
5625
+ registerAssertionsPatternToStringDispatch(patternToString);
5626
+ registerSubjectPatternDispatch({
5627
+ compile: patternCompile,
5628
+ toString: patternToString
5629
+ });
5574
5630
  registerAnyPatternFactory((p) => patternMeta(metaAny(p)));
5575
5631
  registerAndPatternFactory((p) => patternMeta(metaAnd(p)));
5576
5632
  registerOrPatternFactory((p) => patternMeta(metaOr(p)));
@@ -5582,6 +5638,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5582
5638
  }
5583
5639
  registerAllFactories();
5584
5640
  registerVMPatternFunctions(patternPathsWithCaptures, patternMatches, patternPaths);
5641
+ registerPatternFactories({
5642
+ cborPattern: (value) => cborValue(value),
5643
+ cborPatternFromDcbor: (pattern) => cborPattern(pattern),
5644
+ anyArray,
5645
+ arrayWithCount: (count) => patternLeaf(leafArray(ArrayPattern.count(count))),
5646
+ arrayWithRange: (min, max) => patternLeaf(leafArray(ArrayPattern.interval(min, max))),
5647
+ arrayFromDcborPattern: (pattern) => patternLeaf(leafArray(ArrayPattern.fromDcborPattern(pattern)))
5648
+ });
5585
5649
  registerPatternMatchFn(patternMatches);
5586
5650
  registerPatternDispatchFns({
5587
5651
  pathsWithCaptures: patternPathsWithCaptures,
@@ -5591,10 +5655,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5591
5655
  toString: patternToString
5592
5656
  });
5593
5657
  registerTraverseDispatchFunctions(patternPathsWithCaptures, patternCompile, patternIsComplex);
5594
-
5595
- //#endregion
5596
- //#region src/parse/token.ts
5597
- /**
5658
+ //#endregion
5659
+ //#region src/parse/token.ts
5660
+ /**
5598
5661
  * Copyright © 2023-2026 Blockchain Commons, LLC
5599
5662
  * Copyright © 2025-2026 Parity Technologies
5600
5663
  *
@@ -6335,307 +6398,199 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6335
6398
  }
6336
6399
  }
6337
6400
  };
6338
-
6339
- //#endregion
6340
- //#region src/parse/index.ts
6341
- /**
6401
+ //#endregion
6402
+ //#region src/parse/leaf/array-parser.ts
6403
+ /**
6342
6404
  * Copyright © 2023-2026 Blockchain Commons, LLC
6343
6405
  * Copyright © 2025-2026 Parity Technologies
6344
6406
  *
6407
+ * Array parser — port of `bc-envelope-pattern-rust`
6408
+ * `parse/leaf/array_parser.rs`.
6345
6409
  *
6346
- * @bcts/envelope-pattern - Parser entry point
6347
- *
6348
- * This is a 1:1 TypeScript port of bc-envelope-pattern-rust parse/mod.rs
6349
- * Recursive descent parser for Gordian Envelope pattern syntax.
6410
+ * Mirrors Rust's flow exactly: after the `[` token has been consumed,
6411
+ * delegate to `utils::parseArrayInner` (which handles `*`, `{n}`, `{n,m}`,
6412
+ * `{n,}` directly and otherwise wraps the body in `[...]` and re-parses
6413
+ * via dcbor-pattern), then expect a closing `]`.
6350
6414
  *
6351
- * @module envelope-pattern/parse
6415
+ * @module envelope-pattern/parse/leaf/array-parser
6352
6416
  */
6417
+ function parseArray(lexer) {
6418
+ const inner = parseArrayInner(lexer.remainder());
6419
+ if (!inner.ok) return inner;
6420
+ const [pattern, consumed] = inner.value;
6421
+ lexer.bump(consumed);
6422
+ const close = lexer.next();
6423
+ if (close === void 0) return err(expectedCloseBracket(lexer.span()));
6424
+ if (close.token.type !== "BracketClose") return err(unexpectedToken(close.token, close.span));
6425
+ return ok(pattern);
6426
+ }
6427
+ //#endregion
6428
+ //#region src/parse/leaf/cbor-parser.ts
6353
6429
  /**
6354
- * Parse a pattern expression string into a Pattern.
6355
- */
6356
- function parse(input) {
6357
- const lexer = new Lexer(input);
6358
- const result = parseOr(lexer);
6359
- if (!result.ok) {
6360
- const dcborResult = (0, _bcts_dcbor_pattern.parse)(input);
6361
- if (dcborResult.ok) return convertDcborPatternToEnvelopePattern$1(dcborResult.value);
6362
- return result;
6363
- }
6364
- const next = lexer.next();
6365
- if (next !== void 0) return err(extraData(next.span));
6366
- return result;
6367
- }
6368
- /**
6369
- * Parse a pattern, allowing extra data after the pattern.
6370
- */
6371
- function parsePartial(input) {
6372
- const lexer = new Lexer(input);
6373
- const result = parseOr(lexer);
6374
- if (!result.ok) return result;
6375
- return ok([result.value, lexer.position]);
6376
- }
6377
- /**
6378
- * Convert a dcbor-pattern Pattern to an envelope-pattern Pattern.
6430
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6431
+ * Copyright © 2025-2026 Parity Technologies
6432
+ *
6433
+ * CBOR pattern parser — port of `bc-envelope-pattern-rust`
6434
+ * `parse/leaf/cbor_parser.rs`.
6435
+ *
6436
+ * Mirrors Rust's flow: lookahead for `(`. If absent, return `any_cbor()`.
6437
+ * Otherwise consume the `(`, delegate to `parseCborInner` (handles
6438
+ * `/regex/`, `ur:…`, and CBOR diagnostic notation), and expect a closing
6439
+ * `)`.
6440
+ *
6441
+ * @module envelope-pattern/parse/leaf/cbor-parser
6379
6442
  */
6380
- function convertDcborPatternToEnvelopePattern$1(_dcborPattern) {
6381
- return ok(any());
6382
- }
6443
+ function parseCbor(lexer) {
6444
+ if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(anyCbor());
6445
+ lexer.next();
6446
+ const innerResult = parseCborInner(lexer.remainder());
6447
+ if (!innerResult.ok) return innerResult;
6448
+ const [pattern, consumed] = innerResult.value;
6449
+ lexer.bump(consumed);
6450
+ const close = lexer.next();
6451
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
6452
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
6453
+ return ok(pattern);
6454
+ }
6455
+ //#endregion
6456
+ //#region src/parse/leaf/date-parser.ts
6383
6457
  /**
6384
- * Parse an Or expression: expr (| expr)*
6458
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6459
+ * Copyright © 2025-2026 Parity Technologies
6460
+ *
6461
+ * Date content parser — port of `bc-envelope-pattern-rust`
6462
+ * `parse/leaf/date_parser.rs`.
6463
+ *
6464
+ * Mirrors Rust's `Date::from_string`, which accepts a strict ISO-8601
6465
+ * subset, by deferring to dcbor's `CborDate.fromString`. Falls back to JS
6466
+ * `Date.parse` only as a defensive shim — that branch is unreachable for
6467
+ * conformant inputs.
6468
+ *
6469
+ * @module envelope-pattern/parse/leaf/date-parser
6385
6470
  */
6386
- function parseOr(lexer) {
6387
- const patterns = [];
6388
- const first = parseTraverse(lexer);
6389
- if (!first.ok) return first;
6390
- patterns.push(first.value);
6391
- while (true) {
6392
- if (lexer.peekToken()?.token.type !== "Or") break;
6393
- lexer.next();
6394
- const nextExpr = parseTraverse(lexer);
6395
- if (!nextExpr.ok) return nextExpr;
6396
- patterns.push(nextExpr.value);
6397
- }
6398
- if (patterns.length === 1) return ok(patterns[0]);
6399
- return ok(or(patterns));
6400
- }
6401
6471
  /**
6402
- * Parse a Traverse expression: expr (-> expr)*
6472
+ * Parse a date pattern of one of the forms accepted by Rust:
6473
+ *
6474
+ * - `/regex/` (regex match against ISO-8601 string)
6475
+ * - `start...end` (inclusive range)
6476
+ * - `start...` (earliest)
6477
+ * - `...end` (latest)
6478
+ * - `iso-8601` (exact)
6479
+ *
6480
+ * Mirrors `parse_date_content` in Rust; uses `CborDate.fromString` so the
6481
+ * accepted formats match Rust's `bc_envelope::prelude::Date::from_string`
6482
+ * exactly rather than the looser JS `Date.parse`.
6403
6483
  */
6404
- function parseTraverse(lexer) {
6405
- const patterns = [];
6406
- const first = parseAnd(lexer);
6407
- if (!first.ok) return first;
6408
- patterns.push(first.value);
6409
- while (true) {
6410
- if (lexer.peekToken()?.token.type !== "Traverse") break;
6411
- lexer.next();
6412
- const nextExpr = parseAnd(lexer);
6413
- if (!nextExpr.ok) return nextExpr;
6414
- patterns.push(nextExpr.value);
6484
+ function parseDateContent(content, span) {
6485
+ if (content.startsWith("/") && content.endsWith("/") && content.length >= 2) {
6486
+ const regexStr = content.slice(1, -1);
6487
+ try {
6488
+ return ok(dateRegex(new RegExp(regexStr)));
6489
+ } catch {
6490
+ return err(invalidRegex(span));
6491
+ }
6415
6492
  }
6416
- if (patterns.length === 1) return ok(patterns[0]);
6417
- return ok(traverse(patterns));
6418
- }
6419
- /**
6420
- * Parse an And expression: expr (& expr)*
6421
- */
6422
- function parseAnd(lexer) {
6423
- const patterns = [];
6424
- const first = parseNot(lexer);
6425
- if (!first.ok) return first;
6426
- patterns.push(first.value);
6427
- while (true) {
6428
- if (lexer.peekToken()?.token.type !== "And") break;
6429
- lexer.next();
6430
- const nextExpr = parseNot(lexer);
6431
- if (!nextExpr.ok) return nextExpr;
6432
- patterns.push(nextExpr.value);
6493
+ const ellipsisIdx = content.indexOf("...");
6494
+ if (ellipsisIdx !== -1) {
6495
+ const left = content.slice(0, ellipsisIdx);
6496
+ const right = content.slice(ellipsisIdx + 3);
6497
+ if (left.length === 0 && right.length > 0) {
6498
+ const parsed = parseIsoDateStrict(right);
6499
+ if (parsed === void 0) return err(invalidDateFormat(span));
6500
+ return ok(dateLatest(parsed));
6501
+ }
6502
+ if (left.length > 0 && right.length === 0) {
6503
+ const parsed = parseIsoDateStrict(left);
6504
+ if (parsed === void 0) return err(invalidDateFormat(span));
6505
+ return ok(dateEarliest(parsed));
6506
+ }
6507
+ if (left.length > 0 && right.length > 0) {
6508
+ const start = parseIsoDateStrict(left);
6509
+ const end = parseIsoDateStrict(right);
6510
+ if (start === void 0 || end === void 0) return err(invalidDateFormat(span));
6511
+ return ok(dateRange(start, end));
6512
+ }
6513
+ return err(invalidDateFormat(span));
6433
6514
  }
6434
- if (patterns.length === 1) return ok(patterns[0]);
6435
- return ok(and(patterns));
6515
+ const parsed = parseIsoDateStrict(content);
6516
+ if (parsed === void 0) return err(invalidDateFormat(span));
6517
+ return ok(date(parsed));
6436
6518
  }
6437
- /**
6438
- * Parse a Not expression: !? group
6439
- */
6440
- function parseNot(lexer) {
6441
- if (lexer.peekToken()?.token.type === "Not") {
6442
- lexer.next();
6443
- const inner = parseGroup(lexer);
6444
- if (!inner.ok) return inner;
6445
- return ok(notMatching(inner.value));
6519
+ function parseIsoDateStrict(value) {
6520
+ try {
6521
+ return _bcts_dcbor.CborDate.fromString(value);
6522
+ } catch {
6523
+ return;
6446
6524
  }
6447
- return parseGroup(lexer);
6448
6525
  }
6526
+ //#endregion
6527
+ //#region src/parse/leaf/known-value-parser.ts
6449
6528
  /**
6450
- * Parse a Group expression: primary quantifier?
6529
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6530
+ * Copyright © 2025-2026 Parity Technologies
6531
+ *
6532
+ * Helpers for parsing the body of a `'…'` (single-quoted) known-value
6533
+ * literal. Mirrors the inline body of Rust's `Token::SingleQuotedPattern`
6534
+ * branch in `parse_primary`:
6535
+ *
6536
+ * - If the contents are a valid `u64`, build `Pattern::known_value(...)`.
6537
+ * - Otherwise, build `Pattern::known_value_named(...)`.
6538
+ *
6539
+ * The earlier port duck-typed a fake `KnownValue`; this version uses the
6540
+ * real `KnownValue` constructor so all subsequent KnownValue methods work
6541
+ * (e.g., `taggedCbor()`, `name()`, etc.).
6542
+ *
6543
+ * @module envelope-pattern/parse/leaf/known-value-parser
6451
6544
  */
6452
- function parseGroup(lexer) {
6453
- const primary = parsePrimary(lexer);
6454
- if (!primary.ok) return primary;
6455
- const next = lexer.peekToken();
6456
- if (next === void 0) return primary;
6457
- const tokenType = next.token.type;
6458
- let quantifier;
6459
- if (tokenType === "RepeatZeroOrMore") {
6460
- lexer.next();
6461
- quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrMore(_bcts_dcbor_pattern.Reluctance.Greedy);
6462
- } else if (tokenType === "RepeatZeroOrMoreLazy") {
6463
- lexer.next();
6464
- quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrMore(_bcts_dcbor_pattern.Reluctance.Lazy);
6465
- } else if (tokenType === "RepeatZeroOrMorePossessive") {
6466
- lexer.next();
6467
- quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrMore(_bcts_dcbor_pattern.Reluctance.Possessive);
6468
- } else if (tokenType === "RepeatOneOrMore") {
6469
- lexer.next();
6470
- quantifier = _bcts_dcbor_pattern.Quantifier.oneOrMore(_bcts_dcbor_pattern.Reluctance.Greedy);
6471
- } else if (tokenType === "RepeatOneOrMoreLazy") {
6472
- lexer.next();
6473
- quantifier = _bcts_dcbor_pattern.Quantifier.oneOrMore(_bcts_dcbor_pattern.Reluctance.Lazy);
6474
- } else if (tokenType === "RepeatOneOrMorePossessive") {
6475
- lexer.next();
6476
- quantifier = _bcts_dcbor_pattern.Quantifier.oneOrMore(_bcts_dcbor_pattern.Reluctance.Possessive);
6477
- } else if (tokenType === "RepeatZeroOrOne") {
6478
- lexer.next();
6479
- quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrOne(_bcts_dcbor_pattern.Reluctance.Greedy);
6480
- } else if (tokenType === "RepeatZeroOrOneLazy") {
6481
- lexer.next();
6482
- quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrOne(_bcts_dcbor_pattern.Reluctance.Lazy);
6483
- } else if (tokenType === "RepeatZeroOrOnePossessive") {
6484
- lexer.next();
6485
- quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrOne(_bcts_dcbor_pattern.Reluctance.Possessive);
6486
- } else if (tokenType === "Range") {
6487
- lexer.next();
6488
- if (!next.token.value.ok) return err(next.token.value.error);
6489
- quantifier = next.token.value.value;
6490
- } else return primary;
6491
- return ok(repeat(primary.value, quantifier.min(), quantifier.max(), quantifier.reluctance()));
6492
- }
6493
6545
  /**
6494
- * Parse a primary expression (atoms and structure keywords).
6546
+ * Maximum value of a Rust `u64`. Used to reject literals that would
6547
+ * silently wrap or lose precision when constructing a `KnownValue`.
6495
6548
  */
6496
- function parsePrimary(lexer) {
6497
- const tokenResult = lexer.next();
6498
- if (tokenResult === void 0) return err(unexpectedEndOfInput());
6499
- const { token, span } = tokenResult;
6500
- switch (token.type) {
6501
- case "Search": return parseSearch(lexer);
6502
- case "Node": return parseNode(lexer);
6503
- case "Assertion": return parseAssertion(lexer);
6504
- case "AssertionPred": return parseAssertionPred(lexer);
6505
- case "AssertionObj": return parseAssertionObj(lexer);
6506
- case "Digest": return parseDigest(lexer);
6507
- case "Obj": return parseObject(lexer);
6508
- case "Obscured": return ok(obscured());
6509
- case "Elided": return ok(elided());
6510
- case "Encrypted": return ok(encrypted());
6511
- case "Compressed": return ok(compressed());
6512
- case "Pred": return parsePredicate(lexer);
6513
- case "Subject": return parseSubject(lexer);
6514
- case "Wrapped": return ok(wrapped());
6515
- case "Unwrap": return parseUnwrap(lexer);
6516
- case "Leaf": return ok(leaf());
6517
- case "GroupName": return parseCapture(lexer, token.name);
6518
- case "ParenOpen": return parseParenGroup(lexer);
6519
- case "Cbor": return parseCbor(lexer);
6520
- case "RepeatZeroOrMore": return ok(any());
6521
- case "BoolKeyword": return ok(anyBool());
6522
- case "BoolTrue": return ok(bool(true));
6523
- case "BoolFalse": return ok(bool(false));
6524
- case "NumberKeyword": return ok(anyNumber());
6525
- case "TextKeyword": return ok(anyText());
6526
- case "StringLiteral":
6527
- if (!token.value.ok) return err(token.value.error);
6528
- return ok(text(token.value.value));
6529
- case "UnsignedInteger":
6530
- if (!token.value.ok) return err(token.value.error);
6531
- return parseNumberRangeOrComparison(lexer, token.value.value);
6532
- case "Integer":
6533
- if (!token.value.ok) return err(token.value.error);
6534
- return parseNumberRangeOrComparison(lexer, token.value.value);
6535
- case "Float":
6536
- if (!token.value.ok) return err(token.value.error);
6537
- return parseNumberRangeOrComparison(lexer, token.value.value);
6538
- case "GreaterThanOrEqual": return parseComparisonNumber(lexer, ">=");
6539
- case "LessThanOrEqual": return parseComparisonNumber(lexer, "<=");
6540
- case "GreaterThan": return parseComparisonNumber(lexer, ">");
6541
- case "LessThan": return parseComparisonNumber(lexer, "<");
6542
- case "NaN": return ok(patternLeaf(leafNumber(NumberPattern.nan())));
6543
- case "Infinity": return ok(number(Infinity));
6544
- case "NegativeInfinity": return ok(number(-Infinity));
6545
- case "Regex":
6546
- if (!token.value.ok) return err(token.value.error);
6547
- try {
6548
- return ok(textRegex(new RegExp(token.value.value)));
6549
- } catch {
6550
- return err(invalidRegex(span));
6551
- }
6552
- case "BracketOpen": return parseArray(lexer);
6553
- case "ByteString": return ok(anyByteString());
6554
- case "HexPattern":
6555
- if (!token.value.ok) return err(token.value.error);
6556
- return ok(byteString(token.value.value));
6557
- case "HexBinaryRegex":
6558
- if (!token.value.ok) return err(token.value.error);
6559
- try {
6560
- return ok(patternLeaf(leafByteString(ByteStringPattern.regex(new RegExp(token.value.value)))));
6561
- } catch {
6562
- return err(invalidRegex(span));
6563
- }
6564
- case "DateKeyword": return ok(anyDate());
6565
- case "DatePattern":
6566
- if (!token.value.ok) return err(token.value.error);
6567
- return parseDateContent(token.value.value, span);
6568
- case "Tagged": return parseTag(lexer);
6569
- case "Known": return ok(anyKnownValue());
6570
- case "SingleQuotedPattern":
6571
- if (!token.value.ok) return err(token.value.error);
6572
- return parseKnownValueContent(token.value.value);
6573
- case "SingleQuotedRegex":
6574
- if (!token.value.ok) return err(token.value.error);
6575
- try {
6576
- return ok(patternLeaf(leafKnownValue(KnownValuePattern.regex(new RegExp(token.value.value)))));
6577
- } catch {
6578
- return err(invalidRegex(span));
6579
- }
6580
- case "Null": return ok(nullPattern());
6581
- case "And":
6582
- case "Or":
6583
- case "Not":
6584
- case "Traverse":
6585
- case "RepeatZeroOrMoreLazy":
6586
- case "RepeatZeroOrMorePossessive":
6587
- case "RepeatOneOrMore":
6588
- case "RepeatOneOrMoreLazy":
6589
- case "RepeatOneOrMorePossessive":
6590
- case "RepeatZeroOrOne":
6591
- case "RepeatZeroOrOneLazy":
6592
- case "RepeatZeroOrOnePossessive":
6593
- case "ParenClose":
6594
- case "BracketClose":
6595
- case "Comma":
6596
- case "Ellipsis":
6597
- case "Range":
6598
- case "Identifier": return err(unexpectedToken(token, span));
6599
- }
6600
- }
6549
+ const U64_MAX = 18446744073709551615n;
6601
6550
  /**
6602
- * Parse a parenthesized group expression.
6551
+ * Parse the inner contents of a `'…'` known-value pattern token.
6552
+ *
6553
+ * Mirrors the Rust dispatch
6554
+ * ```ignore
6555
+ * if let Ok(value) = content.parse::<u64>() {
6556
+ * Pattern::known_value(KnownValue::new(value))
6557
+ * } else {
6558
+ * Pattern::known_value_named(content)
6559
+ * }
6560
+ * ```
6561
+ * but uses BigInt parsing to preserve full `u64` range — the previous
6562
+ * `parseInt(...)` path silently truncated above `2^53-1`.
6603
6563
  */
6604
- function parseParenGroup(lexer) {
6605
- const inner = parseOr(lexer);
6606
- if (!inner.ok) return inner;
6607
- if (lexer.next()?.token.type !== "ParenClose") return err({
6608
- type: "ExpectedCloseParen",
6609
- span: lexer.span()
6610
- });
6611
- return ok(group(inner.value));
6564
+ function parseKnownValueContent(content) {
6565
+ if (isU64Literal(content)) return ok(knownValue(new _bcts_known_values.KnownValue(BigInt(content))));
6566
+ return ok(patternLeaf(leafKnownValue(KnownValuePattern.named(content))));
6612
6567
  }
6613
- /**
6614
- * Parse a capture group: @name pattern
6615
- */
6616
- function parseCapture(lexer, name) {
6617
- const inner = parseGroup(lexer);
6618
- if (!inner.ok) return inner;
6619
- return ok(capture(name, inner.value));
6568
+ function isU64Literal(content) {
6569
+ if (content.length === 0) return false;
6570
+ for (let i = 0; i < content.length; i++) {
6571
+ const c = content.charCodeAt(i);
6572
+ if (c < 48 || c > 57) return false;
6573
+ }
6574
+ try {
6575
+ const value = BigInt(content);
6576
+ return value >= 0n && value <= U64_MAX;
6577
+ } catch {
6578
+ return false;
6579
+ }
6620
6580
  }
6581
+ //#endregion
6582
+ //#region src/parse/leaf/number-parser.ts
6621
6583
  /**
6622
- * Parse a search pattern: search(pattern)
6584
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6585
+ * Copyright © 2025-2026 Parity Technologies
6586
+ *
6587
+ * Number parsers — port of `bc-envelope-pattern-rust` `parse/leaf/number_parser.rs`.
6588
+ *
6589
+ * @module envelope-pattern/parse/leaf/number-parser
6623
6590
  */
6624
- function parseSearch(lexer) {
6625
- if (lexer.next()?.token.type !== "ParenOpen") return err({
6626
- type: "ExpectedOpenParen",
6627
- span: lexer.span()
6628
- });
6629
- const inner = parseOr(lexer);
6630
- if (!inner.ok) return inner;
6631
- if (lexer.next()?.token.type !== "ParenClose") return err({
6632
- type: "ExpectedCloseParen",
6633
- span: lexer.span()
6634
- });
6635
- return ok(search(inner.value));
6636
- }
6637
6591
  /**
6638
- * Parse number with possible range or comparison.
6592
+ * Parses an optional `...end` suffix following an already-consumed number,
6593
+ * mirroring Rust `parse_number_range_or_comparison`.
6639
6594
  */
6640
6595
  function parseNumberRangeOrComparison(lexer, firstValue) {
6641
6596
  const next = lexer.peekToken();
@@ -6645,10 +6600,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6645
6600
  const endToken = lexer.next();
6646
6601
  if (endToken === void 0) return err(unexpectedEndOfInput());
6647
6602
  let endValue;
6648
- if (endToken.token.type === "UnsignedInteger" || endToken.token.type === "Integer") {
6649
- if (!endToken.token.value.ok) return err(endToken.token.value.error);
6650
- endValue = endToken.token.value.value;
6651
- } else if (endToken.token.type === "Float") {
6603
+ if (endToken.token.type === "UnsignedInteger" || endToken.token.type === "Integer" || endToken.token.type === "Float") {
6652
6604
  if (!endToken.token.value.ok) return err(endToken.token.value.error);
6653
6605
  endValue = endToken.token.value.value;
6654
6606
  } else return err(unexpectedToken(endToken.token, endToken.span));
@@ -6657,16 +6609,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6657
6609
  return ok(number(firstValue));
6658
6610
  }
6659
6611
  /**
6660
- * Parse comparison number: >=n, <=n, >n, <n
6612
+ * Parses a number following a comparison operator, mirroring Rust
6613
+ * `parse_comparison_number`.
6661
6614
  */
6662
6615
  function parseComparisonNumber(lexer, op) {
6663
6616
  const numToken = lexer.next();
6664
6617
  if (numToken === void 0) return err(unexpectedEndOfInput());
6665
6618
  let value;
6666
- if (numToken.token.type === "UnsignedInteger" || numToken.token.type === "Integer") {
6667
- if (!numToken.token.value.ok) return err(numToken.token.value.error);
6668
- value = numToken.token.value.value;
6669
- } else if (numToken.token.type === "Float") {
6619
+ if (numToken.token.type === "UnsignedInteger" || numToken.token.type === "Integer" || numToken.token.type === "Float") {
6670
6620
  if (!numToken.token.value.ok) return err(numToken.token.value.error);
6671
6621
  value = numToken.token.value.value;
6672
6622
  } else return err(unexpectedToken(numToken.token, numToken.span));
@@ -6675,558 +6625,1072 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6675
6625
  case "<=": return ok(patternLeaf(leafNumber(NumberPattern.lessThanOrEqual(value))));
6676
6626
  case ">": return ok(numberGreaterThan(value));
6677
6627
  case "<": return ok(numberLessThan(value));
6678
- default: return ok(number(value));
6679
6628
  }
6680
6629
  }
6630
+ //#endregion
6631
+ //#region src/parse/leaf/tag-parser.ts
6681
6632
  /**
6682
- * Parse an array pattern.
6633
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6634
+ * Copyright © 2025-2026 Parity Technologies
6635
+ *
6636
+ * Tag parser — port of `bc-envelope-pattern-rust`
6637
+ * `parse/leaf/tag_parser.rs`.
6638
+ *
6639
+ * Mirrors the Rust dispatch exactly: lookahead for `(`; if absent, return
6640
+ * the bare `any_tag()`. Otherwise build a synthetic dcbor-pattern
6641
+ * expression `tagged(<inner>)`, parse it via `@bcts/dcbor-pattern`, and
6642
+ * extract the resulting `TaggedPattern` to wrap as an envelope-pattern
6643
+ * leaf. This keeps the **full** tag selector (number, name, regex)
6644
+ * intact — the previous port discarded the tag value entirely.
6645
+ *
6646
+ * @module envelope-pattern/parse/leaf/tag-parser
6683
6647
  */
6684
- function parseArray(lexer) {
6685
- const first = lexer.peekToken();
6686
- if (first === void 0) return err(unexpectedEndOfInput());
6687
- if (first.token.type === "BracketClose") {
6688
- lexer.next();
6689
- return ok(patternLeaf(leafArray(ArrayPattern.count(0))));
6690
- }
6691
- if (first.token.type === "RepeatZeroOrMore") {
6692
- lexer.next();
6693
- if (lexer.next()?.token.type !== "BracketClose") return err({
6694
- type: "ExpectedCloseBracket",
6695
- span: lexer.span()
6696
- });
6697
- return ok(anyArray());
6698
- }
6699
- const patterns = [];
6700
- while (true) {
6701
- const next = lexer.peekToken();
6702
- if (next === void 0) return err(unexpectedEndOfInput());
6703
- if (next.token.type === "BracketClose") {
6704
- lexer.next();
6705
- break;
6706
- }
6707
- const pattern = parseOr(lexer);
6708
- if (!pattern.ok) return pattern;
6709
- patterns.push(pattern.value);
6710
- const afterPattern = lexer.peekToken();
6711
- if (afterPattern === void 0) return err(unexpectedEndOfInput());
6712
- if (afterPattern.token.type === "Comma") lexer.next();
6713
- else if (afterPattern.token.type !== "BracketClose") return err(unexpectedToken(afterPattern.token, afterPattern.span));
6714
- }
6715
- if (patterns.length === 0) return ok(patternLeaf(leafArray(ArrayPattern.count(0))));
6716
- return ok(patternLeaf(leafArray(ArrayPattern.withPatterns(patterns))));
6717
- }
6718
6648
  /**
6719
- * Parse a tag pattern.
6649
+ * Parse `tagged` and `tagged(...)` patterns.
6720
6650
  */
6721
6651
  function parseTag(lexer) {
6722
- if (lexer.next()?.token.type !== "ParenOpen") return ok(anyTag());
6723
- const tagToken = lexer.next();
6724
- if (tagToken === void 0) return err(unexpectedEndOfInput());
6725
- if (tagToken.token.type !== "UnsignedInteger") return err(unexpectedToken(tagToken.token, tagToken.span));
6726
- if (!tagToken.token.value.ok) return err(tagToken.token.value.error);
6727
- if (lexer.next()?.token.type !== "ParenClose") return err({
6728
- type: "ExpectedCloseParen",
6729
- span: lexer.span()
6730
- });
6731
- return ok(anyTag());
6732
- }
6733
- /**
6734
- * Parse date content from date'...' pattern.
6735
- */
6736
- function parseDateContent(content, span) {
6737
- if (content.startsWith("/") && content.endsWith("/")) {
6738
- const regexStr = content.slice(1, -1);
6739
- try {
6740
- return ok(dateRegex(new RegExp(regexStr)));
6741
- } catch {
6742
- return err(invalidRegex(span));
6652
+ if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(anyTag());
6653
+ lexer.next();
6654
+ const remainder = lexer.remainder();
6655
+ const closeIdx = findMatchingCloseParen(remainder);
6656
+ if (closeIdx === void 0) return err(expectedCloseParen(lexer.span()));
6657
+ const innerContent = remainder.slice(0, closeIdx);
6658
+ const dcborResult = (0, _bcts_dcbor_pattern.parse)(`tagged(${innerContent})`);
6659
+ if (dcborResult.ok) {
6660
+ const dcborPattern = dcborResult.value;
6661
+ if (dcborPattern.kind === "Structure" && dcborPattern.pattern.type === "Tagged") {
6662
+ lexer.bump(closeIdx);
6663
+ const close = lexer.next();
6664
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
6665
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
6666
+ return ok(patternLeaf(leafTag(TaggedPattern.fromDcborPattern(dcborPattern.pattern.pattern))));
6743
6667
  }
6744
6668
  }
6745
- const rangeIdx = content.indexOf("...");
6746
- if (rangeIdx !== -1) {
6747
- const left = content.slice(0, rangeIdx).trim();
6748
- const right = content.slice(rangeIdx + 3).trim();
6749
- if (left.length === 0 && right.length > 0) {
6750
- const parsed = Date.parse(right);
6751
- if (isNaN(parsed)) return err({
6752
- type: "InvalidDateFormat",
6753
- span
6754
- });
6755
- return ok(dateLatest(_bcts_dcbor.CborDate.fromDatetime(new Date(parsed))));
6756
- }
6757
- if (left.length > 0 && right.length === 0) {
6758
- const parsed = Date.parse(left);
6759
- if (isNaN(parsed)) return err({
6760
- type: "InvalidDateFormat",
6761
- span
6762
- });
6763
- return ok(dateEarliest(_bcts_dcbor.CborDate.fromDatetime(new Date(parsed))));
6669
+ const fallback = parseTagInner(innerContent);
6670
+ if (!fallback.ok) return fallback;
6671
+ lexer.bump(closeIdx);
6672
+ const close = lexer.next();
6673
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
6674
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
6675
+ return ok(fallback.value);
6676
+ }
6677
+ /**
6678
+ * Locate the index of the closing `)` matching the `(` that has already
6679
+ * been consumed by `parseTag`. Mirrors Rust `find_matching_paren`.
6680
+ */
6681
+ function findMatchingCloseParen(src) {
6682
+ let depth = 0;
6683
+ for (let i = 0; i < src.length; i++) {
6684
+ const ch = src.charCodeAt(i);
6685
+ if (ch === 40) depth += 1;
6686
+ else if (ch === 41) {
6687
+ if (depth === 0) return i;
6688
+ depth -= 1;
6764
6689
  }
6765
- if (left.length > 0 && right.length > 0) {
6766
- const parsedStart = Date.parse(left);
6767
- const parsedEnd = Date.parse(right);
6768
- if (isNaN(parsedStart) || isNaN(parsedEnd)) return err({
6769
- type: "InvalidDateFormat",
6770
- span
6771
- });
6772
- return ok(dateRange(_bcts_dcbor.CborDate.fromDatetime(new Date(parsedStart)), _bcts_dcbor.CborDate.fromDatetime(new Date(parsedEnd))));
6773
- }
6774
- return err({
6775
- type: "InvalidDateFormat",
6776
- span
6777
- });
6778
6690
  }
6779
- const parsed = Date.parse(content);
6780
- if (isNaN(parsed)) return err({
6781
- type: "InvalidDateFormat",
6782
- span
6783
- });
6784
- return ok(date(_bcts_dcbor.CborDate.fromDatetime(new Date(parsed))));
6785
6691
  }
6786
6692
  /**
6787
- * Parse known value content from '...' pattern.
6693
+ * Fallback for `tagged(N)` and `tagged(name)` when the full delegation
6694
+ * to dcbor-pattern fails. Mirrors Rust `parse_tag_inner`.
6788
6695
  */
6789
- function parseKnownValueContent(content) {
6790
- const numValue = parseInt(content, 10);
6791
- if (!isNaN(numValue)) return ok(knownValue({ value: () => BigInt(numValue) }));
6792
- return ok(patternLeaf(leafKnownValue(KnownValuePattern.named(content))));
6696
+ function parseTagInner(src) {
6697
+ const trimmed = src.trim();
6698
+ if (trimmed.length === 0) return err(unexpectedEndOfInput());
6699
+ if (trimmed.startsWith("/")) return err(unexpectedEndOfInput());
6700
+ if (/^\d+$/.test(trimmed)) try {
6701
+ const dcborResult = (0, _bcts_dcbor_pattern.parse)(`tagged(${trimmed})`);
6702
+ if (dcborResult.ok && dcborResult.value.kind === "Structure" && dcborResult.value.pattern.type === "Tagged") return ok(patternLeaf(leafTag(TaggedPattern.fromDcborPattern(dcborResult.value.pattern.pattern))));
6703
+ } catch {}
6704
+ const dcborResult = (0, _bcts_dcbor_pattern.parse)(`tagged(${trimmed})`);
6705
+ if (dcborResult.ok && dcborResult.value.kind === "Structure" && dcborResult.value.pattern.type === "Tagged") return ok(patternLeaf(leafTag(TaggedPattern.fromDcborPattern(dcborResult.value.pattern.pattern))));
6706
+ return err(unexpectedEndOfInput());
6793
6707
  }
6708
+ //#endregion
6709
+ //#region src/parse/structure/assertion-parser.ts
6794
6710
  /**
6795
- * Parse CBOR pattern.
6711
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6712
+ * Copyright © 2025-2026 Parity Technologies
6796
6713
  *
6797
- * Matches Rust parse_cbor: tries dcbor-pattern regex first (/keyword/),
6798
- * then CBOR diagnostic notation via parseDcborItemPartial, then falls
6799
- * back to parseOr for envelope pattern expressions.
6714
+ * Assertion parser port of `bc-envelope-pattern-rust`
6715
+ * `parse/structure/assertion_parser.rs`.
6716
+ *
6717
+ * Note: Rust's `parse_assertion` ignores its lexer entirely and always
6718
+ * returns `Pattern::any_assertion()`. There is intentionally **no**
6719
+ * `assert(pred, obj)` syntax — predicate/object filters are written via
6720
+ * the dedicated `assertpred(...)` / `assertobj(...)` keywords.
6721
+ *
6722
+ * @module envelope-pattern/parse/structure/assertion-parser
6800
6723
  */
6801
- function parseCbor(lexer) {
6802
- if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(anyCbor());
6803
- lexer.next();
6804
- if (lexer.peek() === "/") {
6805
- const regexTokenResult = lexer.next();
6806
- if (regexTokenResult?.token.type === "Regex") {
6807
- const regexToken = regexTokenResult.token;
6808
- if (!regexToken.value.ok) return err(regexToken.value.error);
6809
- const keyword = regexToken.value.value;
6810
- const dcborResult = (0, _bcts_dcbor_pattern.parse)(keyword);
6811
- if (!dcborResult.ok) return err(unexpectedToken(regexToken, regexTokenResult.span));
6812
- if (lexer.next()?.token.type !== "ParenClose") return err({
6813
- type: "ExpectedCloseParen",
6814
- span: lexer.span()
6815
- });
6816
- return ok(cborPattern(dcborResult.value));
6817
- }
6818
- }
6819
- const cborResult = (0, _bcts_dcbor_parse.parseDcborItemPartial)(lexer.remainder());
6820
- if (cborResult.ok) {
6821
- const [cborData, consumed] = cborResult.value;
6822
- lexer.bump(consumed);
6823
- while (lexer.peek() === " " || lexer.peek() === " " || lexer.peek() === "\n") lexer.bump(1);
6824
- if (lexer.next()?.token.type !== "ParenClose") return err({
6825
- type: "ExpectedCloseParen",
6826
- span: lexer.span()
6827
- });
6828
- return ok(cborValue(cborData));
6829
- }
6830
- const inner = parseOr(lexer);
6831
- if (!inner.ok) return inner;
6832
- if (lexer.next()?.token.type !== "ParenClose") return err({
6833
- type: "ExpectedCloseParen",
6834
- span: lexer.span()
6835
- });
6836
- return inner;
6724
+ function parseAssertion(_lexer) {
6725
+ return ok(anyAssertion());
6837
6726
  }
6838
- function parseNode(lexer) {
6839
- if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(anyNode());
6840
- lexer.next();
6841
- const afterParen = lexer.peekToken();
6842
- if (afterParen?.token.type === "Range") {
6843
- lexer.next();
6844
- const rangeToken = afterParen.token;
6845
- if (!rangeToken.value.ok) return err(rangeToken.value.error);
6846
- const interval = rangeToken.value.value.interval();
6847
- if (lexer.next()?.token.type !== "ParenClose") return err({
6848
- type: "ExpectedCloseParen",
6849
- span: lexer.span()
6850
- });
6851
- return ok(patternStructure(structureNode(NodePattern.fromInterval(interval))));
6852
- }
6727
+ //#endregion
6728
+ //#region src/parse/structure/assertion-obj-parser.ts
6729
+ /**
6730
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6731
+ * Copyright © 2025-2026 Parity Technologies
6732
+ *
6733
+ * Assertion-object parser — port of
6734
+ * `bc-envelope-pattern-rust/src/parse/structure/assertion_obj_parser.rs`.
6735
+ *
6736
+ * Requires `assertobj(<pattern>)`. The bare `assertobj` keyword is a
6737
+ * syntax error in Rust; we now mirror that behaviour.
6738
+ *
6739
+ * @module envelope-pattern/parse/structure/assertion-obj-parser
6740
+ */
6741
+ function parseAssertionObj(lexer) {
6742
+ const open = lexer.next();
6743
+ if (open === void 0) return err(unexpectedEndOfInput());
6744
+ if (open.token.type !== "ParenOpen") return err(unexpectedToken(open.token, open.span));
6853
6745
  const inner = parseOr(lexer);
6854
6746
  if (!inner.ok) return inner;
6855
- if (lexer.next()?.token.type !== "ParenClose") return err({
6856
- type: "ExpectedCloseParen",
6857
- span: lexer.span()
6858
- });
6859
- return ok(patternStructure(structureNode(NodePattern.withSubject(inner.value))));
6860
- }
6861
- function parseAssertion(lexer) {
6862
- if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(anyAssertion());
6863
- lexer.next();
6864
- const pred = parseOr(lexer);
6865
- if (!pred.ok) return pred;
6866
- const comma = lexer.next();
6867
- if (comma?.token.type !== "Comma") return err(unexpectedToken(comma?.token ?? { type: "Null" }, comma?.span ?? lexer.span()));
6868
- const obj = parseOr(lexer);
6869
- if (!obj.ok) return obj;
6870
- if (lexer.next()?.token.type !== "ParenClose") return err({
6871
- type: "ExpectedCloseParen",
6872
- span: lexer.span()
6873
- });
6874
- return ok(patternStructure(structureAssertions(AssertionsPattern.withBoth(pred.value, obj.value))));
6747
+ const close = lexer.next();
6748
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
6749
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
6750
+ return ok(assertionWithObject(inner.value));
6875
6751
  }
6752
+ //#endregion
6753
+ //#region src/parse/structure/assertion-pred-parser.ts
6754
+ /**
6755
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6756
+ * Copyright © 2025-2026 Parity Technologies
6757
+ *
6758
+ * Assertion-predicate parser — port of
6759
+ * `bc-envelope-pattern-rust/src/parse/structure/assertion_pred_parser.rs`.
6760
+ *
6761
+ * Requires `assertpred(<pattern>)`. The bare `assertpred` keyword is a
6762
+ * syntax error in Rust (it errors on `UnexpectedEndOfInput` /
6763
+ * `UnexpectedToken`); we now mirror that behaviour.
6764
+ *
6765
+ * @module envelope-pattern/parse/structure/assertion-pred-parser
6766
+ */
6876
6767
  function parseAssertionPred(lexer) {
6877
- if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(anyAssertion());
6878
- lexer.next();
6768
+ const open = lexer.next();
6769
+ if (open === void 0) return err(unexpectedEndOfInput());
6770
+ if (open.token.type !== "ParenOpen") return err(unexpectedToken(open.token, open.span));
6879
6771
  const inner = parseOr(lexer);
6880
6772
  if (!inner.ok) return inner;
6881
- if (lexer.next()?.token.type !== "ParenClose") return err({
6882
- type: "ExpectedCloseParen",
6883
- span: lexer.span()
6884
- });
6773
+ const close = lexer.next();
6774
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
6775
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
6885
6776
  return ok(assertionWithPredicate(inner.value));
6886
6777
  }
6887
- function parseAssertionObj(lexer) {
6888
- if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(anyAssertion());
6889
- lexer.next();
6890
- const inner = parseOr(lexer);
6891
- if (!inner.ok) return inner;
6892
- if (lexer.next()?.token.type !== "ParenClose") return err({
6893
- type: "ExpectedCloseParen",
6894
- span: lexer.span()
6895
- });
6896
- return ok(assertionWithObject(inner.value));
6778
+ //#endregion
6779
+ //#region src/parse/structure/compressed-parser.ts
6780
+ /**
6781
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6782
+ * Copyright © 2025-2026 Parity Technologies
6783
+ *
6784
+ * Compressed parser — port of `bc-envelope-pattern-rust`
6785
+ * `parse/structure/compressed_parser.rs`.
6786
+ *
6787
+ * @module envelope-pattern/parse/structure/compressed-parser
6788
+ */
6789
+ function parseCompressed(_lexer) {
6790
+ return ok(compressed());
6897
6791
  }
6792
+ //#endregion
6793
+ //#region src/parse/structure/digest-parser.ts
6794
+ /**
6795
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6796
+ * Copyright © 2025-2026 Parity Technologies
6797
+ *
6798
+ * Digest parser — port of `bc-envelope-pattern-rust`
6799
+ * `parse/structure/digest_parser.rs`.
6800
+ *
6801
+ * Mirrors Rust exactly:
6802
+ *
6803
+ * - Requires `digest(...)` — bare `digest` is an `UnexpectedEndOfInput`
6804
+ * error (the previous TS port silently returned `digest(any)`).
6805
+ * - Inside the parens, accepts either a UR string (`ur:digest/...`,
6806
+ * parsed via `Digest.fromURString`) or a hex byte prefix.
6807
+ * - Hex prefixes must have even length and not exceed `Digest.DIGEST_SIZE`
6808
+ * bytes; otherwise the parser surfaces `InvalidHexString`.
6809
+ *
6810
+ * @module envelope-pattern/parse/structure/digest-parser
6811
+ */
6812
+ const DIGEST_SIZE = _bcts_envelope.Digest.DIGEST_SIZE;
6898
6813
  function parseDigest(lexer) {
6899
- if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(patternStructure(structureDigest(DigestPattern.any())));
6900
- lexer.next();
6901
- const digestToken = lexer.next();
6902
- if (digestToken === void 0) return err(unexpectedEndOfInput());
6903
- if (digestToken.token.type === "HexPattern") {
6904
- if (!digestToken.token.value.ok) return err(digestToken.token.value.error);
6905
- if (lexer.next()?.token.type !== "ParenClose") return err({
6906
- type: "ExpectedCloseParen",
6907
- span: lexer.span()
6908
- });
6909
- return ok(digestPrefix(digestToken.token.value.value));
6814
+ const open = lexer.next();
6815
+ if (open === void 0) return err(unexpectedEndOfInput());
6816
+ if (open.token.type !== "ParenOpen") return err(unexpectedToken(open.token, open.span));
6817
+ const innerResult = parseDigestInner(lexer.remainder(), lexer.position);
6818
+ if (!innerResult.ok) return innerResult;
6819
+ const [pattern, consumed] = innerResult.value;
6820
+ lexer.bump(consumed);
6821
+ const close = lexer.next();
6822
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
6823
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
6824
+ return ok(pattern);
6825
+ }
6826
+ function parseDigestInner(src, basePos) {
6827
+ let pos = 0;
6828
+ pos = skipWs(src, pos);
6829
+ if (src.startsWith("ur:", pos)) {
6830
+ const start = pos;
6831
+ while (pos < src.length && src[pos] !== ")") pos += 1;
6832
+ const ur = src.slice(start, pos).trimEnd();
6833
+ let parsed;
6834
+ try {
6835
+ parsed = _bcts_envelope.Digest.fromURString(ur);
6836
+ } catch {
6837
+ return err(invalidUr(ur, {
6838
+ start: basePos + start,
6839
+ end: basePos + pos
6840
+ }));
6841
+ }
6842
+ pos = skipWs(src, pos);
6843
+ return ok([digest(parsed), pos]);
6844
+ }
6845
+ const start = pos;
6846
+ while (pos < src.length && isAsciiHexDigit(src.charCodeAt(pos))) pos += 1;
6847
+ if (pos === start) return err(invalidHexString({
6848
+ start: basePos + pos,
6849
+ end: basePos + pos
6850
+ }));
6851
+ const hexStr = src.slice(start, pos);
6852
+ if (hexStr.length % 2 !== 0) return err(invalidHexString({
6853
+ start: basePos + pos,
6854
+ end: basePos + pos
6855
+ }));
6856
+ const bytes = decodeHex(hexStr);
6857
+ if (bytes === void 0) return err(invalidHexString({
6858
+ start: basePos + pos,
6859
+ end: basePos + pos
6860
+ }));
6861
+ if (bytes.length > DIGEST_SIZE) return err(invalidHexString({
6862
+ start: basePos + pos,
6863
+ end: basePos + pos
6864
+ }));
6865
+ pos = skipWs(src, pos);
6866
+ return ok([digestPrefix(bytes), pos]);
6867
+ }
6868
+ function skipWs(src, pos) {
6869
+ while (pos < src.length) {
6870
+ const ch = src[pos];
6871
+ if (ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f") pos += 1;
6872
+ else break;
6910
6873
  }
6911
- if (digestToken.token.type === "Identifier") {
6912
- const hexStr = digestToken.token.value;
6913
- if (hexStr.length === 0 || hexStr.length % 2 !== 0 || !/^[0-9a-fA-F]+$/.test(hexStr)) return err({
6914
- type: "InvalidHexString",
6915
- span: digestToken.span
6916
- });
6917
- const bytes = new Uint8Array(hexStr.length / 2);
6918
- for (let i = 0; i < hexStr.length; i += 2) bytes[i / 2] = Number.parseInt(hexStr.slice(i, i + 2), 16);
6919
- if (lexer.next()?.token.type !== "ParenClose") return err({
6920
- type: "ExpectedCloseParen",
6921
- span: lexer.span()
6922
- });
6923
- return ok(digestPrefix(bytes));
6874
+ return pos;
6875
+ }
6876
+ function isAsciiHexDigit(c) {
6877
+ return c >= 48 && c <= 57 || c >= 65 && c <= 70 || c >= 97 && c <= 102;
6878
+ }
6879
+ function decodeHex(hex) {
6880
+ if (hex.length % 2 !== 0) return void 0;
6881
+ const out = new Uint8Array(hex.length / 2);
6882
+ for (let i = 0; i < hex.length; i += 2) {
6883
+ const value = Number.parseInt(hex.slice(i, i + 2), 16);
6884
+ if (Number.isNaN(value)) return void 0;
6885
+ out[i / 2] = value;
6924
6886
  }
6925
- return err(unexpectedToken(digestToken.token, digestToken.span));
6887
+ return out;
6888
+ }
6889
+ //#endregion
6890
+ //#region src/parse/structure/elided-parser.ts
6891
+ /**
6892
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6893
+ * Copyright © 2025-2026 Parity Technologies
6894
+ *
6895
+ * Elided parser — port of `bc-envelope-pattern-rust`
6896
+ * `parse/structure/elided_parser.rs`.
6897
+ *
6898
+ * @module envelope-pattern/parse/structure/elided-parser
6899
+ */
6900
+ function parseElided(_lexer) {
6901
+ return ok(elided());
6902
+ }
6903
+ //#endregion
6904
+ //#region src/parse/structure/encrypted-parser.ts
6905
+ /**
6906
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6907
+ * Copyright © 2025-2026 Parity Technologies
6908
+ *
6909
+ * Encrypted parser — port of `bc-envelope-pattern-rust`
6910
+ * `parse/structure/encrypted_parser.rs`.
6911
+ *
6912
+ * @module envelope-pattern/parse/structure/encrypted-parser
6913
+ */
6914
+ function parseEncrypted(_lexer) {
6915
+ return ok(encrypted());
6926
6916
  }
6917
+ //#endregion
6918
+ //#region src/parse/structure/node-parser.ts
6919
+ /**
6920
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6921
+ * Copyright © 2025-2026 Parity Technologies
6922
+ *
6923
+ * Node parser — port of `bc-envelope-pattern-rust`
6924
+ * `parse/structure/node_parser.rs`.
6925
+ *
6926
+ * Mirrors Rust:
6927
+ * - Bare `node` → `any_node()`.
6928
+ * - `node({n})` / `node({n,m})` / `node({n,})` → `node_with_assertions_range`.
6929
+ * - Anything else inside the parens (e.g. `node(text)`) is a syntax error
6930
+ * in Rust; the previous TS port silently produced an always-matching
6931
+ * `WithSubject` node, which we have removed.
6932
+ *
6933
+ * @module envelope-pattern/parse/structure/node-parser
6934
+ */
6935
+ function parseNode(lexer) {
6936
+ if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(anyNode());
6937
+ lexer.next();
6938
+ const inner = lexer.next();
6939
+ if (inner === void 0) return err(unexpectedEndOfInput());
6940
+ if (inner.token.type !== "Range") return err(unexpectedToken(inner.token, inner.span));
6941
+ if (!inner.token.value.ok) return err(inner.token.value.error);
6942
+ const interval = inner.token.value.value.interval();
6943
+ const close = lexer.next();
6944
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
6945
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
6946
+ return ok(patternStructure(structureNode(NodePattern.fromInterval(interval))));
6947
+ }
6948
+ //#endregion
6949
+ //#region src/parse/structure/object-parser.ts
6950
+ /**
6951
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6952
+ * Copyright © 2025-2026 Parity Technologies
6953
+ *
6954
+ * Object parser — port of `bc-envelope-pattern-rust`
6955
+ * `parse/structure/object_parser.rs`.
6956
+ *
6957
+ * @module envelope-pattern/parse/structure/object-parser
6958
+ */
6927
6959
  function parseObject(lexer) {
6928
6960
  if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(anyObject());
6929
6961
  lexer.next();
6930
6962
  const inner = parseOr(lexer);
6931
6963
  if (!inner.ok) return inner;
6932
- if (lexer.next()?.token.type !== "ParenClose") return err({
6933
- type: "ExpectedCloseParen",
6934
- span: lexer.span()
6935
- });
6964
+ const close = lexer.next();
6965
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
6966
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
6936
6967
  return ok(object(inner.value));
6937
6968
  }
6969
+ //#endregion
6970
+ //#region src/parse/structure/obscured-parser.ts
6971
+ /**
6972
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6973
+ * Copyright © 2025-2026 Parity Technologies
6974
+ *
6975
+ * Obscured parser — port of `bc-envelope-pattern-rust`
6976
+ * `parse/structure/obscured_parser.rs`.
6977
+ *
6978
+ * @module envelope-pattern/parse/structure/obscured-parser
6979
+ */
6980
+ function parseObscured(_lexer) {
6981
+ return ok(obscured());
6982
+ }
6983
+ //#endregion
6984
+ //#region src/parse/structure/predicate-parser.ts
6985
+ /**
6986
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6987
+ * Copyright © 2025-2026 Parity Technologies
6988
+ *
6989
+ * Predicate parser — port of `bc-envelope-pattern-rust`
6990
+ * `parse/structure/predicate_parser.rs`.
6991
+ *
6992
+ * @module envelope-pattern/parse/structure/predicate-parser
6993
+ */
6938
6994
  function parsePredicate(lexer) {
6939
6995
  if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(anyPredicate());
6940
6996
  lexer.next();
6941
6997
  const inner = parseOr(lexer);
6942
6998
  if (!inner.ok) return inner;
6943
- if (lexer.next()?.token.type !== "ParenClose") return err({
6944
- type: "ExpectedCloseParen",
6945
- span: lexer.span()
6946
- });
6999
+ const close = lexer.next();
7000
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
7001
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
6947
7002
  return ok(predicate(inner.value));
6948
7003
  }
7004
+ //#endregion
7005
+ //#region src/parse/structure/subject-parser.ts
7006
+ /**
7007
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7008
+ * Copyright © 2025-2026 Parity Technologies
7009
+ *
7010
+ * Subject parser — port of `bc-envelope-pattern-rust`
7011
+ * `parse/structure/subject_parser.rs`.
7012
+ *
7013
+ * @module envelope-pattern/parse/structure/subject-parser
7014
+ */
6949
7015
  function parseSubject(lexer) {
6950
7016
  if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(anySubject());
6951
7017
  lexer.next();
6952
7018
  const inner = parseOr(lexer);
6953
7019
  if (!inner.ok) return inner;
6954
- if (lexer.next()?.token.type !== "ParenClose") return err({
6955
- type: "ExpectedCloseParen",
6956
- span: lexer.span()
6957
- });
7020
+ const close = lexer.next();
7021
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
7022
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
6958
7023
  return ok(subject(inner.value));
6959
7024
  }
7025
+ //#endregion
7026
+ //#region src/parse/structure/wrapped-parser.ts
7027
+ /**
7028
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7029
+ * Copyright © 2025-2026 Parity Technologies
7030
+ *
7031
+ * Wrapped/unwrap parser — port of `bc-envelope-pattern-rust`
7032
+ * `parse/structure/wrapped_parser.rs`.
7033
+ *
7034
+ * @module envelope-pattern/parse/structure/wrapped-parser
7035
+ */
7036
+ function parseWrapped(_lexer) {
7037
+ return ok(wrapped());
7038
+ }
6960
7039
  function parseUnwrap(lexer) {
6961
7040
  if (lexer.peekToken()?.token.type !== "ParenOpen") return ok(unwrapEnvelope());
6962
7041
  lexer.next();
6963
7042
  const inner = parseOr(lexer);
6964
7043
  if (!inner.ok) return inner;
6965
- if (lexer.next()?.token.type !== "ParenClose") return err({
6966
- type: "ExpectedCloseParen",
6967
- span: lexer.span()
6968
- });
7044
+ const close = lexer.next();
7045
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
7046
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
6969
7047
  return ok(unwrapMatching(inner.value));
6970
7048
  }
6971
-
6972
- //#endregion
6973
- //#region src/index.ts
6974
- /**
7049
+ //#endregion
7050
+ //#region src/parse/meta/capture-parser.ts
7051
+ /**
7052
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7053
+ * Copyright © 2025-2026 Parity Technologies
7054
+ *
7055
+ * Capture parser — port of `bc-envelope-pattern-rust`
7056
+ * `parse/meta/capture_parser.rs`.
7057
+ *
7058
+ * The `@name(...)` form requires explicit parentheses. Mirrors Rust
7059
+ * exactly:
7060
+ * ```ignore
7061
+ * @name ( expr )
7062
+ * ```
7063
+ * The previous TS port called `parse_group` (primary + quantifier), which
7064
+ * wrapped the inner expression in a redundant `GroupPattern` and accepted
7065
+ * the bare `@name p` form that Rust rejects.
7066
+ *
7067
+ * @module envelope-pattern/parse/meta/capture-parser
7068
+ */
7069
+ function parseCapture(lexer, name) {
7070
+ const open = lexer.next();
7071
+ if (open === void 0) return err(unexpectedEndOfInput());
7072
+ if (open.token.type !== "ParenOpen") return err(unexpectedToken(open.token, open.span));
7073
+ const inner = parseOr(lexer);
7074
+ if (!inner.ok) return inner;
7075
+ const close = lexer.next();
7076
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
7077
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
7078
+ return ok(capture(name, inner.value));
7079
+ }
7080
+ //#endregion
7081
+ //#region src/parse/meta/group-parser.ts
7082
+ /**
7083
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7084
+ * Copyright © 2025-2026 Parity Technologies
7085
+ *
7086
+ * Group parser — port of `bc-envelope-pattern-rust`
7087
+ * `parse/meta/group_parser.rs`.
7088
+ *
7089
+ * Called from `parse_primary` after the opening `(` has been consumed.
7090
+ *
7091
+ * Mirrors Rust exactly:
7092
+ *
7093
+ * - Parse the inner expression with `parse_or`.
7094
+ * - Expect `)`. If missing, surface `ExpectedCloseParen`.
7095
+ * - Lookahead **once** for a quantifier suffix. If present, consume it
7096
+ * and wrap as `Pattern::repeat(inner, …)`. Otherwise return the inner
7097
+ * expression unchanged.
7098
+ *
7099
+ * The previous TS port wrapped every parenthesised expression in a
7100
+ * dedicated `GroupPattern` and applied quantifiers to bare primaries —
7101
+ * both broke `format(parse(s)) === s` round-tripping.
7102
+ *
7103
+ * @module envelope-pattern/parse/meta/group-parser
7104
+ */
7105
+ function parseGroup(lexer) {
7106
+ const inner = parseOr(lexer);
7107
+ if (!inner.ok) return inner;
7108
+ const close = lexer.next();
7109
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
7110
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
7111
+ const next = lexer.peekToken();
7112
+ if (next === void 0) return inner;
7113
+ let quantifier;
7114
+ const tokenType = next.token.type;
7115
+ if (tokenType === "RepeatZeroOrMore") quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrMore(_bcts_dcbor_pattern.Reluctance.Greedy);
7116
+ else if (tokenType === "RepeatZeroOrMoreLazy") quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrMore(_bcts_dcbor_pattern.Reluctance.Lazy);
7117
+ else if (tokenType === "RepeatZeroOrMorePossessive") quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrMore(_bcts_dcbor_pattern.Reluctance.Possessive);
7118
+ else if (tokenType === "RepeatOneOrMore") quantifier = _bcts_dcbor_pattern.Quantifier.oneOrMore(_bcts_dcbor_pattern.Reluctance.Greedy);
7119
+ else if (tokenType === "RepeatOneOrMoreLazy") quantifier = _bcts_dcbor_pattern.Quantifier.oneOrMore(_bcts_dcbor_pattern.Reluctance.Lazy);
7120
+ else if (tokenType === "RepeatOneOrMorePossessive") quantifier = _bcts_dcbor_pattern.Quantifier.oneOrMore(_bcts_dcbor_pattern.Reluctance.Possessive);
7121
+ else if (tokenType === "RepeatZeroOrOne") quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrOne(_bcts_dcbor_pattern.Reluctance.Greedy);
7122
+ else if (tokenType === "RepeatZeroOrOneLazy") quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrOne(_bcts_dcbor_pattern.Reluctance.Lazy);
7123
+ else if (tokenType === "RepeatZeroOrOnePossessive") quantifier = _bcts_dcbor_pattern.Quantifier.zeroOrOne(_bcts_dcbor_pattern.Reluctance.Possessive);
7124
+ else if (tokenType === "Range") {
7125
+ if (!next.token.value.ok) return err(next.token.value.error);
7126
+ quantifier = next.token.value.value;
7127
+ } else return inner;
7128
+ lexer.next();
7129
+ return ok(repeat(inner.value, quantifier.min(), quantifier.max(), quantifier.reluctance()));
7130
+ }
7131
+ //#endregion
7132
+ //#region src/parse/meta/search-parser.ts
7133
+ /**
7134
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7135
+ * Copyright © 2025-2026 Parity Technologies
7136
+ *
7137
+ * Search parser — port of `bc-envelope-pattern-rust`
7138
+ * `parse/meta/search_parser.rs`.
7139
+ *
7140
+ * @module envelope-pattern/parse/meta/search-parser
7141
+ */
7142
+ function parseSearch(lexer) {
7143
+ const open = lexer.next();
7144
+ if (open === void 0) return err(unexpectedEndOfInput());
7145
+ if (open.token.type !== "ParenOpen") return err(unexpectedToken(open.token, open.span));
7146
+ const inner = parseOr(lexer);
7147
+ if (!inner.ok) return inner;
7148
+ const close = lexer.next();
7149
+ if (close === void 0) return err(expectedCloseParen(lexer.span()));
7150
+ if (close.token.type !== "ParenClose") return err(unexpectedToken(close.token, close.span));
7151
+ return ok(search(inner.value));
7152
+ }
7153
+ //#endregion
7154
+ //#region src/parse/meta/primary-parser.ts
7155
+ /**
7156
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7157
+ * Copyright © 2025-2026 Parity Technologies
7158
+ *
7159
+ * Primary parser — port of `bc-envelope-pattern-rust`
7160
+ * `parse/meta/primary_parser.rs`.
7161
+ *
7162
+ * Dispatches on the next token to the appropriate leaf/structure/meta
7163
+ * parser. When a `(` is encountered the open paren is consumed here and
7164
+ * `parse_group` handles the rest (paren'd expression + optional
7165
+ * quantifier suffix).
7166
+ *
7167
+ * @module envelope-pattern/parse/meta/primary-parser
7168
+ */
7169
+ function parsePrimary(lexer) {
7170
+ const tokenResult = lexer.next();
7171
+ if (tokenResult === void 0) return err(unexpectedEndOfInput());
7172
+ const { token, span } = tokenResult;
7173
+ switch (token.type) {
7174
+ case "Search": return parseSearch(lexer);
7175
+ case "Node": return parseNode(lexer);
7176
+ case "Assertion": return parseAssertion(lexer);
7177
+ case "AssertionPred": return parseAssertionPred(lexer);
7178
+ case "AssertionObj": return parseAssertionObj(lexer);
7179
+ case "Digest": return parseDigest(lexer);
7180
+ case "Obj": return parseObject(lexer);
7181
+ case "Obscured": return parseObscured(lexer);
7182
+ case "Elided": return parseElided(lexer);
7183
+ case "Encrypted": return parseEncrypted(lexer);
7184
+ case "Compressed": return parseCompressed(lexer);
7185
+ case "Pred": return parsePredicate(lexer);
7186
+ case "Subject": return parseSubject(lexer);
7187
+ case "Wrapped": return parseWrapped(lexer);
7188
+ case "Unwrap": return parseUnwrap(lexer);
7189
+ case "Leaf": return ok(leaf());
7190
+ case "GroupName": return parseCapture(lexer, token.name);
7191
+ case "ParenOpen": return parseGroup(lexer);
7192
+ case "Cbor": return parseCbor(lexer);
7193
+ case "RepeatZeroOrMore": return ok(any());
7194
+ case "BoolKeyword": return ok(anyBool());
7195
+ case "BoolTrue": return ok(bool(true));
7196
+ case "BoolFalse": return ok(bool(false));
7197
+ case "NumberKeyword": return ok(anyNumber());
7198
+ case "TextKeyword": return ok(anyText());
7199
+ case "StringLiteral":
7200
+ if (!token.value.ok) return err(token.value.error);
7201
+ return ok(text(token.value.value));
7202
+ case "UnsignedInteger":
7203
+ if (!token.value.ok) return err(token.value.error);
7204
+ return parseNumberRangeOrComparison(lexer, token.value.value);
7205
+ case "Integer":
7206
+ if (!token.value.ok) return err(token.value.error);
7207
+ return parseNumberRangeOrComparison(lexer, token.value.value);
7208
+ case "Float":
7209
+ if (!token.value.ok) return err(token.value.error);
7210
+ return parseNumberRangeOrComparison(lexer, token.value.value);
7211
+ case "GreaterThanOrEqual": return parseComparisonNumber(lexer, ">=");
7212
+ case "LessThanOrEqual": return parseComparisonNumber(lexer, "<=");
7213
+ case "GreaterThan": return parseComparisonNumber(lexer, ">");
7214
+ case "LessThan": return parseComparisonNumber(lexer, "<");
7215
+ case "NaN": return ok(patternLeaf(leafNumber(NumberPattern.nan())));
7216
+ case "Infinity": return ok(number(Infinity));
7217
+ case "NegativeInfinity": return ok(number(-Infinity));
7218
+ case "Regex":
7219
+ if (!token.value.ok) return err(token.value.error);
7220
+ try {
7221
+ return ok(textRegex(new RegExp(token.value.value)));
7222
+ } catch {
7223
+ return err(invalidRegex(span));
7224
+ }
7225
+ case "BracketOpen": return parseArray(lexer);
7226
+ case "ByteString": return ok(anyByteString());
7227
+ case "HexPattern":
7228
+ if (!token.value.ok) return err(token.value.error);
7229
+ return ok(byteString(token.value.value));
7230
+ case "HexBinaryRegex":
7231
+ if (!token.value.ok) return err(token.value.error);
7232
+ try {
7233
+ return ok(patternLeaf(leafByteString(ByteStringPattern.regex(new RegExp(token.value.value)))));
7234
+ } catch {
7235
+ return err(invalidRegex(span));
7236
+ }
7237
+ case "DateKeyword": return ok(anyDate());
7238
+ case "DatePattern":
7239
+ if (!token.value.ok) return err(token.value.error);
7240
+ return parseDateContent(token.value.value, span);
7241
+ case "Tagged": return parseTag(lexer);
7242
+ case "Known": return ok(anyKnownValue());
7243
+ case "SingleQuotedPattern":
7244
+ if (!token.value.ok) return err(token.value.error);
7245
+ return parseKnownValueContent(token.value.value);
7246
+ case "SingleQuotedRegex":
7247
+ if (!token.value.ok) return err(token.value.error);
7248
+ try {
7249
+ return ok(patternLeaf(leafKnownValue(KnownValuePattern.regex(new RegExp(token.value.value)))));
7250
+ } catch {
7251
+ return err(invalidRegex(span));
7252
+ }
7253
+ case "Null": return ok(nullPattern());
7254
+ case "Identifier": return err(unrecognizedToken(span));
7255
+ case "And":
7256
+ case "Or":
7257
+ case "Not":
7258
+ case "Traverse":
7259
+ case "RepeatZeroOrMoreLazy":
7260
+ case "RepeatZeroOrMorePossessive":
7261
+ case "RepeatOneOrMore":
7262
+ case "RepeatOneOrMoreLazy":
7263
+ case "RepeatOneOrMorePossessive":
7264
+ case "RepeatZeroOrOne":
7265
+ case "RepeatZeroOrOneLazy":
7266
+ case "RepeatZeroOrOnePossessive":
7267
+ case "ParenClose":
7268
+ case "BracketClose":
7269
+ case "Comma":
7270
+ case "Ellipsis":
7271
+ case "Range": return err(unexpectedToken(token, span));
7272
+ }
7273
+ }
7274
+ //#endregion
7275
+ //#region src/parse/meta/and-parser.ts
7276
+ /**
7277
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7278
+ * Copyright © 2025-2026 Parity Technologies
7279
+ *
7280
+ * And parser — port of `bc-envelope-pattern-rust`
7281
+ * `parse/meta/and_parser.rs`.
7282
+ *
7283
+ * Mirrors Rust: `parse_and` calls `parse_primary` (NOT `parse_not`); `!`
7284
+ * is handled at a higher precedence level by `parse_not`.
7285
+ *
7286
+ * @module envelope-pattern/parse/meta/and-parser
7287
+ */
7288
+ function parseAnd(lexer) {
7289
+ const patterns = [];
7290
+ const first = parsePrimary(lexer);
7291
+ if (!first.ok) return first;
7292
+ patterns.push(first.value);
7293
+ while (true) {
7294
+ if (lexer.peekToken()?.token.type !== "And") break;
7295
+ lexer.next();
7296
+ const nextExpr = parsePrimary(lexer);
7297
+ if (!nextExpr.ok) return nextExpr;
7298
+ patterns.push(nextExpr.value);
7299
+ }
7300
+ if (patterns.length === 1) return ok(patterns[0]);
7301
+ return ok(and(patterns));
7302
+ }
7303
+ //#endregion
7304
+ //#region src/parse/meta/not-parser.ts
7305
+ /**
7306
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7307
+ * Copyright © 2025-2026 Parity Technologies
7308
+ *
7309
+ * Not parser — port of `bc-envelope-pattern-rust`
7310
+ * `parse/meta/not_parser.rs`.
7311
+ *
7312
+ * Mirrors Rust:
7313
+ * - On `!`, recurse into `parse_not` so chained negation parses as
7314
+ * `not(not(x))` rather than `not(group(x))`.
7315
+ * - Otherwise descend into `parse_and`.
7316
+ *
7317
+ * @module envelope-pattern/parse/meta/not-parser
7318
+ */
7319
+ function parseNot(lexer) {
7320
+ if (lexer.peekToken()?.token.type === "Not") {
7321
+ lexer.next();
7322
+ const inner = parseNot(lexer);
7323
+ if (!inner.ok) return inner;
7324
+ return ok(notMatching(inner.value));
7325
+ }
7326
+ return parseAnd(lexer);
7327
+ }
7328
+ //#endregion
7329
+ //#region src/parse/meta/traverse-parser.ts
7330
+ /**
7331
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7332
+ * Copyright © 2025-2026 Parity Technologies
7333
+ *
7334
+ * Traverse parser — port of `bc-envelope-pattern-rust`
7335
+ * `parse/meta/traverse_parser.rs`.
7336
+ *
7337
+ * Note the precedence chain: `parse_or → parse_traverse → parse_not →
7338
+ * parse_and → parse_primary`. The earlier TS port had `parse_traverse`
7339
+ * call `parse_and` directly, which pushed `!` below `&` and
7340
+ * miscompiled `!a & b`.
7341
+ *
7342
+ * @module envelope-pattern/parse/meta/traverse-parser
7343
+ */
7344
+ function parseTraverse(lexer) {
7345
+ const patterns = [];
7346
+ const first = parseNot(lexer);
7347
+ if (!first.ok) return first;
7348
+ patterns.push(first.value);
7349
+ while (true) {
7350
+ if (lexer.peekToken()?.token.type !== "Traverse") break;
7351
+ lexer.next();
7352
+ const nextExpr = parseNot(lexer);
7353
+ if (!nextExpr.ok) return nextExpr;
7354
+ patterns.push(nextExpr.value);
7355
+ }
7356
+ if (patterns.length === 1) return ok(patterns[0]);
7357
+ return ok(traverse(patterns));
7358
+ }
7359
+ //#endregion
7360
+ //#region src/parse/meta/or-parser.ts
7361
+ /**
7362
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7363
+ * Copyright © 2025-2026 Parity Technologies
7364
+ *
7365
+ * Or parser — port of `bc-envelope-pattern-rust` `parse/meta/or_parser.rs`.
7366
+ *
7367
+ * @module envelope-pattern/parse/meta/or-parser
7368
+ */
7369
+ function parseOr(lexer) {
7370
+ const patterns = [];
7371
+ const first = parseTraverse(lexer);
7372
+ if (!first.ok) return first;
7373
+ patterns.push(first.value);
7374
+ while (true) {
7375
+ if (lexer.peekToken()?.token.type !== "Or") break;
7376
+ lexer.next();
7377
+ const nextExpr = parseTraverse(lexer);
7378
+ if (!nextExpr.ok) return nextExpr;
7379
+ patterns.push(nextExpr.value);
7380
+ }
7381
+ if (patterns.length === 1) return ok(patterns[0]);
7382
+ return ok(or(patterns));
7383
+ }
7384
+ //#endregion
7385
+ //#region src/parse/index.ts
7386
+ /**
7387
+ * Copyright © 2023-2026 Blockchain Commons, LLC
7388
+ * Copyright © 2025-2026 Parity Technologies
7389
+ *
7390
+ *
7391
+ * @bcts/envelope-pattern - Parser entry point
7392
+ *
7393
+ * This is a 1:1 TypeScript port of bc-envelope-pattern-rust parse/mod.rs.
7394
+ *
7395
+ * Recursive-descent parser for the Gordian Envelope pattern syntax. The
7396
+ * parsing rules live under `parse/leaf/`, `parse/meta/`, and
7397
+ * `parse/structure/`, mirroring the Rust crate's module layout.
7398
+ *
7399
+ * @module envelope-pattern/parse
7400
+ */
7401
+ /**
7402
+ * Parse a pattern expression string into a Pattern.
7403
+ *
7404
+ * Mirrors Rust `Pattern::parse`: tries envelope-pattern parsing first;
7405
+ * on failure falls back to dcbor-pattern parsing and converts the
7406
+ * result into an envelope pattern via the
7407
+ * `dcbor_integration::convert_dcbor_pattern_to_envelope_pattern` bridge.
7408
+ */
7409
+ function parse(input) {
7410
+ const lexer = new Lexer(input);
7411
+ const result = parseOr(lexer);
7412
+ if (!result.ok) {
7413
+ const dcborResult = (0, _bcts_dcbor_pattern.parse)(input);
7414
+ if (dcborResult.ok) return convertDcborPatternToEnvelopePattern(dcborResult.value);
7415
+ return result;
7416
+ }
7417
+ const next = lexer.next();
7418
+ if (next !== void 0) return err(extraData(next.span));
7419
+ return result;
7420
+ }
7421
+ /**
7422
+ * Parse a pattern, allowing extra data after the pattern.
7423
+ *
7424
+ * Returns the parsed pattern and the byte offset at which parsing
7425
+ * stopped, mirroring `Pattern::parse_partial` in spirit.
7426
+ */
7427
+ function parsePartial(input) {
7428
+ const lexer = new Lexer(input);
7429
+ const result = parseOr(lexer);
7430
+ if (!result.ok) return result;
7431
+ return ok([result.value, lexer.position]);
7432
+ }
7433
+ //#endregion
7434
+ //#region src/index.ts
7435
+ /**
6975
7436
  * Package version.
6976
7437
  */
6977
7438
  const VERSION = "1.0.0-alpha.11";
7439
+ //#endregion
7440
+ exports.AndPattern = AndPattern;
7441
+ exports.AnyPattern = AnyPattern;
7442
+ exports.ArrayPattern = ArrayPattern;
7443
+ exports.AssertionsPattern = AssertionsPattern;
7444
+ exports.BoolPattern = BoolPattern;
7445
+ exports.ByteStringPattern = ByteStringPattern;
7446
+ exports.CBORPattern = CBORPattern;
7447
+ exports.CapturePattern = CapturePattern;
7448
+ exports.DatePattern = DatePattern;
7449
+ exports.DigestPattern = DigestPattern;
7450
+ exports.FormatPathsOptsBuilder = FormatPathsOptsBuilder;
7451
+ exports.GroupPattern = GroupPattern;
7452
+ Object.defineProperty(exports, "Interval", {
7453
+ enumerable: true,
7454
+ get: function() {
7455
+ return _bcts_dcbor_pattern.Interval;
7456
+ }
7457
+ });
7458
+ exports.KnownValuePattern = KnownValuePattern;
7459
+ exports.LeafStructurePattern = LeafStructurePattern;
7460
+ exports.Lexer = Lexer;
7461
+ exports.MapPattern = MapPattern;
7462
+ exports.MatcherDefaults = MatcherDefaults;
7463
+ exports.NodePattern = NodePattern;
7464
+ exports.NotPattern = NotPattern;
7465
+ exports.NullPattern = NullPattern;
7466
+ exports.NumberPattern = NumberPattern;
7467
+ exports.ObjectPattern = ObjectPattern;
7468
+ exports.ObscuredPattern = ObscuredPattern;
7469
+ exports.OrPattern = OrPattern;
7470
+ exports.PredicatePattern = PredicatePattern;
7471
+ Object.defineProperty(exports, "Quantifier", {
7472
+ enumerable: true,
7473
+ get: function() {
7474
+ return _bcts_dcbor_pattern.Quantifier;
7475
+ }
7476
+ });
7477
+ Object.defineProperty(exports, "Reluctance", {
7478
+ enumerable: true,
7479
+ get: function() {
7480
+ return _bcts_dcbor_pattern.Reluctance;
7481
+ }
7482
+ });
7483
+ exports.SearchPattern = SearchPattern;
7484
+ exports.SubjectPattern = SubjectPattern;
7485
+ exports.TaggedPattern = TaggedPattern;
7486
+ exports.TextPattern = TextPattern;
7487
+ exports.TraversePattern = TraversePattern;
7488
+ exports.VERSION = VERSION;
7489
+ exports.WrappedPattern = WrappedPattern;
7490
+ exports.and = and;
7491
+ exports.any = any;
7492
+ exports.anyArray = anyArray;
7493
+ exports.anyAssertion = anyAssertion;
7494
+ exports.anyBool = anyBool;
7495
+ exports.anyByteString = anyByteString;
7496
+ exports.anyCbor = anyCbor;
7497
+ exports.anyDate = anyDate;
7498
+ exports.anyKnownValue = anyKnownValue;
7499
+ exports.anyMap = anyMap;
7500
+ exports.anyNode = anyNode;
7501
+ exports.anyNumber = anyNumber;
7502
+ exports.anyObject = anyObject;
7503
+ exports.anyPredicate = anyPredicate;
7504
+ exports.anySubject = anySubject;
7505
+ exports.anyTag = anyTag;
7506
+ exports.anyText = anyText;
7507
+ exports.assertionWithObject = assertionWithObject;
7508
+ exports.assertionWithPredicate = assertionWithPredicate;
7509
+ exports.axisChildren = axisChildren;
7510
+ exports.bool = bool;
7511
+ exports.byteString = byteString;
7512
+ exports.capture = capture;
7513
+ exports.cborPattern = cborPattern;
7514
+ exports.cborValue = cborValue;
7515
+ exports.compile = compile;
7516
+ exports.compileAsAtomic = compileAsAtomic;
7517
+ exports.compressed = compressed;
7518
+ exports.convertDcborPatternToEnvelopePattern = convertDcborPatternToEnvelopePattern;
7519
+ exports.date = date;
7520
+ exports.dateEarliest = dateEarliest;
7521
+ exports.dateLatest = dateLatest;
7522
+ exports.dateRange = dateRange;
7523
+ exports.dateRegex = dateRegex;
7524
+ exports.dcborPatternError = dcborPatternError;
7525
+ exports.defaultFormatPathsOpts = defaultFormatPathsOpts;
7526
+ exports.defaultPathElementFormat = defaultPathElementFormat;
7527
+ exports.digest = digest;
7528
+ exports.digestPrefix = digestPrefix;
7529
+ exports.digestURFormat = digestURFormat;
7530
+ exports.dispatchCompile = dispatchCompile;
7531
+ exports.dispatchIsComplex = dispatchIsComplex;
7532
+ exports.dispatchPaths = dispatchPaths;
7533
+ exports.dispatchPathsWithCaptures = dispatchPathsWithCaptures;
7534
+ exports.dispatchPatternToString = dispatchPatternToString;
7535
+ exports.elided = elided;
7536
+ exports.emptyInput = emptyInput;
7537
+ exports.encrypted = encrypted;
7538
+ exports.envelopeSummary = envelopeSummary;
7539
+ exports.envelopeURFormat = envelopeURFormat;
7540
+ exports.err = err;
7541
+ exports.expectedCloseBracket = expectedCloseBracket;
7542
+ exports.expectedCloseParen = expectedCloseParen;
7543
+ exports.expectedOpenBracket = expectedOpenBracket;
7544
+ exports.expectedOpenParen = expectedOpenParen;
7545
+ exports.expectedPattern = expectedPattern;
7546
+ exports.extraData = extraData;
7547
+ exports.formatError = formatError;
7548
+ exports.formatPath = formatPath;
7549
+ exports.formatPathOpt = formatPathOpt;
7550
+ exports.formatPaths = formatPaths;
7551
+ exports.formatPathsOpt = formatPathsOpt;
7552
+ exports.formatPathsOpts = formatPathsOpts;
7553
+ exports.formatPathsWithCaptures = formatPathsWithCaptures;
7554
+ exports.formatPathsWithCapturesOpt = formatPathsWithCapturesOpt;
7555
+ exports.group = group;
7556
+ exports.invalidCaptureGroupName = invalidCaptureGroupName;
7557
+ exports.invalidDateFormat = invalidDateFormat;
7558
+ exports.invalidHexString = invalidHexString;
7559
+ exports.invalidNumberFormat = invalidNumberFormat;
7560
+ exports.invalidPattern = invalidPattern;
7561
+ exports.invalidRange = invalidRange;
7562
+ exports.invalidRegex = invalidRegex;
7563
+ exports.invalidUr = invalidUr;
7564
+ exports.isErr = isErr;
7565
+ exports.isOk = isOk;
7566
+ exports.knownValue = knownValue;
7567
+ exports.leaf = leaf;
7568
+ exports.leafArray = leafArray;
7569
+ exports.leafBool = leafBool;
7570
+ exports.leafByteString = leafByteString;
7571
+ exports.leafCbor = leafCbor;
7572
+ exports.leafDate = leafDate;
7573
+ exports.leafKnownValue = leafKnownValue;
7574
+ exports.leafMap = leafMap;
7575
+ exports.leafNull = leafNull;
7576
+ exports.leafNumber = leafNumber;
7577
+ exports.leafPatternCompile = leafPatternCompile;
7578
+ exports.leafPatternIsComplex = leafPatternIsComplex;
7579
+ exports.leafPatternPaths = leafPatternPaths;
7580
+ exports.leafPatternPathsWithCaptures = leafPatternPathsWithCaptures;
7581
+ exports.leafPatternToString = leafPatternToString;
7582
+ exports.leafTag = leafTag;
7583
+ exports.leafText = leafText;
7584
+ exports.map = map;
7585
+ exports.matchPattern = matchPattern;
7586
+ exports.metaAnd = metaAnd;
7587
+ exports.metaAny = metaAny;
7588
+ exports.metaCapture = metaCapture;
7589
+ exports.metaGroup = metaGroup;
7590
+ exports.metaNot = metaNot;
7591
+ exports.metaOr = metaOr;
7592
+ exports.metaPatternCollectCaptureNames = metaPatternCollectCaptureNames;
7593
+ exports.metaPatternCompile = metaPatternCompile;
7594
+ exports.metaPatternIsComplex = metaPatternIsComplex;
7595
+ exports.metaPatternPathsWithCaptures = metaPatternPathsWithCaptures;
7596
+ exports.metaPatternToString = metaPatternToString;
7597
+ exports.metaSearch = metaSearch;
7598
+ exports.metaTraverse = metaTraverse;
7599
+ exports.notMatching = notMatching;
7600
+ exports.nullPattern = nullPattern;
7601
+ exports.number = number;
7602
+ exports.numberGreaterThan = numberGreaterThan;
7603
+ exports.numberLessThan = numberLessThan;
7604
+ exports.numberRange = numberRange;
7605
+ exports.object = object;
7606
+ exports.obscured = obscured;
7607
+ exports.ok = ok;
7608
+ exports.or = or;
7609
+ exports.parse = parse;
7610
+ exports.parsePartial = parsePartial;
7611
+ exports.patternCollectCaptureNames = patternCollectCaptureNames;
7612
+ exports.patternCompile = patternCompile;
7613
+ exports.patternIsComplex = patternIsComplex;
7614
+ exports.patternLeaf = patternLeaf;
7615
+ exports.patternMatches = patternMatches;
7616
+ exports.patternMeta = patternMeta;
7617
+ exports.patternPaths = patternPaths;
7618
+ exports.patternPathsWithCaptures = patternPathsWithCaptures;
7619
+ exports.patternStructure = patternStructure;
7620
+ exports.patternToString = patternToString;
7621
+ exports.predicate = predicate;
7622
+ exports.registerAndPatternFactory = registerAndPatternFactory;
7623
+ exports.registerAnyPatternFactory = registerAnyPatternFactory;
7624
+ exports.registerArrayPatternFactory = registerArrayPatternFactory;
7625
+ exports.registerAssertionsPatternFactory = registerAssertionsPatternFactory;
7626
+ exports.registerAssertionsPatternToStringDispatch = registerAssertionsPatternToStringDispatch;
7627
+ exports.registerBoolPatternFactory = registerBoolPatternFactory;
7628
+ exports.registerByteStringPatternFactory = registerByteStringPatternFactory;
7629
+ exports.registerCBORPatternFactory = registerCBORPatternFactory;
7630
+ exports.registerCapturePatternFactory = registerCapturePatternFactory;
7631
+ exports.registerDatePatternFactory = registerDatePatternFactory;
7632
+ exports.registerDigestPatternFactory = registerDigestPatternFactory;
7633
+ exports.registerGroupPatternFactory = registerGroupPatternFactory;
7634
+ exports.registerKnownValuePatternFactory = registerKnownValuePatternFactory;
7635
+ exports.registerLeafStructurePatternFactory = registerLeafStructurePatternFactory;
7636
+ exports.registerMapPatternFactory = registerMapPatternFactory;
7637
+ exports.registerNodePatternFactory = registerNodePatternFactory;
7638
+ exports.registerNotPatternFactory = registerNotPatternFactory;
7639
+ exports.registerNullPatternFactory = registerNullPatternFactory;
7640
+ exports.registerNumberPatternFactory = registerNumberPatternFactory;
7641
+ exports.registerObjectPatternFactory = registerObjectPatternFactory;
7642
+ exports.registerObscuredPatternFactory = registerObscuredPatternFactory;
7643
+ exports.registerOrPatternFactory = registerOrPatternFactory;
7644
+ exports.registerPatternDispatchFns = registerPatternDispatchFns;
7645
+ exports.registerPatternMatchFn = registerPatternMatchFn;
7646
+ exports.registerPredicatePatternFactory = registerPredicatePatternFactory;
7647
+ exports.registerSearchPatternFactory = registerSearchPatternFactory;
7648
+ exports.registerSubjectPatternDispatch = registerSubjectPatternDispatch;
7649
+ exports.registerSubjectPatternFactory = registerSubjectPatternFactory;
7650
+ exports.registerTaggedPatternFactory = registerTaggedPatternFactory;
7651
+ exports.registerTextPatternFactory = registerTextPatternFactory;
7652
+ exports.registerTraversePatternFactory = registerTraversePatternFactory;
7653
+ exports.registerVMPatternFunctions = registerVMPatternFunctions;
7654
+ exports.registerWrappedPatternAny = registerWrappedPatternAny;
7655
+ exports.registerWrappedPatternDispatch = registerWrappedPatternDispatch;
7656
+ exports.registerWrappedPatternFactory = registerWrappedPatternFactory;
7657
+ exports.repeat = repeat;
7658
+ exports.run = run;
7659
+ exports.search = search;
7660
+ exports.structureAssertions = structureAssertions;
7661
+ exports.structureDigest = structureDigest;
7662
+ exports.structureLeaf = structureLeaf;
7663
+ exports.structureNode = structureNode;
7664
+ exports.structureObject = structureObject;
7665
+ exports.structureObscured = structureObscured;
7666
+ exports.structurePatternCompile = structurePatternCompile;
7667
+ exports.structurePatternIsComplex = structurePatternIsComplex;
7668
+ exports.structurePatternPaths = structurePatternPaths;
7669
+ exports.structurePatternPathsWithCaptures = structurePatternPathsWithCaptures;
7670
+ exports.structurePatternToString = structurePatternToString;
7671
+ exports.structurePredicate = structurePredicate;
7672
+ exports.structureSubject = structureSubject;
7673
+ exports.structureWrapped = structureWrapped;
7674
+ exports.subject = subject;
7675
+ exports.summaryFormat = summaryFormat;
7676
+ exports.tagged = tagged;
7677
+ exports.text = text;
7678
+ exports.textRegex = textRegex;
7679
+ exports.traverse = traverse;
7680
+ exports.unexpectedEndOfInput = unexpectedEndOfInput;
7681
+ exports.unexpectedToken = unexpectedToken;
7682
+ exports.unit = unit;
7683
+ exports.unknown = unknown;
7684
+ exports.unmatchedBraces = unmatchedBraces;
7685
+ exports.unmatchedParentheses = unmatchedParentheses;
7686
+ exports.unrecognizedToken = unrecognizedToken;
7687
+ exports.unterminatedRegex = unterminatedRegex;
7688
+ exports.unwrap = unwrap;
7689
+ exports.unwrapEnvelope = unwrapEnvelope;
7690
+ exports.unwrapMatching = unwrapMatching;
7691
+ exports.unwrapOr = unwrapOr;
7692
+ exports.wrapped = wrapped;
7693
+ return exports;
7694
+ })({}, bctsDcborPattern, bctsKnownValues, bctsDcbor, bctsEnvelope, bctsDcborParse);
6978
7695
 
6979
- //#endregion
6980
- exports.AndPattern = AndPattern;
6981
- exports.AnyPattern = AnyPattern;
6982
- exports.ArrayPattern = ArrayPattern;
6983
- exports.AssertionsPattern = AssertionsPattern;
6984
- exports.BoolPattern = BoolPattern;
6985
- exports.ByteStringPattern = ByteStringPattern;
6986
- exports.CBORPattern = CBORPattern;
6987
- exports.CapturePattern = CapturePattern;
6988
- exports.DatePattern = DatePattern;
6989
- exports.DigestPattern = DigestPattern;
6990
- exports.FormatPathsOptsBuilder = FormatPathsOptsBuilder;
6991
- exports.GroupPattern = GroupPattern;
6992
- Object.defineProperty(exports, 'Interval', {
6993
- enumerable: true,
6994
- get: function () {
6995
- return _bcts_dcbor_pattern.Interval;
6996
- }
6997
- });
6998
- exports.KnownValuePattern = KnownValuePattern;
6999
- exports.LeafStructurePattern = LeafStructurePattern;
7000
- exports.Lexer = Lexer;
7001
- exports.MapPattern = MapPattern;
7002
- exports.MatcherDefaults = MatcherDefaults;
7003
- exports.NodePattern = NodePattern;
7004
- exports.NotPattern = NotPattern;
7005
- exports.NullPattern = NullPattern;
7006
- exports.NumberPattern = NumberPattern;
7007
- exports.ObjectPattern = ObjectPattern;
7008
- exports.ObscuredPattern = ObscuredPattern;
7009
- exports.OrPattern = OrPattern;
7010
- exports.PredicatePattern = PredicatePattern;
7011
- Object.defineProperty(exports, 'Quantifier', {
7012
- enumerable: true,
7013
- get: function () {
7014
- return _bcts_dcbor_pattern.Quantifier;
7015
- }
7016
- });
7017
- Object.defineProperty(exports, 'Reluctance', {
7018
- enumerable: true,
7019
- get: function () {
7020
- return _bcts_dcbor_pattern.Reluctance;
7021
- }
7022
- });
7023
- exports.SearchPattern = SearchPattern;
7024
- exports.SubjectPattern = SubjectPattern;
7025
- exports.TaggedPattern = TaggedPattern;
7026
- exports.TextPattern = TextPattern;
7027
- exports.TraversePattern = TraversePattern;
7028
- exports.VERSION = VERSION;
7029
- exports.WrappedPattern = WrappedPattern;
7030
- exports.and = and;
7031
- exports.any = any;
7032
- exports.anyArray = anyArray;
7033
- exports.anyAssertion = anyAssertion;
7034
- exports.anyBool = anyBool;
7035
- exports.anyByteString = anyByteString;
7036
- exports.anyCbor = anyCbor;
7037
- exports.anyDate = anyDate;
7038
- exports.anyKnownValue = anyKnownValue;
7039
- exports.anyMap = anyMap;
7040
- exports.anyNode = anyNode;
7041
- exports.anyNumber = anyNumber;
7042
- exports.anyObject = anyObject;
7043
- exports.anyPredicate = anyPredicate;
7044
- exports.anySubject = anySubject;
7045
- exports.anyTag = anyTag;
7046
- exports.anyText = anyText;
7047
- exports.assertionWithObject = assertionWithObject;
7048
- exports.assertionWithPredicate = assertionWithPredicate;
7049
- exports.axisChildren = axisChildren;
7050
- exports.bool = bool;
7051
- exports.byteString = byteString;
7052
- exports.capture = capture;
7053
- exports.cborPattern = cborPattern;
7054
- exports.cborValue = cborValue;
7055
- exports.compile = compile;
7056
- exports.compileAsAtomic = compileAsAtomic;
7057
- exports.compressed = compressed;
7058
- exports.convertDcborPatternToEnvelopePattern = convertDcborPatternToEnvelopePattern;
7059
- exports.date = date;
7060
- exports.dateEarliest = dateEarliest;
7061
- exports.dateLatest = dateLatest;
7062
- exports.dateRange = dateRange;
7063
- exports.dateRegex = dateRegex;
7064
- exports.dcborPatternError = dcborPatternError;
7065
- exports.defaultFormatPathsOpts = defaultFormatPathsOpts;
7066
- exports.defaultPathElementFormat = defaultPathElementFormat;
7067
- exports.digest = digest;
7068
- exports.digestPrefix = digestPrefix;
7069
- exports.digestURFormat = digestURFormat;
7070
- exports.dispatchCompile = dispatchCompile;
7071
- exports.dispatchIsComplex = dispatchIsComplex;
7072
- exports.dispatchPaths = dispatchPaths;
7073
- exports.dispatchPathsWithCaptures = dispatchPathsWithCaptures;
7074
- exports.dispatchPatternToString = dispatchPatternToString;
7075
- exports.elided = elided;
7076
- exports.emptyInput = emptyInput;
7077
- exports.encrypted = encrypted;
7078
- exports.envelopeSummary = envelopeSummary;
7079
- exports.envelopeURFormat = envelopeURFormat;
7080
- exports.err = err;
7081
- exports.expectedCloseBracket = expectedCloseBracket;
7082
- exports.expectedCloseParen = expectedCloseParen;
7083
- exports.expectedOpenBracket = expectedOpenBracket;
7084
- exports.expectedOpenParen = expectedOpenParen;
7085
- exports.expectedPattern = expectedPattern;
7086
- exports.extraData = extraData;
7087
- exports.formatError = formatError;
7088
- exports.formatPath = formatPath;
7089
- exports.formatPathOpt = formatPathOpt;
7090
- exports.formatPaths = formatPaths;
7091
- exports.formatPathsOpt = formatPathsOpt;
7092
- exports.formatPathsOpts = formatPathsOpts;
7093
- exports.formatPathsWithCaptures = formatPathsWithCaptures;
7094
- exports.formatPathsWithCapturesOpt = formatPathsWithCapturesOpt;
7095
- exports.group = group;
7096
- exports.invalidCaptureGroupName = invalidCaptureGroupName;
7097
- exports.invalidDateFormat = invalidDateFormat;
7098
- exports.invalidHexString = invalidHexString;
7099
- exports.invalidNumberFormat = invalidNumberFormat;
7100
- exports.invalidPattern = invalidPattern;
7101
- exports.invalidRange = invalidRange;
7102
- exports.invalidRegex = invalidRegex;
7103
- exports.invalidUr = invalidUr;
7104
- exports.isErr = isErr;
7105
- exports.isOk = isOk;
7106
- exports.knownValue = knownValue;
7107
- exports.leaf = leaf;
7108
- exports.leafArray = leafArray;
7109
- exports.leafBool = leafBool;
7110
- exports.leafByteString = leafByteString;
7111
- exports.leafCbor = leafCbor;
7112
- exports.leafDate = leafDate;
7113
- exports.leafKnownValue = leafKnownValue;
7114
- exports.leafMap = leafMap;
7115
- exports.leafNull = leafNull;
7116
- exports.leafNumber = leafNumber;
7117
- exports.leafPatternCompile = leafPatternCompile;
7118
- exports.leafPatternIsComplex = leafPatternIsComplex;
7119
- exports.leafPatternPaths = leafPatternPaths;
7120
- exports.leafPatternPathsWithCaptures = leafPatternPathsWithCaptures;
7121
- exports.leafPatternToString = leafPatternToString;
7122
- exports.leafTag = leafTag;
7123
- exports.leafText = leafText;
7124
- exports.map = map;
7125
- exports.matchPattern = matchPattern;
7126
- exports.metaAnd = metaAnd;
7127
- exports.metaAny = metaAny;
7128
- exports.metaCapture = metaCapture;
7129
- exports.metaGroup = metaGroup;
7130
- exports.metaNot = metaNot;
7131
- exports.metaOr = metaOr;
7132
- exports.metaPatternCollectCaptureNames = metaPatternCollectCaptureNames;
7133
- exports.metaPatternCompile = metaPatternCompile;
7134
- exports.metaPatternIsComplex = metaPatternIsComplex;
7135
- exports.metaPatternPathsWithCaptures = metaPatternPathsWithCaptures;
7136
- exports.metaPatternToString = metaPatternToString;
7137
- exports.metaSearch = metaSearch;
7138
- exports.metaTraverse = metaTraverse;
7139
- exports.notMatching = notMatching;
7140
- exports.nullPattern = nullPattern;
7141
- exports.number = number;
7142
- exports.numberGreaterThan = numberGreaterThan;
7143
- exports.numberLessThan = numberLessThan;
7144
- exports.numberRange = numberRange;
7145
- exports.object = object;
7146
- exports.obscured = obscured;
7147
- exports.ok = ok;
7148
- exports.or = or;
7149
- exports.parse = parse;
7150
- exports.parsePartial = parsePartial;
7151
- exports.patternCollectCaptureNames = patternCollectCaptureNames;
7152
- exports.patternCompile = patternCompile;
7153
- exports.patternIsComplex = patternIsComplex;
7154
- exports.patternLeaf = patternLeaf;
7155
- exports.patternMatches = patternMatches;
7156
- exports.patternMeta = patternMeta;
7157
- exports.patternPaths = patternPaths;
7158
- exports.patternPathsWithCaptures = patternPathsWithCaptures;
7159
- exports.patternStructure = patternStructure;
7160
- exports.patternToString = patternToString;
7161
- exports.predicate = predicate;
7162
- exports.registerAndPatternFactory = registerAndPatternFactory;
7163
- exports.registerAnyPatternFactory = registerAnyPatternFactory;
7164
- exports.registerArrayPatternFactory = registerArrayPatternFactory;
7165
- exports.registerAssertionsPatternFactory = registerAssertionsPatternFactory;
7166
- exports.registerBoolPatternFactory = registerBoolPatternFactory;
7167
- exports.registerByteStringPatternFactory = registerByteStringPatternFactory;
7168
- exports.registerCBORPatternFactory = registerCBORPatternFactory;
7169
- exports.registerCapturePatternFactory = registerCapturePatternFactory;
7170
- exports.registerDatePatternFactory = registerDatePatternFactory;
7171
- exports.registerDigestPatternFactory = registerDigestPatternFactory;
7172
- exports.registerGroupPatternFactory = registerGroupPatternFactory;
7173
- exports.registerKnownValuePatternFactory = registerKnownValuePatternFactory;
7174
- exports.registerLeafStructurePatternFactory = registerLeafStructurePatternFactory;
7175
- exports.registerMapPatternFactory = registerMapPatternFactory;
7176
- exports.registerNodePatternFactory = registerNodePatternFactory;
7177
- exports.registerNotPatternFactory = registerNotPatternFactory;
7178
- exports.registerNullPatternFactory = registerNullPatternFactory;
7179
- exports.registerNumberPatternFactory = registerNumberPatternFactory;
7180
- exports.registerObjectPatternFactory = registerObjectPatternFactory;
7181
- exports.registerObscuredPatternFactory = registerObscuredPatternFactory;
7182
- exports.registerOrPatternFactory = registerOrPatternFactory;
7183
- exports.registerPatternDispatchFns = registerPatternDispatchFns;
7184
- exports.registerPatternMatchFn = registerPatternMatchFn;
7185
- exports.registerPredicatePatternFactory = registerPredicatePatternFactory;
7186
- exports.registerSearchPatternFactory = registerSearchPatternFactory;
7187
- exports.registerSubjectPatternFactory = registerSubjectPatternFactory;
7188
- exports.registerTaggedPatternFactory = registerTaggedPatternFactory;
7189
- exports.registerTextPatternFactory = registerTextPatternFactory;
7190
- exports.registerTraversePatternFactory = registerTraversePatternFactory;
7191
- exports.registerVMPatternFunctions = registerVMPatternFunctions;
7192
- exports.registerWrappedPatternDispatch = registerWrappedPatternDispatch;
7193
- exports.registerWrappedPatternFactory = registerWrappedPatternFactory;
7194
- exports.repeat = repeat;
7195
- exports.run = run;
7196
- exports.search = search;
7197
- exports.structureAssertions = structureAssertions;
7198
- exports.structureDigest = structureDigest;
7199
- exports.structureLeaf = structureLeaf;
7200
- exports.structureNode = structureNode;
7201
- exports.structureObject = structureObject;
7202
- exports.structureObscured = structureObscured;
7203
- exports.structurePatternCompile = structurePatternCompile;
7204
- exports.structurePatternIsComplex = structurePatternIsComplex;
7205
- exports.structurePatternPaths = structurePatternPaths;
7206
- exports.structurePatternPathsWithCaptures = structurePatternPathsWithCaptures;
7207
- exports.structurePatternToString = structurePatternToString;
7208
- exports.structurePredicate = structurePredicate;
7209
- exports.structureSubject = structureSubject;
7210
- exports.structureWrapped = structureWrapped;
7211
- exports.subject = subject;
7212
- exports.summaryFormat = summaryFormat;
7213
- exports.tagged = tagged;
7214
- exports.text = text;
7215
- exports.textRegex = textRegex;
7216
- exports.traverse = traverse;
7217
- exports.unexpectedEndOfInput = unexpectedEndOfInput;
7218
- exports.unexpectedToken = unexpectedToken;
7219
- exports.unit = unit;
7220
- exports.unknown = unknown;
7221
- exports.unmatchedBraces = unmatchedBraces;
7222
- exports.unmatchedParentheses = unmatchedParentheses;
7223
- exports.unrecognizedToken = unrecognizedToken;
7224
- exports.unterminatedRegex = unterminatedRegex;
7225
- exports.unwrap = unwrap;
7226
- exports.unwrapEnvelope = unwrapEnvelope;
7227
- exports.unwrapMatching = unwrapMatching;
7228
- exports.unwrapOr = unwrapOr;
7229
- exports.wrapped = wrapped;
7230
- return exports;
7231
- })({}, bctsDcborPattern, bctsKnownValues, bctsEnvelope, bctsDcbor, bctsDcborParse);
7232
7696
  //# sourceMappingURL=index.iife.js.map