@bcts/envelope 1.0.0-alpha.19 → 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 +30 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +30 -10
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +31 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/base/error.ts +6 -0
- package/src/extension/edge.ts +39 -17
package/dist/index.cjs
CHANGED
|
@@ -63,6 +63,7 @@ let ErrorCode = /* @__PURE__ */ function(ErrorCode) {
|
|
|
63
63
|
ErrorCode["EDGE_DUPLICATE_IS_A"] = "EDGE_DUPLICATE_IS_A";
|
|
64
64
|
ErrorCode["EDGE_DUPLICATE_SOURCE"] = "EDGE_DUPLICATE_SOURCE";
|
|
65
65
|
ErrorCode["EDGE_DUPLICATE_TARGET"] = "EDGE_DUPLICATE_TARGET";
|
|
66
|
+
ErrorCode["EDGE_UNEXPECTED_ASSERTION"] = "EDGE_UNEXPECTED_ASSERTION";
|
|
66
67
|
ErrorCode["NONEXISTENT_EDGE"] = "NONEXISTENT_EDGE";
|
|
67
68
|
ErrorCode["AMBIGUOUS_EDGE"] = "AMBIGUOUS_EDGE";
|
|
68
69
|
ErrorCode["ALREADY_COMPRESSED"] = "ALREADY_COMPRESSED";
|
|
@@ -155,6 +156,9 @@ var EnvelopeError = class EnvelopeError extends Error {
|
|
|
155
156
|
static edgeDuplicateTarget() {
|
|
156
157
|
return new EnvelopeError(ErrorCode.EDGE_DUPLICATE_TARGET, "edge has duplicate 'target' assertions");
|
|
157
158
|
}
|
|
159
|
+
static edgeUnexpectedAssertion() {
|
|
160
|
+
return new EnvelopeError(ErrorCode.EDGE_UNEXPECTED_ASSERTION, "edge has unexpected assertion");
|
|
161
|
+
}
|
|
158
162
|
static nonexistentEdge() {
|
|
159
163
|
return new EnvelopeError(ErrorCode.NONEXISTENT_EDGE, "nonexistent edge");
|
|
160
164
|
}
|
|
@@ -2286,7 +2290,7 @@ Envelope.prototype.edges = function() {
|
|
|
2286
2290
|
*
|
|
2287
2291
|
* An edge may be wrapped (signed) or unwrapped. The inner envelope
|
|
2288
2292
|
* must have exactly three assertion predicates: `'isA'`, `'source'`,
|
|
2289
|
-
* and `'target'`.
|
|
2293
|
+
* and `'target'`. No other assertions are permitted on the edge subject.
|
|
2290
2294
|
*
|
|
2291
2295
|
* Equivalent to Rust's `Envelope::validate_edge()`.
|
|
2292
2296
|
*
|
|
@@ -2294,15 +2298,31 @@ Envelope.prototype.edges = function() {
|
|
|
2294
2298
|
*/
|
|
2295
2299
|
Envelope.prototype.validateEdge = function() {
|
|
2296
2300
|
const inner = this.subject().isWrapped() ? this.subject().tryUnwrap() : this;
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
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();
|
|
2306
2326
|
};
|
|
2307
2327
|
/**
|
|
2308
2328
|
* Extracts the `'isA'` assertion object from an edge envelope.
|