@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bcts/envelope-pattern",
3
- "version": "1.0.0-alpha.22",
3
+ "version": "1.0.0-beta.0",
4
4
  "type": "module",
5
5
  "description": "Pattern matching for Gordian Envelope structures",
6
6
  "license": "BSD-2-Clause-Patent",
@@ -48,17 +48,19 @@
48
48
  "devDependencies": {
49
49
  "@bcts/eslint": "^0.1.0",
50
50
  "@bcts/tsconfig": "^0.1.0",
51
- "eslint": "^10.0.2",
52
- "tsdown": "^0.20.3",
53
- "typedoc": "^0.28.17",
54
- "typescript": "^5.9.3",
55
- "vitest": "^4.0.18"
51
+ "eslint": "^10.2.1",
52
+ "tsdown": "^0.21.0",
53
+ "typedoc": "^0.28.19",
54
+ "typescript": "^6.0.3",
55
+ "vitest": "^4.1.5"
56
56
  },
57
57
  "dependencies": {
58
- "@bcts/dcbor": "^1.0.0-alpha.22",
59
- "@bcts/dcbor-parse": "^1.0.0-alpha.22",
60
- "@bcts/dcbor-pattern": "^1.0.0-alpha.22",
61
- "@bcts/envelope": "^1.0.0-alpha.22",
62
- "@bcts/known-values": "^1.0.0-alpha.22"
58
+ "@bcts/components": "^1.0.0-beta.0",
59
+ "@bcts/dcbor": "^1.0.0-beta.0",
60
+ "@bcts/dcbor-parse": "^1.0.0-beta.0",
61
+ "@bcts/dcbor-pattern": "^1.0.0-beta.0",
62
+ "@bcts/envelope": "^1.0.0-beta.0",
63
+ "@bcts/known-values": "^1.0.0-beta.0",
64
+ "@bcts/rand": "^1.0.0-beta.0"
63
65
  }
64
66
  }
package/src/error.ts CHANGED
@@ -114,7 +114,7 @@ export function map<T, U>(result: Result<T>, fn: (value: T) => U): Result<U> {
114
114
  if (result.ok) {
115
115
  return ok(fn(result.value));
116
116
  }
117
- return result as Result<U>;
117
+ return result;
118
118
  }
119
119
 
120
120
  /**
package/src/format.ts CHANGED
@@ -151,6 +151,14 @@ export function formatPathsOpts(): FormatPathsOptsBuilder {
151
151
  /**
152
152
  * Gets a summary of an envelope for display.
153
153
  *
154
+ * Mirrors Rust `envelope_summary` in `format.rs`: defers to
155
+ * `Envelope::format_flat()` for nodes / wrapped / assertions and to
156
+ * `cbor.envelope_summary(usize::MAX, ...)` for raw CBOR leaves. The
157
+ * obscured cases (`elided` / `encrypted` / `compressed`) emit just the
158
+ * keyword. KnownValue envelopes look up the canonical name via
159
+ * `KnownValue.name()`, matching the Rust call to
160
+ * `KnownValuesStore::known_value_for_raw_value(value, …)`.
161
+ *
154
162
  * @param env - The envelope to summarize
155
163
  * @returns A string summary of the envelope
156
164
  */
@@ -160,37 +168,18 @@ export function envelopeSummary(env: Envelope): string {
160
168
 
161
169
  let summary: string;
162
170
  switch (c.type) {
163
- case "node": {
164
- const subjectSummary = env.subject().summary(Number.MAX_SAFE_INTEGER);
165
- const assertions = env.assertions();
166
- if (assertions.length > 0) {
167
- const assertionSummaries = assertions.map((a) => {
168
- const ac = a.case();
169
- if (ac.type === "assertion") {
170
- const pred = ac.assertion.predicate().summary(Number.MAX_SAFE_INTEGER);
171
- const obj = ac.assertion.object().summary(Number.MAX_SAFE_INTEGER);
172
- return `${pred}: ${obj}`;
173
- }
174
- return a.summary(Number.MAX_SAFE_INTEGER);
175
- });
176
- summary = `NODE ${subjectSummary} [ ${assertionSummaries.join(", ")} ]`;
177
- } else {
178
- summary = `NODE ${subjectSummary}`;
179
- }
171
+ case "node":
172
+ summary = `NODE ${env.formatFlat()}`;
180
173
  break;
181
- }
182
174
  case "leaf":
183
175
  summary = `LEAF ${env.summary(Number.MAX_SAFE_INTEGER)}`;
184
176
  break;
185
177
  case "wrapped":
186
- summary = `WRAPPED ${env.summary(Number.MAX_SAFE_INTEGER)}`;
178
+ summary = `WRAPPED ${env.formatFlat()}`;
187
179
  break;
188
- case "assertion": {
189
- const pred = c.assertion.predicate().summary(Number.MAX_SAFE_INTEGER);
190
- const obj = c.assertion.object().summary(Number.MAX_SAFE_INTEGER);
191
- summary = `ASSERTION ${pred}: ${obj}`;
180
+ case "assertion":
181
+ summary = `ASSERTION ${env.formatFlat()}`;
192
182
  break;
193
- }
194
183
  case "elided":
195
184
  summary = "ELIDED";
196
185
  break;
@@ -254,10 +243,9 @@ export function formatPathOpt(
254
243
  return truncateWithEllipsis(summary, opts.elementFormat.maxLength);
255
244
  }
256
245
  case "EnvelopeUR":
257
- // TODO: Implement proper UR string format when available
258
- return element.digest().toString();
246
+ return element.urString();
259
247
  case "DigestUR":
260
- return element.digest().toString();
248
+ return element.digest().urString();
261
249
  }
262
250
  }
263
251
 
@@ -277,11 +265,11 @@ export function formatPathOpt(
277
265
  return lines.join("\n");
278
266
  }
279
267
  case "EnvelopeUR":
280
- // TODO: Implement proper UR string format when available
281
- return path.map((element) => element.digest().toString()).join(" ");
268
+ // Single-line, space-separated envelope URs (mirrors Rust).
269
+ return path.map((element) => element.urString()).join(" ");
282
270
  case "DigestUR":
283
- // Single-line, space-separated digest strings
284
- return path.map((element) => element.digest().toString()).join(" ");
271
+ // Single-line, space-separated digest URs (mirrors Rust).
272
+ return path.map((element) => element.digest().urString()).join(" ");
285
273
  }
286
274
  }
287
275