@bcts/envelope 1.0.0-alpha.18 → 1.0.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,5 @@
1
- //#region rolldown:runtime
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -62,6 +63,7 @@ let ErrorCode = /* @__PURE__ */ function(ErrorCode) {
62
63
  ErrorCode["EDGE_DUPLICATE_IS_A"] = "EDGE_DUPLICATE_IS_A";
63
64
  ErrorCode["EDGE_DUPLICATE_SOURCE"] = "EDGE_DUPLICATE_SOURCE";
64
65
  ErrorCode["EDGE_DUPLICATE_TARGET"] = "EDGE_DUPLICATE_TARGET";
66
+ ErrorCode["EDGE_UNEXPECTED_ASSERTION"] = "EDGE_UNEXPECTED_ASSERTION";
65
67
  ErrorCode["NONEXISTENT_EDGE"] = "NONEXISTENT_EDGE";
66
68
  ErrorCode["AMBIGUOUS_EDGE"] = "AMBIGUOUS_EDGE";
67
69
  ErrorCode["ALREADY_COMPRESSED"] = "ALREADY_COMPRESSED";
@@ -154,6 +156,9 @@ var EnvelopeError = class EnvelopeError extends Error {
154
156
  static edgeDuplicateTarget() {
155
157
  return new EnvelopeError(ErrorCode.EDGE_DUPLICATE_TARGET, "edge has duplicate 'target' assertions");
156
158
  }
159
+ static edgeUnexpectedAssertion() {
160
+ return new EnvelopeError(ErrorCode.EDGE_UNEXPECTED_ASSERTION, "edge has unexpected assertion");
161
+ }
157
162
  static nonexistentEdge() {
158
163
  return new EnvelopeError(ErrorCode.NONEXISTENT_EDGE, "nonexistent edge");
159
164
  }
@@ -2285,7 +2290,7 @@ Envelope.prototype.edges = function() {
2285
2290
  *
2286
2291
  * An edge may be wrapped (signed) or unwrapped. The inner envelope
2287
2292
  * must have exactly three assertion predicates: `'isA'`, `'source'`,
2288
- * and `'target'`.
2293
+ * and `'target'`. No other assertions are permitted on the edge subject.
2289
2294
  *
2290
2295
  * Equivalent to Rust's `Envelope::validate_edge()`.
2291
2296
  *
@@ -2293,15 +2298,31 @@ Envelope.prototype.edges = function() {
2293
2298
  */
2294
2299
  Envelope.prototype.validateEdge = function() {
2295
2300
  const inner = this.subject().isWrapped() ? this.subject().tryUnwrap() : this;
2296
- const isACount = inner.assertionsWithPredicate(_bcts_known_values.IS_A).length;
2297
- const sourceCount = inner.assertionsWithPredicate(_bcts_known_values.SOURCE).length;
2298
- const targetCount = inner.assertionsWithPredicate(_bcts_known_values.TARGET).length;
2299
- if (isACount === 0) throw EnvelopeError.edgeMissingIsA();
2300
- if (sourceCount === 0) throw EnvelopeError.edgeMissingSource();
2301
- if (targetCount === 0) throw EnvelopeError.edgeMissingTarget();
2302
- if (isACount > 1) throw EnvelopeError.edgeDuplicateIsA();
2303
- if (sourceCount > 1) throw EnvelopeError.edgeDuplicateSource();
2304
- if (targetCount > 1) throw EnvelopeError.edgeDuplicateTarget();
2301
+ let seenIsA = false;
2302
+ let seenSource = false;
2303
+ let seenTarget = false;
2304
+ for (const assertion of inner.assertions()) {
2305
+ const kv = assertion.tryPredicate().asKnownValue();
2306
+ if (kv === void 0) throw EnvelopeError.edgeUnexpectedAssertion();
2307
+ switch (kv.valueBigInt()) {
2308
+ case _bcts_known_values.IS_A_RAW:
2309
+ if (seenIsA) throw EnvelopeError.edgeDuplicateIsA();
2310
+ seenIsA = true;
2311
+ break;
2312
+ case _bcts_known_values.SOURCE_RAW:
2313
+ if (seenSource) throw EnvelopeError.edgeDuplicateSource();
2314
+ seenSource = true;
2315
+ break;
2316
+ case _bcts_known_values.TARGET_RAW:
2317
+ if (seenTarget) throw EnvelopeError.edgeDuplicateTarget();
2318
+ seenTarget = true;
2319
+ break;
2320
+ default: throw EnvelopeError.edgeUnexpectedAssertion();
2321
+ }
2322
+ }
2323
+ if (!seenIsA) throw EnvelopeError.edgeMissingIsA();
2324
+ if (!seenSource) throw EnvelopeError.edgeMissingSource();
2325
+ if (!seenTarget) throw EnvelopeError.edgeMissingTarget();
2305
2326
  };
2306
2327
  /**
2307
2328
  * Extracts the `'isA'` assertion object from an edge envelope.