capdag 1.361.331 → 1.363.10

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/capdag.js CHANGED
@@ -646,38 +646,38 @@ class CapUrn {
646
646
  }
647
647
 
648
648
  /**
649
- * Check if this cap (pattern/handler) accepts a request (instance).
649
+ * Whether `cap` fits this cap read as a PATTERN over caps — what a search
650
+ * asks: `cap`'s input is within this pattern's, its output covers the
651
+ * pattern's, its effect is the pattern's (a pattern's `?effect` fits any),
652
+ * and its cap-tags — complete: a cap has the tags it has — satisfy the
653
+ * pattern's.
650
654
  *
651
- * Direction (in/out) uses TaggedUrn.accepts()/conformsTo() (via MediaUrn matching):
652
- * - Input: capIn.accepts(requestIn) — cap's input spec is pattern, request's input is instance
653
- * - Output: capOut.conformsTo(requestOut) — cap's output is instance, request's output is pattern
654
- * For other tags:
655
- * - For each tag in the request: cap has same value, wildcard (*), or missing tag
656
- * - For each tag in the cap: if request is missing that tag, that's fine (cap is more specific)
657
- * Missing tags (except in/out) are treated as wildcards (less specific, can handle any value).
655
+ * A side the pattern leaves open is not asked about. `cap:candle` fits every
656
+ * cap tagged `candle`, whatever it takes and gives: its open output is "not
657
+ * established", not the type "anything".
658
658
  *
659
- * @param {CapUrn} request - The request cap to check
660
- * @returns {boolean} Whether this cap accepts the request
659
+ * Decided by the proved model (CapDAG.Exec.accepts, which is CapDAG.fits).
660
+ * For a question no cap URN can spell — "what gives this, whatever it
661
+ * takes" — ask a CapQuery.
662
+ *
663
+ * @param {CapUrn} cap - The cap to test against this pattern
664
+ * @returns {boolean} Whether the cap fits
661
665
  */
662
- accepts(request) {
663
- if (!request) {
666
+ accepts(cap) {
667
+ if (!cap) {
664
668
  return true;
665
669
  }
666
- // Decided by the proved model (CapDAG.Exec.accepts). The cap-tag axis runs
667
- // opposite to isDispatchable's: this is the pattern relation, dispatch is
668
- // the routing one.
669
- return model.accepts(this.formal, request.formal);
670
+ return model.accepts(this.formal, cap.formal);
670
671
  }
671
672
 
672
673
  /**
673
- * Check if this cap (instance) conforms to another cap (pattern).
674
- * Equivalent to cap.accepts(this).
674
+ * Whether this cap fits `pattern`: `pattern.accepts(this)`.
675
675
  *
676
- * @param {CapUrn} cap - The cap to check conformance against
677
- * @returns {boolean} Whether this cap conforms to the given cap
676
+ * @param {CapUrn} pattern
677
+ * @returns {boolean}
678
678
  */
679
- conformsTo(cap) {
680
- return cap.accepts(this);
679
+ conformsTo(pattern) {
680
+ return pattern.accepts(this);
681
681
  }
682
682
 
683
683
  /**
@@ -861,21 +861,64 @@ class CapUrn {
861
861
  }
862
862
 
863
863
  /**
864
- * Check if this candidate can dispatch the given request.
864
+ * Whether this candidate SERVES `request` — the predicate routing and
865
+ * dispatch act on.
866
+ *
867
+ * The candidate takes at least what the request sends, gives at least what
868
+ * the request needs, has the effect asked for unless the request says
869
+ * `?effect`, and has the cap-tags asked for — its own tags being complete, so
870
+ * a request for `!x` is served by a candidate that does not mention `x`, and
871
+ * a candidate may carry tags the request does not ask about.
872
+ *
873
+ * An input the request leaves open is not established: the caller has not
874
+ * said what it will send, and every candidate passes that side. That is
875
+ * "some input", not "any input" — `media:` on a CANDIDATE's input does mean
876
+ * it takes anything.
877
+ *
878
+ * This is a guarantee. What only could serve does not; see mayDispatch and
879
+ * CapQuery.grade. Decided by the proved model (CapDAG.Exec.dispatch, which is
880
+ * CapDAG.serves). Not symmetric.
865
881
  *
866
882
  * @param {CapUrn} request
867
883
  * @returns {boolean}
868
884
  */
869
885
  isDispatchable(request) {
870
- // Decided by the proved model (CapDAG.Exec.dispatch): every axis is a type.
871
- // The request's input refines the candidate's, the candidate's output
872
- // refines the request's, the effect matches unless the request says
873
- // ?effect, and the candidate's cap-tags refine the request's. `media:` on
874
- // a request's input is a type — "may send anything" — so only a candidate
875
- // that accepts anything serves it, which is what makes dispatch compose.
876
886
  return model.dispatch(this.formal, request.formal);
877
887
  }
878
888
 
889
+ /**
890
+ * Whether this candidate COULD serve `request`: not guaranteed, not
891
+ * excluded. For exploring what the fabric might do — never for routing a
892
+ * call, which must be served.
893
+ *
894
+ * @param {CapUrn} request
895
+ * @returns {boolean}
896
+ */
897
+ mayDispatch(request) {
898
+ return model.mayDispatch(this.formal, request.formal);
899
+ }
900
+
901
+ /**
902
+ * Whether what this cap gives, `next` takes: the edge of a route.
903
+ *
904
+ * @param {CapUrn} next
905
+ * @returns {boolean}
906
+ */
907
+ flowsInto(next) {
908
+ return model.flows(this.formal, next.formal);
909
+ }
910
+
911
+ /**
912
+ * Whether what this cap gives COULD be something `next` takes: an edge a
913
+ * search may explore and a run has to check.
914
+ *
915
+ * @param {CapUrn} next
916
+ * @returns {boolean}
917
+ */
918
+ mayFlowInto(next) {
919
+ return model.mayFlow(this.formal, next.formal);
920
+ }
921
+
879
922
  /**
880
923
  * Infer the runtime output media for a concrete runtime input.
881
924
  *
@@ -886,7 +929,9 @@ class CapUrn {
886
929
  const declaredIn = this.inMediaUrn();
887
930
  const declaredOut = this.outMediaUrn();
888
931
 
889
- if (!runtimeInput.conformsTo(declaredIn)) {
932
+ // A runtime media URN is the media of a value that exists, so it is read
933
+ // complete: it SATISFIES the declared type, or does not.
934
+ if (!runtimeInput.satisfies(declaredIn)) {
890
935
  throw new CapUrnError(
891
936
  ErrorCodes.INVALID_EFFECT_APPLICATION,
892
937
  `Runtime input '${runtimeInput}' does not conform to declared input '${declaredIn}'`
@@ -918,7 +963,7 @@ class CapUrn {
918
963
  );
919
964
  }
920
965
 
921
- if (!runtimeOut.conformsTo(declaredOut)) {
966
+ if (!runtimeOut.satisfies(declaredOut)) {
922
967
  throw new CapUrnError(
923
968
  ErrorCodes.INVALID_EFFECT_APPLICATION,
924
969
  `Inferred runtime output '${runtimeOut}' does not conform to declared output '${declaredOut}'`
@@ -962,7 +1007,7 @@ class CapUrn {
962
1007
  case CapEffect.PATCH:
963
1008
  return runtimeOutput.isEquivalent(inferred);
964
1009
  case CapEffect.DECLARED:
965
- return runtimeOutput.conformsTo(inferred);
1010
+ return runtimeOutput.satisfies(inferred);
966
1011
  default:
967
1012
  throw new CapUrnError(
968
1013
  ErrorCodes.INVALID_EFFECT_APPLICATION,
@@ -1106,6 +1151,109 @@ class CapUrnBuilder {
1106
1151
  }
1107
1152
  }
1108
1153
 
1154
+ /**
1155
+ * How a registered cap answers a CapQuery.
1156
+ *
1157
+ * - EXACT: guaranteed, and exactly what was asked on every side that was asked.
1158
+ * - GUARANTEED: whatever the cap takes and gives, it is what was asked.
1159
+ * - POSSIBLE: not guaranteed and not excluded — only running it tells. For
1160
+ * exploring; a call is never routed on it.
1161
+ * - NONE: excluded.
1162
+ */
1163
+ const MatchGrade = Object.freeze({
1164
+ EXACT: 'exact',
1165
+ GUARANTEED: 'guaranteed',
1166
+ POSSIBLE: 'possible',
1167
+ NONE: 'none',
1168
+ });
1169
+
1170
+ /** Whether routing may act on a grade. */
1171
+ function gradeIsGuaranteed(grade) {
1172
+ return grade === MatchGrade.EXACT || grade === MatchGrade.GUARANTEED;
1173
+ }
1174
+
1175
+ /** The cap-tag pattern a query asks for: `cap:` with these tags (none asks for none). */
1176
+ function queryTagPattern(tags) {
1177
+ return modelUrn(new TaggedUrn('cap', { ...(tags || {}) }));
1178
+ }
1179
+
1180
+ /**
1181
+ * A question about caps.
1182
+ *
1183
+ * A request is not a cap. A cap takes this and gives that; a request is a
1184
+ * QUESTION about caps, and may leave a side unasked: "what gives me this file,
1185
+ * whatever it takes?", "what can this input become?". Those are not cap URNs
1186
+ * with `media:` on a side — `media:` is the type "anything", a claim about
1187
+ * every input — they are queries with that side unknown.
1188
+ *
1189
+ * A cap URN read as a request or as a pattern is one (fromRequest, fromPattern)
1190
+ * — which is what CapUrn.isDispatchable and CapUrn.accepts ask — and so are the
1191
+ * questions no cap URN can spell (producing, consuming, between). Every answer
1192
+ * is decided by the proved model (formal/CapDAG/Query.lean).
1193
+ */
1194
+ class CapQuery {
1195
+ constructor(formal, asked) {
1196
+ Object.defineProperty(this, 'formal', { value: formal, enumerable: false });
1197
+ this.asked = asked;
1198
+ Object.freeze(this);
1199
+ }
1200
+
1201
+ toString() {
1202
+ return this.asked;
1203
+ }
1204
+
1205
+ /** The cap URN `request`, read as a request: an input it leaves open is not established. */
1206
+ static fromRequest(request) {
1207
+ return new CapQuery(model.queryOfRequest(request.formal), `request ${request}`);
1208
+ }
1209
+
1210
+ /** The cap URN `pattern`, read as a pattern over caps: an output it leaves open is not established. */
1211
+ static fromPattern(pattern) {
1212
+ return new CapQuery(model.queryOfPattern(pattern.formal), `pattern ${pattern}`);
1213
+ }
1214
+
1215
+ /** Caps that GIVE `output`, whatever they take, with the cap-tags `tags` asks for. */
1216
+ static producing(output, tags) {
1217
+ return new CapQuery(
1218
+ model.queryProducing(modelUrn(output._urn), queryTagPattern(tags)),
1219
+ `anything giving ${output}`);
1220
+ }
1221
+
1222
+ /** Caps that TAKE `input`, whatever they give: what this input can become in one step. */
1223
+ static consuming(input, tags) {
1224
+ return new CapQuery(
1225
+ model.queryConsuming(modelUrn(input._urn), queryTagPattern(tags)),
1226
+ `anything taking ${input}`);
1227
+ }
1228
+
1229
+ /** Caps that take `input` and give `output`: nothing unknown. */
1230
+ static between(input, output, tags) {
1231
+ return new CapQuery(
1232
+ model.queryBetween(modelUrn(input._urn), modelUrn(output._urn), queryTagPattern(tags)),
1233
+ `anything taking ${input} and giving ${output}`);
1234
+ }
1235
+
1236
+ /** Whether `cap` is guaranteed to be what is asked. */
1237
+ admits(cap) {
1238
+ return model.queryAdmits(this.formal, cap.formal);
1239
+ }
1240
+
1241
+ /** Whether `cap` could be what is asked. */
1242
+ mayAdmit(cap) {
1243
+ return model.queryMayAdmit(this.formal, cap.formal);
1244
+ }
1245
+
1246
+ /** How `cap` answers: one of MatchGrade. */
1247
+ grade(cap) {
1248
+ const answer = model.queryGrade(this.formal, cap.formal);
1249
+ const grade = { exact: MatchGrade.EXACT, guaranteed: MatchGrade.GUARANTEED, possible: MatchGrade.POSSIBLE, none: MatchGrade.NONE }[answer.kind];
1250
+ if (grade === undefined) {
1251
+ throw new Error(`capdag: the model answered with a grade this mirror does not know: ${JSON.stringify(answer)}`);
1252
+ }
1253
+ return grade;
1254
+ }
1255
+ }
1256
+
1109
1257
  /**
1110
1258
  * Cap Matcher utility class
1111
1259
  */
@@ -1615,6 +1763,34 @@ class MediaUrn {
1615
1763
  */
1616
1764
  accepts(instance) { return this._urn.accepts(instance._urn); }
1617
1765
 
1766
+ /**
1767
+ * Whether this media type and `other` COULD describe the same value: not a
1768
+ * guarantee (conformsTo), and not excluded. `media:ext` meets
1769
+ * `media:ext=pdf`; `media:ext=pdf` does not meet `media:ext=png`.
1770
+ * @param {MediaUrn} other
1771
+ * @returns {boolean}
1772
+ */
1773
+ meets(other) { return this._urn.meets(other._urn); }
1774
+
1775
+ /**
1776
+ * Whether a VALUE whose media this is satisfies the type `pattern`.
1777
+ *
1778
+ * conformsTo compares two types, and a type that does not mention a key
1779
+ * says nothing about it. A value that exists is complete: the tags it does
1780
+ * not have, it does not have. Use this where the receiver is the media of
1781
+ * actual data — a stream that arrived, an output that was produced.
1782
+ * @param {MediaUrn} pattern
1783
+ * @returns {boolean}
1784
+ */
1785
+ satisfies(pattern) { return this._urn.satisfies(pattern._urn); }
1786
+
1787
+ /**
1788
+ * Whether a value whose media this is COULD satisfy `pattern`.
1789
+ * @param {MediaUrn} pattern
1790
+ * @returns {boolean}
1791
+ */
1792
+ maySatisfy(pattern) { return this._urn.maySatisfy(pattern._urn); }
1793
+
1618
1794
  /** @returns {number} Specificity score (tag count based) */
1619
1795
  specificity() { return this._urn.specificity(); }
1620
1796
 
@@ -2720,13 +2896,14 @@ class Cap {
2720
2896
  }
2721
2897
 
2722
2898
  /**
2723
- * Check if this capability accepts a request string
2899
+ * Whether this capability, as a candidate, can serve the request
2900
+ * (CapUrn.isDispatchable).
2724
2901
  * @param {string} request - The request string
2725
- * @returns {boolean} Whether this capability accepts the request
2902
+ * @returns {boolean} Whether this capability serves the request
2726
2903
  */
2727
2904
  acceptsRequest(request) {
2728
2905
  const requestUrn = CapUrn.fromString(request);
2729
- return this.urn.accepts(requestUrn);
2906
+ return this.urn.isDispatchable(requestUrn);
2730
2907
  }
2731
2908
 
2732
2909
  /**
@@ -5343,16 +5520,17 @@ class CartridgeRepoServer {
5343
5520
  }
5344
5521
 
5345
5522
  /**
5346
- * Get cartridges that provide a specific cap.
5523
+ * Get every cartridge with a cap that can SERVE the requested URN.
5347
5524
  *
5348
- * The request URN is parsed via CapUrn.fromString. Each declared
5349
- * cartridge cap is parsed and matched with `conformsTo`: cap dispatch
5350
- * is the partial-order question "does the declared cap conform to
5351
- * (i.e. refine, equal, or be more specific than) the requested
5352
- * pattern?". Only `in` and `out` tags are semantically meaningful —
5353
- * no string comparison, no special role for the `op` tag. A malformed
5354
- * input URN throws; a malformed declared URN in the registry also
5355
- * throws (registry corruption is not a fallback condition).
5525
+ * The request URN is parsed via CapUrn.fromString; each declared
5526
+ * cartridge cap is parsed too and asked `isDispatchable` — "can this
5527
+ * declared candidate serve the request?" (it takes at least what is
5528
+ * sent, gives at least what is needed, has the tags asked for; a side the
5529
+ * request leaves open is not asked about). This is deliberately looser
5530
+ * than the equivalence used to resolve an alias to its exact cap: here
5531
+ * everything capable is enumerated. A malformed input URN throws; a
5532
+ * malformed declared URN in the registry also throws (registry corruption
5533
+ * is not a fallback condition).
5356
5534
  */
5357
5535
  getCartridgesByCap(capUrn) {
5358
5536
  const requested = CapUrn.fromString(capUrn);
@@ -5361,7 +5539,7 @@ class CartridgeRepoServer {
5361
5539
  (p.cap_groups || []).some(g =>
5362
5540
  (g.caps || []).some(c => {
5363
5541
  const declared = CapUrn.fromString(c.urn);
5364
- return declared.conformsTo(requested);
5542
+ return declared.isDispatchable(requested);
5365
5543
  })
5366
5544
  )
5367
5545
  );
@@ -8438,6 +8616,9 @@ export {
8438
8616
  CapEffect,
8439
8617
  CapUrnBuilder,
8440
8618
  CapMatcher,
8619
+ CapQuery,
8620
+ MatchGrade,
8621
+ gradeIsGuaranteed,
8441
8622
  CapUrnError,
8442
8623
  ErrorCodes,
8443
8624
  MediaUrn,
package/formal/index.d.ts CHANGED
@@ -19,6 +19,30 @@ export type Effect =
19
19
  ;
20
20
  export function effectType(): L.Type<Effect>;
21
21
 
22
+ /** Lean's CapDAG.Exec.WfQuery. */
23
+ export interface WfQuery {
24
+ readonly input: WfAsk;
25
+ readonly output: WfAsk;
26
+ readonly tags: Wf;
27
+ readonly effect: Effect;
28
+ }
29
+ export function wfQueryType(): L.Type<WfQuery>;
30
+
31
+ /** Lean's TaggedUrn.Exec.Wf, held by handle: only the program's functions make and read its values. */
32
+ export class Wf extends L.Opaque {
33
+ private constructor();
34
+ }
35
+ export function wfType(): L.Type<Wf>;
36
+
37
+ /** Lean's CapDAG.Grade. */
38
+ export type Grade =
39
+ | { readonly kind: "exact" }
40
+ | { readonly kind: "guaranteed" }
41
+ | { readonly kind: "possible" }
42
+ | { readonly kind: "none" }
43
+ ;
44
+ export function gradeType(): L.Type<Grade>;
45
+
22
46
  /** Lean's TaggedUrn.Constraint. */
23
47
  export type Constraint =
24
48
  | { readonly kind: "missing" }
@@ -31,11 +55,14 @@ export type Constraint =
31
55
  ;
32
56
  export function constraintType(): L.Type<Constraint>;
33
57
 
34
- /** Lean's TaggedUrn.Exec.Wf, held by handle: only the program's functions make and read its values. */
35
- export class Wf extends L.Opaque {
36
- private constructor();
37
- }
38
- export function wfType(): L.Type<Wf>;
58
+ /** Lean's CapDAG.Exec.WfAsk. */
59
+ export type WfAsk =
60
+ | { readonly kind: "unknown" }
61
+ | { readonly kind: "within"; readonly u: Wf }
62
+ | { readonly kind: "covers"; readonly u: Wf }
63
+ | { readonly kind: "same"; readonly u: Wf }
64
+ ;
65
+ export function wfAskType(): L.Type<WfAsk>;
39
66
 
40
67
  /** The layout fingerprint and descriptor of each type, by Lean name, for modules using them. */
41
68
  export const leanTypes: {
@@ -46,7 +73,7 @@ export const leanTypes: {
46
73
  export class CapdagFormal {
47
74
  private constructor();
48
75
  /** Lean's CapDAG.Exec.accepts : CapDAG.Exec.WfCap → CapDAG.Exec.WfCap → Bool */
49
- accepts(pattern: WfCap, request: WfCap): boolean;
76
+ accepts(pattern: WfCap, cap: WfCap): boolean;
50
77
  /** Lean's CapDAG.Exec.comparable : CapDAG.Exec.WfCap → CapDAG.Exec.WfCap → Bool */
51
78
  comparable(a: WfCap, b: WfCap): boolean;
52
79
  /** Lean's CapDAG.Exec.dispatch : CapDAG.Exec.WfCap → CapDAG.Exec.WfCap → Bool */
@@ -55,6 +82,28 @@ export class CapdagFormal {
55
82
  effectOk(candidate: Effect, request: Effect): boolean;
56
83
  /** Lean's CapDAG.Exec.equivalent : CapDAG.Exec.WfCap → CapDAG.Exec.WfCap → Bool */
57
84
  equivalent(a: WfCap, b: WfCap): boolean;
85
+ /** Lean's CapDAG.Exec.flows : CapDAG.Exec.WfCap → CapDAG.Exec.WfCap → Bool */
86
+ flows(a: WfCap, b: WfCap): boolean;
87
+ /** Lean's CapDAG.Exec.mayDispatch : CapDAG.Exec.WfCap → CapDAG.Exec.WfCap → Bool */
88
+ mayDispatch(candidate: WfCap, request: WfCap): boolean;
89
+ /** Lean's CapDAG.Exec.mayFlow : CapDAG.Exec.WfCap → CapDAG.Exec.WfCap → Bool */
90
+ mayFlow(a: WfCap, b: WfCap): boolean;
91
+ /** Lean's CapDAG.Exec.queryAdmits : CapDAG.Exec.WfQuery → CapDAG.Exec.WfCap → Bool */
92
+ queryAdmits(q: WfQuery, c: WfCap): boolean;
93
+ /** Lean's CapDAG.Exec.queryBetween : TaggedUrn.Exec.Wf → TaggedUrn.Exec.Wf → TaggedUrn.Exec.Wf → CapDAG.Exec.WfQuery */
94
+ queryBetween(input: Wf, output: Wf, tags: Wf): WfQuery;
95
+ /** Lean's CapDAG.Exec.queryConsuming : TaggedUrn.Exec.Wf → TaggedUrn.Exec.Wf → CapDAG.Exec.WfQuery */
96
+ queryConsuming(input: Wf, tags: Wf): WfQuery;
97
+ /** Lean's CapDAG.Exec.queryGrade : CapDAG.Exec.WfQuery → CapDAG.Exec.WfCap → CapDAG.Grade */
98
+ queryGrade(q: WfQuery, c: WfCap): Grade;
99
+ /** Lean's CapDAG.Exec.queryMayAdmit : CapDAG.Exec.WfQuery → CapDAG.Exec.WfCap → Bool */
100
+ queryMayAdmit(q: WfQuery, c: WfCap): boolean;
101
+ /** Lean's CapDAG.Exec.queryOfPattern : CapDAG.Exec.WfCap → CapDAG.Exec.WfQuery */
102
+ queryOfPattern(p: WfCap): WfQuery;
103
+ /** Lean's CapDAG.Exec.queryOfRequest : CapDAG.Exec.WfCap → CapDAG.Exec.WfQuery */
104
+ queryOfRequest(r_: WfCap): WfQuery;
105
+ /** Lean's CapDAG.Exec.queryProducing : TaggedUrn.Exec.Wf → TaggedUrn.Exec.Wf → CapDAG.Exec.WfQuery */
106
+ queryProducing(output: Wf, tags: Wf): WfQuery;
58
107
  /** Lean's CapDAG.Exec.rankingKey : CapDAG.Exec.WfCap → CapDAG.Exec.WfCap → Nat × Nat */
59
108
  rankingKey(candidate: WfCap, request: WfCap): [bigint, bigint];
60
109
  /** Lean's CapDAG.Exec.select : List CapDAG.Exec.WfCap → CapDAG.Exec.WfCap → Option CapDAG.Exec.WfCap */
package/formal/index.js CHANGED
@@ -68,10 +68,81 @@ export function effectType() {
68
68
  );
69
69
  }
70
70
 
71
+ /** Describes CapDAG.Exec.WfQuery for polymorphic functions. */
72
+ export function wfQueryType() {
73
+ return new L.Type(
74
+ L.inductiveExpr(2),
75
+ (w, v) => {
76
+ if (typeof v !== "object" || v === null) throw new L.MalformedError("not a CapDAG.Exec.WfQuery");
77
+ w.u32(0);
78
+ wfAskType().encode(w, v.input);
79
+ wfAskType().encode(w, v.output);
80
+ wfType().encode(w, v.tags);
81
+ effectType().encode(w, v.effect);
82
+ },
83
+ (r) => {
84
+ const c = r.u32();
85
+ if (c !== 0) throw new L.MalformedError(`constructor index ${c} of CapDAG.Exec.WfQuery`);
86
+ return ({ input: wfAskType().decode(r), output: wfAskType().decode(r), tags: wfType().decode(r), effect: effectType().decode(r) });
87
+ },
88
+ );
89
+ }
90
+
91
+ /** Lean's TaggedUrn.Exec.Wf, held by handle: only the program's functions make and read its values. */
92
+ export class Wf extends L.Opaque {}
93
+
94
+ /** Describes TaggedUrn.Exec.Wf for polymorphic functions. */
95
+ export function wfType() {
96
+ return new L.Type(
97
+ L.inductiveExpr(3),
98
+ (w, v) => {
99
+ if (!(v instanceof Wf)) throw new L.MalformedError("not a TaggedUrn.Exec.Wf");
100
+ L.OPAQUE.encode(w, v);
101
+ },
102
+ (r) => new Wf(r.program, r.u64()),
103
+ );
104
+ }
105
+
106
+ /** Describes CapDAG.Grade for polymorphic functions. */
107
+ export function gradeType() {
108
+ return new L.Type(
109
+ L.inductiveExpr(4),
110
+ (w, v) => {
111
+ if (typeof v !== "object" || v === null) throw new L.MalformedError("not a CapDAG.Grade");
112
+ switch (v.kind) {
113
+ case "exact":
114
+ w.u32(0);
115
+ return;
116
+ case "guaranteed":
117
+ w.u32(1);
118
+ return;
119
+ case "possible":
120
+ w.u32(2);
121
+ return;
122
+ case "none":
123
+ w.u32(3);
124
+ return;
125
+ default:
126
+ throw new L.MalformedError(`${String(v.kind)} is not a constructor of CapDAG.Grade`);
127
+ }
128
+ },
129
+ (r) => {
130
+ const c = r.u32();
131
+ switch (c) {
132
+ case 0: return ({ kind: "exact" });
133
+ case 1: return ({ kind: "guaranteed" });
134
+ case 2: return ({ kind: "possible" });
135
+ case 3: return ({ kind: "none" });
136
+ default: throw new L.MalformedError(`constructor index ${c} of CapDAG.Grade`);
137
+ }
138
+ },
139
+ );
140
+ }
141
+
71
142
  /** Describes TaggedUrn.Constraint for polymorphic functions. */
72
143
  export function constraintType() {
73
144
  return new L.Type(
74
- L.inductiveExpr(2),
145
+ L.inductiveExpr(5),
75
146
  (w, v) => {
76
147
  if (typeof v !== "object" || v === null) throw new L.MalformedError("not a TaggedUrn.Constraint");
77
148
  switch (v.kind) {
@@ -119,18 +190,42 @@ export function constraintType() {
119
190
  );
120
191
  }
121
192
 
122
- /** Lean's TaggedUrn.Exec.Wf, held by handle: only the program's functions make and read its values. */
123
- export class Wf extends L.Opaque {}
124
-
125
- /** Describes TaggedUrn.Exec.Wf for polymorphic functions. */
126
- export function wfType() {
193
+ /** Describes CapDAG.Exec.WfAsk for polymorphic functions. */
194
+ export function wfAskType() {
127
195
  return new L.Type(
128
- L.inductiveExpr(3),
196
+ L.inductiveExpr(6),
129
197
  (w, v) => {
130
- if (!(v instanceof Wf)) throw new L.MalformedError("not a TaggedUrn.Exec.Wf");
131
- L.OPAQUE.encode(w, v);
198
+ if (typeof v !== "object" || v === null) throw new L.MalformedError("not a CapDAG.Exec.WfAsk");
199
+ switch (v.kind) {
200
+ case "unknown":
201
+ w.u32(0);
202
+ return;
203
+ case "within":
204
+ w.u32(1);
205
+ wfType().encode(w, v.u);
206
+ return;
207
+ case "covers":
208
+ w.u32(2);
209
+ wfType().encode(w, v.u);
210
+ return;
211
+ case "same":
212
+ w.u32(3);
213
+ wfType().encode(w, v.u);
214
+ return;
215
+ default:
216
+ throw new L.MalformedError(`${String(v.kind)} is not a constructor of CapDAG.Exec.WfAsk`);
217
+ }
218
+ },
219
+ (r) => {
220
+ const c = r.u32();
221
+ switch (c) {
222
+ case 0: return ({ kind: "unknown" });
223
+ case 1: return ({ kind: "within", u: wfType().decode(r) });
224
+ case 2: return ({ kind: "covers", u: wfType().decode(r) });
225
+ case 3: return ({ kind: "same", u: wfType().decode(r) });
226
+ default: throw new L.MalformedError(`constructor index ${c} of CapDAG.Exec.WfAsk`);
227
+ }
132
228
  },
133
- (r) => new Wf(r.program, r.u64()),
134
229
  );
135
230
  }
136
231
 
@@ -138,8 +233,11 @@ export function wfType() {
138
233
  export const leanTypes = Object.freeze({
139
234
  "CapDAG.Exec.WfCap": Object.freeze({ fingerprint: "2b8d6466d218f4ae6bc98d95bba55d98f21cac4a49446ae170993773cefdb830", type: wfCapType }),
140
235
  "CapDAG.Effect": Object.freeze({ fingerprint: "38c7bd3c0527cda156713cd441c9b6b92bd5df8a39108fa101449a789abcb477", type: effectType }),
141
- "TaggedUrn.Constraint": Object.freeze({ fingerprint: "481fc09e23c6415a7c3f05887577ec940a6ecc84b005e63476c1060b59edcac7", type: constraintType }),
236
+ "CapDAG.Exec.WfQuery": Object.freeze({ fingerprint: "e734861d70e3177f6563c4492990bb65131f0450b8dfc62071eb61b6c5f08b8e", type: wfQueryType }),
142
237
  "TaggedUrn.Exec.Wf": Object.freeze({ fingerprint: "20e9f81ad195b2f4a481e7a5dcae2b3d0de6efe7b3dc720db0e2aa3b52527785", type: wfType }),
238
+ "CapDAG.Grade": Object.freeze({ fingerprint: "0a2a20a14d9ecca6121343df2d8a7f2478b3e837710ed522ed385d35efdf46f2", type: gradeType }),
239
+ "TaggedUrn.Constraint": Object.freeze({ fingerprint: "481fc09e23c6415a7c3f05887577ec940a6ecc84b005e63476c1060b59edcac7", type: constraintType }),
240
+ "CapDAG.Exec.WfAsk": Object.freeze({ fingerprint: "d286477c7abc4e6bc6ee2d06889372b71a5bb06605b592ebabb6ad3eaf71b952", type: wfAskType }),
143
241
  });
144
242
 
145
243
  /** The Lean program capdagFormal. */
@@ -148,8 +246,8 @@ export class CapdagFormal {
148
246
  constructor(program) {
149
247
  this.#program = program;
150
248
  }
151
- accepts(pattern, request) {
152
- return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_daccepts", [], [[wfCapType(), pattern], [wfCapType(), request]], L.value(L.BOOL));
249
+ accepts(pattern, cap) {
250
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_daccepts", [], [[wfCapType(), pattern], [wfCapType(), cap]], L.value(L.BOOL));
153
251
  }
154
252
  comparable(a, b) {
155
253
  return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dcomparable", [], [[wfCapType(), a], [wfCapType(), b]], L.value(L.BOOL));
@@ -163,6 +261,39 @@ export class CapdagFormal {
163
261
  equivalent(a, b) {
164
262
  return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dequivalent", [], [[wfCapType(), a], [wfCapType(), b]], L.value(L.BOOL));
165
263
  }
264
+ flows(a, b) {
265
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dflows", [], [[wfCapType(), a], [wfCapType(), b]], L.value(L.BOOL));
266
+ }
267
+ mayDispatch(candidate, request) {
268
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dmayDispatch", [], [[wfCapType(), candidate], [wfCapType(), request]], L.value(L.BOOL));
269
+ }
270
+ mayFlow(a, b) {
271
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dmayFlow", [], [[wfCapType(), a], [wfCapType(), b]], L.value(L.BOOL));
272
+ }
273
+ queryAdmits(q, c) {
274
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dqueryAdmits", [], [[wfQueryType(), q], [wfCapType(), c]], L.value(L.BOOL));
275
+ }
276
+ queryBetween(input, output, tags) {
277
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dqueryBetween", [], [[wfType(), input], [wfType(), output], [wfType(), tags]], L.value(wfQueryType()));
278
+ }
279
+ queryConsuming(input, tags) {
280
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dqueryConsuming", [], [[wfType(), input], [wfType(), tags]], L.value(wfQueryType()));
281
+ }
282
+ queryGrade(q, c) {
283
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dqueryGrade", [], [[wfQueryType(), q], [wfCapType(), c]], L.value(gradeType()));
284
+ }
285
+ queryMayAdmit(q, c) {
286
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dqueryMayAdmit", [], [[wfQueryType(), q], [wfCapType(), c]], L.value(L.BOOL));
287
+ }
288
+ queryOfPattern(p) {
289
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dqueryOfPattern", [], [[wfCapType(), p]], L.value(wfQueryType()));
290
+ }
291
+ queryOfRequest(r_) {
292
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dqueryOfRequest", [], [[wfCapType(), r_]], L.value(wfQueryType()));
293
+ }
294
+ queryProducing(output, tags) {
295
+ return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_dqueryProducing", [], [[wfType(), output], [wfType(), tags]], L.value(wfQueryType()));
296
+ }
166
297
  rankingKey(candidate, request) {
167
298
  return this.#program.invoke("capdagFormal__call_l_CapDAG_dExec_drankingKey", [], [[wfCapType(), candidate], [wfCapType(), request]], L.value(L.pair(L.NAT, L.NAT)));
168
299
  }
Binary file
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "dependencies": {
4
4
  "lungo-ts": "1.78.3254",
5
5
  "peggy": "^5.1.0",
6
- "tagged-urn": "^1.66.108"
6
+ "tagged-urn": "^1.68.11"
7
7
  },
8
8
  "description": "JavaScript implementation of Cap URN (Capability Uniform Resource Names) with strict validation and matching",
9
9
  "engines": {
@@ -50,5 +50,5 @@
50
50
  "test": "node capdag.test.js"
51
51
  },
52
52
  "type": "module",
53
- "version": "1.361.331"
53
+ "version": "1.363.10"
54
54
  }