@astrale-os/kernel-dsl 1.0.0-beta.31 → 1.0.0-beta.32

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 (69) hide show
  1. package/dist/v1/builder/callable/authoring.d.ts +2 -2
  2. package/dist/v1/builder/class/authoring.js +0 -1
  3. package/dist/v1/builder/class/input.d.ts +3 -5
  4. package/dist/v1/builder/index.d.ts +1 -1
  5. package/dist/v1/builder/lowering/class.js +0 -5
  6. package/dist/v1/builder/lowering/policy.js +24 -6
  7. package/dist/v1/builder/policy/authoring.d.ts +33 -7
  8. package/dist/v1/builder/policy/authoring.js +5 -2
  9. package/dist/v1/builder/policy/legacy/inputs.d.ts +8 -0
  10. package/dist/v1/builder/policy/legacy/inputs.js +1 -0
  11. package/dist/v1/compiled/admission/semantics/class.js +0 -15
  12. package/dist/v1/compiled/admission/semantics/context.d.ts +1 -2
  13. package/dist/v1/compiled/admission/semantics/policy/callable.js +2 -2
  14. package/dist/v1/compiled/admission/semantics/policy/parity.js +26 -3
  15. package/dist/v1/compiled/admission/semantics/policy/typing.js +2 -0
  16. package/dist/v1/compiled/admission/wire/class.js +1 -10
  17. package/dist/v1/compiled/admission/wire/policy.js +21 -1
  18. package/dist/v1/compiled/rule.js +0 -1
  19. package/dist/v1/domain/projection/classes.js +0 -8
  20. package/dist/v1/index.d.ts +1 -1
  21. package/dist/v1/language/callable/admission.js +5 -3
  22. package/dist/v1/language/class/model/class.d.ts +1 -2
  23. package/dist/v1/language/class/resolved.d.ts +0 -7
  24. package/dist/v1/language/index.d.ts +1 -2
  25. package/dist/v1/language/index.js +1 -1
  26. package/dist/v1/language/limits.d.ts +2 -0
  27. package/dist/v1/language/limits.js +2 -0
  28. package/dist/v1/language/policy/analysis/branches.d.ts +1 -1
  29. package/dist/v1/language/policy/analysis/branches.js +6 -0
  30. package/dist/v1/language/policy/analysis/budgets.d.ts +4 -2
  31. package/dist/v1/language/policy/analysis/budgets.js +18 -3
  32. package/dist/v1/language/policy/analysis/checks.d.ts +5 -2
  33. package/dist/v1/language/policy/analysis/checks.js +12 -11
  34. package/dist/v1/language/policy/analysis/typing.d.ts +15 -2
  35. package/dist/v1/language/policy/analysis/typing.js +106 -4
  36. package/dist/v1/language/policy/model/policy.d.ts +13 -0
  37. package/dist/v1/language/policy/model/policy.js +4 -0
  38. package/dist/v1/language/policy/normalization/normalize.js +9 -2
  39. package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +106 -16
  40. package/dist/v1/schema/analysis/class.d.ts +0 -8
  41. package/dist/v1/schema/analysis/class.js +0 -28
  42. package/dist/v1/schema/compatibility/comparators/classes.d.ts +1 -1
  43. package/dist/v1/schema/compatibility/comparators/classes.js +1 -11
  44. package/dist/v1/schema/compatibility/evidence.js +12 -2
  45. package/dist/v1/schema/compatibility/fields.d.ts +2 -2
  46. package/dist/v1/schema/compatibility/fields.js +1 -1
  47. package/dist/v1/schema/diagnostic.d.ts +1 -1
  48. package/dist/v1/schema/enforcement/changes.d.ts +0 -6
  49. package/dist/v1/schema/enforcement/changes.js +0 -6
  50. package/dist/v1/schema/enforcement/derived.d.ts +0 -6
  51. package/dist/v1/schema/enforcement/derived.js +0 -6
  52. package/dist/v1/schema/enforcement/fields.d.ts +0 -1
  53. package/dist/v1/schema/enforcement/fields.js +0 -1
  54. package/dist/v1/schema/enforcement/write.d.ts +0 -7
  55. package/dist/v1/schema/enforcement/write.js +0 -7
  56. package/dist/v1/schema/normalization/domain.js +1 -1
  57. package/dist/v1/schema/resolution/origins.js +7 -2
  58. package/dist/v1/schema/rule.js +3 -7
  59. package/dist/v1/schema/validation/domain.structure.d.ts +5 -3
  60. package/dist/v1/schema/validation/domain.structure.js +3 -5
  61. package/dist/v1/schema/validation/policy/budgets.js +2 -1
  62. package/dist/v1/schema/validation/policy/context.d.ts +1 -0
  63. package/dist/v1/schema/validation/policy/context.js +3 -0
  64. package/dist/v1/schema/validation/policy/references.js +4 -1
  65. package/dist/v1/schema/validation/policy/typing.js +6 -0
  66. package/dist/v1/schema/validation/policy/uses.js +24 -2
  67. package/package.json +1 -1
  68. package/dist/v1/language/class/model/data.d.ts +0 -11
  69. package/dist/v1/language/class/model/data.js +0 -2
@@ -42,6 +42,8 @@ export declare const limits: Readonly<{
42
42
  * (`STRUCTURE_MAXIMUM`).
43
43
  */
44
44
  policy: Readonly<{
45
+ /** Named Nodes connected to the subject within a normalized branch. */
46
+ inputs: 6;
45
47
  /**
46
48
  * Levels of a Policy pattern: an Edge or sameNode is one, and each allOf, anyOf, exists and
47
49
  * composition adds one.
@@ -42,6 +42,8 @@ export const limits = Object.freeze({
42
42
  * (`STRUCTURE_MAXIMUM`).
43
43
  */
44
44
  policy: Object.freeze({
45
+ /** Named Nodes connected to the subject within a normalized branch. */
46
+ inputs: 6,
45
47
  /**
46
48
  * Levels of a Policy pattern: an Edge or sameNode is one, and each allOf, anyOf, exists and
47
49
  * composition adds one.
@@ -11,7 +11,7 @@ export interface PatternEdgeUse {
11
11
  readonly pattern: PolicyEdgePattern;
12
12
  readonly namespace: string;
13
13
  }
14
- export type PolicyTargetMode = 'object' | 'edge';
14
+ export type PolicyTargetMode = 'object' | 'edge' | 'named';
15
15
  export declare function branchesOf(pattern: PolicyPatternExpression, namespace: string): readonly PatternBranch[];
16
16
  export declare function branchProduct(children: readonly (readonly PatternBranch[])[]): readonly PatternBranch[];
17
17
  export declare function capBranches(values: readonly PatternBranch[]): readonly PatternBranch[];
@@ -44,14 +44,18 @@ export function isConnected(branch) {
44
44
  return [...vertices].every((vertex) => union.find(vertex) === root);
45
45
  }
46
46
  export function targetMode(branch) {
47
+ let named = false;
47
48
  let object = false;
48
49
  let source = false;
49
50
  let target = false;
50
51
  for (const term of branch.terms.values()) {
52
+ named ||= term.kind === 'input';
51
53
  object ||= term.kind === 'object';
52
54
  source ||= term.kind === 'source';
53
55
  target ||= term.kind === 'target';
54
56
  }
57
+ if (named)
58
+ return object || source || target ? undefined : 'named';
55
59
  if (object && !source && !target)
56
60
  return 'object';
57
61
  if (!object && (source || target))
@@ -59,6 +63,8 @@ export function targetMode(branch) {
59
63
  return undefined;
60
64
  }
61
65
  export function termKey(term, namespace) {
66
+ if (term.kind === 'input')
67
+ return 'input:' + term.name;
62
68
  return term.kind === 'variable'
63
69
  ? variableKey(namespace, term.id)
64
70
  : term.kind === 'ref'
@@ -1,4 +1,4 @@
1
- import type { PolicyRef } from '../../../addressing/index.js';
1
+ import type { ClassRef, PolicyRef } from '../../../addressing/index.js';
2
2
  import type { PolicyCheckExpression, PolicyExpression } from '../model/policy.js';
3
3
  import { limits } from '../../limits.js';
4
4
  /** A key of `limits.policy`. */
@@ -15,6 +15,8 @@ export declare const BRANCH_OVERFLOW: number;
15
15
  * it counted only. The other counts are exact.
16
16
  */
17
17
  export interface PolicyMeasure {
18
+ /** Named Nodes supplied by a use site. */
19
+ readonly inputs: number;
18
20
  /** Levels of the expanded pattern. */
19
21
  readonly patternDepth: number;
20
22
  /** Branches of its normal form, at most `limits.policy.normalizedBranches + 1`. */
@@ -44,6 +46,6 @@ export declare function exceededLimits<Measure extends PolicyMeasure | CheckMeas
44
46
  * measure when it is not normalized, when its expansion reaches itself, or when a composition names
45
47
  * a Policy `isLocal` refuses or one without a measure.
46
48
  */
47
- export declare function policyMeasurer(origin: string, normalized: ReadonlyMap<string, PolicyExpression>, isLocal: (ref: PolicyRef) => boolean): (name: string) => PolicyMeasure | undefined;
49
+ export declare function policyMeasurer(origin: string, normalized: ReadonlyMap<string, PolicyExpression>, isLocal: (ref: PolicyRef) => boolean, inputOf: (name: string) => Readonly<Record<string, ClassRef>> | undefined): (name: string) => PolicyMeasure | undefined;
48
50
  /** Measure one normalized check tree. */
49
51
  export declare function measureChecks(expression: PolicyCheckExpression): CheckMeasure;
@@ -16,7 +16,7 @@ export function exceededLimits(measure) {
16
16
  * measure when it is not normalized, when its expansion reaches itself, or when a composition names
17
17
  * a Policy `isLocal` refuses or one without a measure.
18
18
  */
19
- export function policyMeasurer(origin, normalized, isLocal) {
19
+ export function policyMeasurer(origin, normalized, isLocal, inputOf) {
20
20
  // Measure every distinct composition node once. A node's expanded measure is independent of the
21
21
  // path that reaches it (the only path-sensitive outcome, the back-edge `undefined`, already holds
22
22
  // for every node on or reaching a composition cycle, regardless of entry), so caching the
@@ -33,7 +33,18 @@ export function policyMeasurer(origin, normalized, isLocal) {
33
33
  if (declaration === undefined)
34
34
  return undefined;
35
35
  visiting.add(name);
36
- const measure = yield* measureDeclaration(declaration);
36
+ const pattern = yield* measureDeclaration(declaration);
37
+ const formals = inputOf(name);
38
+ const measure = pattern && formals
39
+ ? {
40
+ ...pattern,
41
+ inputs: Object.keys(formals).length,
42
+ domains: new Set([
43
+ ...pattern.domains,
44
+ ...Object.values(formals).map((ref) => ref.origin),
45
+ ]),
46
+ }
47
+ : pattern;
37
48
  visiting.delete(name);
38
49
  measures.set(name, measure);
39
50
  return measure;
@@ -52,13 +63,17 @@ export function policyMeasurer(origin, normalized, isLocal) {
52
63
  }
53
64
  if (children.length !== refs.length || children.length === 0)
54
65
  return undefined;
55
- return combineMeasures(operator, children);
66
+ return {
67
+ ...combineMeasures(operator, children),
68
+ inputs: Math.max(...children.map((child) => child.inputs ?? 0)),
69
+ };
56
70
  }
57
71
  return (name) => {
58
72
  const measure = runSuspended(measurePolicy(name));
59
73
  return measure === undefined
60
74
  ? undefined
61
75
  : {
76
+ inputs: measure.inputs ?? 0,
62
77
  patternDepth: measure.depth,
63
78
  normalizedBranches: measure.edgeCounts.length,
64
79
  edgePredicates: Math.max(0, ...measure.edgeCounts),
@@ -1,14 +1,17 @@
1
- import type { PolicyCheckExpression } from '../model/policy.js';
1
+ import type { PolicyCheckExpression, PolicyCheckObject } from '../model/policy.js';
2
2
  export type PolicyCheckLeaf = Extract<PolicyCheckExpression, {
3
3
  readonly check: unknown;
4
4
  }>;
5
5
  /** How one check leaf types against the Classes its object accepts. */
6
6
  export interface CheckLeafClasses {
7
+ readonly object: PolicyCheckObject;
7
8
  /** Every Class the leaf's object accepts. */
8
9
  readonly accepted: readonly string[];
9
10
  /** The accepted Classes at least one normalized branch of the leaf's Policy is typed for. */
10
11
  readonly admitted: ReadonlySet<string>;
11
12
  }
13
+ /** Names a callable check object. Every leaf over one object sees the same Node at runtime. */
14
+ export declare function checkObjectName(object: PolicyCheckObject): string;
12
15
  /**
13
16
  * The Classes a leaf admits, from the typing of each normalized branch of its Policy for each
14
17
  * accepted Class of its object. `undefined` when the Policy does not expand, or when one branch is
@@ -25,4 +28,4 @@ export declare function admittedCheckClasses(typing: ReadonlyMap<string, readonl
25
28
  * `sameNode` compares identities, not Classes, so it never removes a Class here. A tree over the
26
29
  * check budget is already refused, so it is not expanded.
27
30
  */
28
- export declare function neverAdmittedClasses(expression: PolicyCheckExpression, leaves: ReadonlyMap<PolicyCheckLeaf, CheckLeafClasses>): readonly (readonly [object: string, className: string])[];
31
+ export declare function neverAdmittedClasses(expression: PolicyCheckExpression, leaves: ReadonlyMap<PolicyCheckLeaf, readonly CheckLeafClasses[]>): readonly (readonly [object: string, className: string])[];
@@ -2,7 +2,7 @@ import { limits } from '../../limits.js';
2
2
  import { PolicyComposition, policyObjectKey } from '../model/policy.js';
3
3
  import { measureChecks } from './budgets.js';
4
4
  /** Names a callable check object. Every leaf over one object sees the same Node at runtime. */
5
- function checkObjectName(object) {
5
+ export function checkObjectName(object) {
6
6
  if (object.kind === 'self')
7
7
  return 'self';
8
8
  if (object.kind === 'input')
@@ -40,22 +40,23 @@ export function neverAdmittedClasses(expression, leaves) {
40
40
  if (measureChecks(expression).checkBranches > limits.policy.checkBranches)
41
41
  return [];
42
42
  const accepted = new Map();
43
- for (const [leaf, classes] of leaves)
44
- accepted.set(checkObjectName(leaf.object), classes.accepted);
43
+ for (const operands of leaves.values()) {
44
+ for (const classes of operands)
45
+ accepted.set(checkObjectName(classes.object), classes.accepted);
46
+ }
45
47
  const admitted = new Map();
46
48
  for (const conjunction of disjunctiveForm(expression)) {
47
49
  const constrained = new Map();
48
50
  for (const leaf of conjunction) {
49
51
  if (!('check' in leaf))
50
52
  continue;
51
- const classes = leaves.get(leaf);
52
- if (classes === undefined)
53
- continue;
54
- const object = checkObjectName(leaf.object);
55
- const previous = constrained.get(object);
56
- constrained.set(object, previous === undefined
57
- ? classes.admitted
58
- : new Set([...previous].filter((name) => classes.admitted.has(name))));
53
+ for (const classes of leaves.get(leaf) ?? []) {
54
+ const object = checkObjectName(classes.object);
55
+ const previous = constrained.get(object);
56
+ constrained.set(object, previous === undefined
57
+ ? classes.admitted
58
+ : new Set([...previous].filter((name) => classes.admitted.has(name))));
59
+ }
59
60
  }
60
61
  if ([...constrained.values()].some((classes) => classes.size === 0))
61
62
  continue;
@@ -1,6 +1,6 @@
1
1
  import type { ClassRef, PolicyRef } from '../../../addressing/index.js';
2
2
  import type { EdgeContract } from '../../class/model/edge.js';
3
- import type { PolicyExpression, PolicyObjectRef } from '../model/policy.js';
3
+ import type { PolicyCheckObject, PolicyExpression, PolicyObjectRef } from '../model/policy.js';
4
4
  import type { CheckLeafClasses } from './checks.js';
5
5
  import { type ClassAncestry } from '../../class/inheritance.js';
6
6
  import { type PatternBranch } from './branches.js';
@@ -10,7 +10,14 @@ export type ObjectContract = {
10
10
  readonly kind: 'exact';
11
11
  readonly ref: ClassRef;
12
12
  };
13
+ type InputSignature = Readonly<Record<string, ClassRef>>;
14
+ type ActualContracts = Readonly<Record<string, readonly ObjectContract[]>>;
13
15
  export type PolicyUseContract = {
16
+ readonly kind: 'named';
17
+ readonly signature: InputSignature;
18
+ readonly actuals: ActualContracts;
19
+ readonly bindings?: Readonly<Record<string, PolicyCheckObject>>;
20
+ } | {
14
21
  readonly kind: 'object';
15
22
  readonly object: ObjectContract;
16
23
  } | {
@@ -20,6 +27,7 @@ export type PolicyUseContract = {
20
27
  };
21
28
  /** What Policy typing reads of the closure it types against: source or compiled admission. */
22
29
  export interface PolicyTypingScope {
30
+ inputOf?(name: string): InputSignature | undefined;
23
31
  readonly normalized: ReadonlyMap<string, PolicyExpression>;
24
32
  /** Each resolves, through `resolveClass`, to a Node Class. */
25
33
  readonly allNodeClasses: readonly ClassRef[];
@@ -38,6 +46,10 @@ export declare class PolicyTyping {
38
46
  constructor(scope: PolicyTypingScope);
39
47
  /** The normalized branches of a named Policy, `undefined` when it does not expand. */
40
48
  expandedBranches(name: string, namespace: string): readonly PatternBranch[] | undefined;
49
+ /** Compositions inherit the signature of their operands, checked at declaration admission. */
50
+ signature(name: string): InputSignature | undefined;
51
+ validDeclaration(name: string): boolean;
52
+ namedCheck(name: string, bindings: Readonly<Record<string, PolicyCheckObject>>, actuals: ActualContracts): readonly CheckLeafClasses[] | undefined;
41
53
  policyAccepts(name: string, object: ObjectContract): boolean;
42
54
  /** Whether the Policy accepts every concrete source and target pair the Edge Class accepts. */
43
55
  policyAcceptsEdgeClass(name: string, declaration: EdgeContract): boolean;
@@ -45,7 +57,8 @@ export declare class PolicyTyping {
45
57
  * How a check of the Policy types against each contract of its object, `undefined` when the
46
58
  * Policy does not expand or one of its branches is typed for no contract.
47
59
  */
48
- checkLeafClasses(name: string, contracts: readonly ObjectContract[]): CheckLeafClasses | undefined;
60
+ checkLeafClasses(name: string, contracts: readonly ObjectContract[]): Omit<CheckLeafClasses, 'object'> | undefined;
49
61
  endpointsOverlap(left: readonly ClassRef[], right: readonly ClassRef[]): boolean;
50
62
  branchIsTyped(branch: PatternBranch, use: PolicyUseContract): boolean;
51
63
  }
64
+ export {};
@@ -4,7 +4,7 @@ import { classSatisfies, isGraphRoot } from '../../class/inheritance.js';
4
4
  import { limits } from '../../limits.js';
5
5
  import { PolicyComposition } from '../model/policy.js';
6
6
  import { branchesOf, branchProduct, capBranches, targetMode, termKey, UnionFind, } from './branches.js';
7
- import { admittedCheckClasses } from './checks.js';
7
+ import { admittedCheckClasses, checkObjectName } from './checks.js';
8
8
  export class PolicyTyping {
9
9
  scope;
10
10
  // Expanded branches of each named Policy, cached by node identity. A Policy's expansion is reused
@@ -25,11 +25,74 @@ export class PolicyTyping {
25
25
  expandedBranches(name, namespace) {
26
26
  return this.#expandedBranches(name, new Set(), namespace);
27
27
  }
28
+ /** Compositions inherit the signature of their operands, checked at declaration admission. */
29
+ signature(name) {
30
+ const seen = new Set();
31
+ while (!seen.has(name)) {
32
+ seen.add(name);
33
+ const expression = this.scope.normalized.get(name);
34
+ if (expression === undefined || 'match' in expression)
35
+ return this.scope.inputOf?.(name);
36
+ name = PolicyComposition.of(expression).operands[0].name;
37
+ }
38
+ return undefined;
39
+ }
40
+ validDeclaration(name) {
41
+ const expression = this.scope.normalized.get(name);
42
+ if (!expression)
43
+ return false;
44
+ const signature = this.signature(name);
45
+ if (!('match' in expression)) {
46
+ if (this.scope.inputOf?.(name) !== undefined)
47
+ return false;
48
+ return PolicyComposition.of(expression).operands.every((ref) => {
49
+ const other = this.signature(ref.name);
50
+ if (!signature || !other)
51
+ return signature === other;
52
+ return (Object.keys(signature).length === Object.keys(other).length &&
53
+ Object.entries(signature).every(([key, cls]) => Object.hasOwn(other, key) &&
54
+ definitionRefIndex(cls) === definitionRefIndex(other[key])));
55
+ });
56
+ }
57
+ if (signature &&
58
+ (Object.keys(signature).length === 0 || Object.keys(signature).length > limits.policy.inputs))
59
+ return false;
60
+ return branchesOf(expression.match, name).every((branch) => {
61
+ if (!signature)
62
+ return targetMode(branch) !== 'named';
63
+ return this.branchIsTyped(branch, { kind: 'named', signature, actuals: {} });
64
+ });
65
+ }
66
+ namedCheck(name, bindings, actuals) {
67
+ const signature = this.signature(name);
68
+ const branches = this.expandedBranches(name, name);
69
+ if (!signature ||
70
+ !branches ||
71
+ Object.keys(bindings).length !== Object.keys(signature).length ||
72
+ Object.keys(signature).some((key) => !Object.hasOwn(bindings, key)))
73
+ return undefined;
74
+ const use = { kind: 'named', signature, actuals, bindings };
75
+ if (!branches.every((branch) => this.branchIsTyped(branch, use)))
76
+ return undefined;
77
+ return Object.entries(actuals).map(([name, options]) => {
78
+ const key = (option) => option.kind === 'exact' ? Key.of(option.ref) : 'default';
79
+ const admitted = options
80
+ .filter((option) => branches.some((branch) => this.branchIsTyped(branch, {
81
+ ...use,
82
+ actuals: { ...actuals, [name]: [option] },
83
+ })))
84
+ .map(key);
85
+ return { object: bindings[name], accepted: options.map(key), admitted: new Set(admitted) };
86
+ });
87
+ }
28
88
  policyAccepts(name, object) {
29
89
  return this.#policyBranchTyping(name, object)?.every(Boolean) ?? false;
30
90
  }
31
91
  /** Whether the Policy accepts every concrete source and target pair the Edge Class accepts. */
32
92
  policyAcceptsEdgeClass(name, declaration) {
93
+ const signature = this.signature(name);
94
+ if (signature && Object.keys(signature).some((key) => key !== 'source' && key !== 'target'))
95
+ return false;
33
96
  const endpoints = endpointPair(declaration);
34
97
  const sources = this.#concreteEndpointClasses(endpoints[0].accepts);
35
98
  const targets = this.#concreteEndpointClasses(endpoints[1].accepts);
@@ -55,18 +118,32 @@ export class PolicyTyping {
55
118
  branchIsTyped(branch, use) {
56
119
  if (targetMode(branch) !== use.kind)
57
120
  return false;
121
+ if (use.kind === 'named') {
122
+ const terms = [...branch.terms.values()].filter((term) => term.kind === 'input');
123
+ if (terms.length !== Object.keys(use.signature).length ||
124
+ terms.some((term) => !Object.hasOwn(use.signature, term.name)))
125
+ return false;
126
+ }
58
127
  const alternatives = edgeAlternatives(branch.edges, this);
59
128
  return alternatives.some((variants) => this.#constraintsAreSatisfiable(branch, variants, use));
60
129
  }
61
130
  /** Whether each normalized branch of the Policy is typed for an object of this contract. */
62
131
  #policyBranchTyping(name, object) {
63
132
  const branches = this.#expandedBranches(name, new Set(), `$use:${name}`);
64
- const use = { kind: 'object', object };
133
+ const signature = this.signature(name);
134
+ if (signature && (Object.keys(signature).length !== 1 || !Object.hasOwn(signature, 'object')))
135
+ return undefined;
136
+ const use = signature
137
+ ? { kind: 'named', signature, actuals: { object: [object] } }
138
+ : { kind: 'object', object };
65
139
  return branches?.map((branch) => this.branchIsTyped(branch, use));
66
140
  }
67
141
  #policyAcceptsEdge(name, source, target) {
68
142
  const branches = this.#expandedBranches(name, new Set(), `$edge-use:${name}`);
69
- const use = { kind: 'edge', source, target };
143
+ const signature = this.signature(name);
144
+ const use = signature
145
+ ? { kind: 'named', signature, actuals: { source: [source], target: [target] } }
146
+ : { kind: 'edge', source, target };
70
147
  return branches !== undefined && branches.every((branch) => this.branchIsTyped(branch, use));
71
148
  }
72
149
  #concreteEndpointClasses(accepts) {
@@ -108,7 +185,11 @@ export class PolicyTyping {
108
185
  return operator === 'allOf' ? branchProduct(children) : capBranches(children.flat());
109
186
  }
110
187
  #constraintsAreSatisfiable(branch, variants, use) {
111
- const terms = new Set(use.kind === 'object' ? ['subject', 'object'] : ['subject', 'source', 'target']);
188
+ const terms = new Set(use.kind === 'named'
189
+ ? ['subject']
190
+ : use.kind === 'object'
191
+ ? ['subject', 'object']
192
+ : ['subject', 'source', 'target']);
112
193
  for (const key of branch.variables.keys())
113
194
  terms.add(key);
114
195
  for (const key of branch.terms.keys())
@@ -118,6 +199,17 @@ export class PolicyTyping {
118
199
  terms.add(termKey(edge.pattern.target, edge.namespace));
119
200
  }
120
201
  const union = new UnionFind(terms);
202
+ if (use.kind === 'named' && use.bindings) {
203
+ const terms = new Map();
204
+ for (const [name, operand] of Object.entries(use.bindings)) {
205
+ const key = checkObjectName(operand);
206
+ const term = 'input:' + name;
207
+ const previous = terms.get(key);
208
+ if (previous)
209
+ union.join(previous, term);
210
+ terms.set(key, term);
211
+ }
212
+ }
121
213
  for (const [left, right] of branch.equalities)
122
214
  union.join(left, right);
123
215
  for (const variant of variants) {
@@ -159,6 +251,14 @@ export class PolicyTyping {
159
251
  #applyInitial(candidates, term, branch, use) {
160
252
  if (term === 'subject')
161
253
  return this.#applyAnyNodeClass(candidates);
254
+ if (use.kind === 'named' && term.startsWith('input:')) {
255
+ const name = term.slice(6);
256
+ const declared = this.#applyRequirement(candidates, use.signature[name]);
257
+ const options = use.actuals[name];
258
+ return !Array.isArray(options)
259
+ ? declared
260
+ : uniqueBy(options.flatMap((option) => option.kind === 'exact' ? this.#applyExact(declared, option.ref) : declared), candidateKey);
261
+ }
162
262
  const contract = targetContract(term, use);
163
263
  if (contract !== undefined) {
164
264
  if (contract.kind === 'exact')
@@ -351,6 +451,8 @@ function ancestryKeys(actual, scope) {
351
451
  return keys;
352
452
  }
353
453
  function targetContract(term, use) {
454
+ if (use.kind === 'named')
455
+ return undefined;
354
456
  if (use.kind === 'object')
355
457
  return term === 'object' ? use.object : undefined;
356
458
  if (term === 'source')
@@ -1,6 +1,9 @@
1
1
  import type { CoreRef, ClassRef, FunctionRef, PolicyRef, ViewRef, DefinitionBase, MethodAddress } from '../../../addressing/index.js';
2
2
  export type PolicyPatternTerm = {
3
3
  readonly kind: 'subject';
4
+ } | {
5
+ readonly kind: 'input';
6
+ readonly name: string;
4
7
  } | {
5
8
  readonly kind: 'object';
6
9
  } | {
@@ -103,6 +106,7 @@ export type PolicyExpression = {
103
106
  readonly anyOf: readonly [PolicyRef, ...PolicyRef[]];
104
107
  };
105
108
  export interface PolicyDefinition extends DefinitionBase<PolicyRef> {
109
+ readonly input?: Readonly<Record<string, ClassRef>>;
106
110
  readonly expression: PolicyExpression;
107
111
  readonly description?: string;
108
112
  }
@@ -187,6 +191,9 @@ export type PolicyCheckObject = {
187
191
  export type PolicyCheckExpression<Policy = PolicyRef, Object = PolicyCheckObject> = {
188
192
  readonly check: Policy;
189
193
  readonly object: Object;
194
+ } | {
195
+ readonly check: Policy;
196
+ readonly input: Readonly<Record<string, Object>>;
190
197
  } | PolicySameNode<Object> | {
191
198
  readonly allOf: readonly [
192
199
  PolicyCheckExpression<Policy, Object>,
@@ -203,3 +210,9 @@ export type PolicyCheckExpression<Policy = PolicyRef, Object = PolicyCheckObject
203
210
  * Its other value has no spelling there: an absent callable Policy already means `false`.
204
211
  */
205
212
  export type CallablePolicy = PolicyCheckExpression | true;
213
+ /** Actual Node operands of one check, keyed by their formal input names. */
214
+ export declare function checkBindings<Operand>(leaf: {
215
+ readonly object: Operand;
216
+ } | {
217
+ readonly input: Readonly<Record<string, Operand>>;
218
+ }): Readonly<Record<string, Operand>>;
@@ -88,3 +88,7 @@ export function checksNameTheCaller(value) {
88
88
  ? operands.some(checksNameTheCaller)
89
89
  : operands.every(checksNameTheCaller);
90
90
  }
91
+ /** Actual Node operands of one check, keyed by their formal input names. */
92
+ export function checkBindings(leaf) {
93
+ return 'input' in leaf ? leaf.input : { object: leaf.object };
94
+ }
@@ -47,7 +47,7 @@ export function normalizeClassRule(value) {
47
47
  if (!isClassRuleChecks(value))
48
48
  return value;
49
49
  const checks = unwrapSingleOperands(normalizePolicyChecks(value));
50
- return ('check' in checks && checks.object.kind === 'self' ? checks.check : checks);
50
+ return ('object' in checks && checks.object.kind === 'self' ? checks.check : checks);
51
51
  }
52
52
  /** Replace each composition of one operand by that operand, merging what it then nests. */
53
53
  function unwrapSingleOperands(value) {
@@ -60,8 +60,13 @@ function unwrapSingleOperands(value) {
60
60
  return PolicyComposition.from(operator, operands(children));
61
61
  }
62
62
  export function normalizePolicyChecks(value) {
63
- if ('check' in value)
63
+ if ('check' in value) {
64
+ if ('input' in value &&
65
+ Object.keys(value.input).length === 1 &&
66
+ Object.hasOwn(value.input, 'object'))
67
+ return { check: value.check, object: value.input.object };
64
68
  return value;
69
+ }
65
70
  if ('sameNode' in value)
66
71
  return { sameNode: normalizeEquality(value.sameNode) };
67
72
  const { operator, operands: values } = PolicyComposition.of(value);
@@ -198,6 +203,8 @@ function rank(names) {
198
203
  return new Map([...names].map(([id, name]) => [id, ranks.get(name) ?? '']));
199
204
  }
200
205
  function termColor(term, colors) {
206
+ if (term.kind === 'input')
207
+ return 'input:' + term.name;
201
208
  if (term.kind === 'variable')
202
209
  return `variable:${colors.get(term.id) ?? '?'}`;
203
210
  if (term.kind === 'ref')