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

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 (72) 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/lowering/value/zod.js +0 -25
  8. package/dist/v1/builder/policy/authoring.d.ts +33 -7
  9. package/dist/v1/builder/policy/authoring.js +5 -2
  10. package/dist/v1/builder/policy/legacy/inputs.d.ts +8 -0
  11. package/dist/v1/builder/policy/legacy/inputs.js +1 -0
  12. package/dist/v1/compiled/admission/semantics/class.js +0 -15
  13. package/dist/v1/compiled/admission/semantics/context.d.ts +1 -2
  14. package/dist/v1/compiled/admission/semantics/policy/callable.js +2 -2
  15. package/dist/v1/compiled/admission/semantics/policy/parity.js +26 -3
  16. package/dist/v1/compiled/admission/semantics/policy/typing.js +2 -0
  17. package/dist/v1/compiled/admission/wire/class.js +1 -10
  18. package/dist/v1/compiled/admission/wire/entry.js +5 -2
  19. package/dist/v1/compiled/admission/wire/policy.js +21 -1
  20. package/dist/v1/compiled/rule.js +0 -1
  21. package/dist/v1/domain/projection/classes.js +0 -8
  22. package/dist/v1/index.d.ts +1 -1
  23. package/dist/v1/language/callable/admission.js +5 -3
  24. package/dist/v1/language/class/model/class.d.ts +1 -2
  25. package/dist/v1/language/class/resolved.d.ts +0 -7
  26. package/dist/v1/language/index.d.ts +1 -2
  27. package/dist/v1/language/index.js +1 -1
  28. package/dist/v1/language/limits.d.ts +2 -0
  29. package/dist/v1/language/limits.js +2 -0
  30. package/dist/v1/language/policy/analysis/branches.d.ts +1 -1
  31. package/dist/v1/language/policy/analysis/branches.js +6 -0
  32. package/dist/v1/language/policy/analysis/budgets.d.ts +4 -2
  33. package/dist/v1/language/policy/analysis/budgets.js +18 -3
  34. package/dist/v1/language/policy/analysis/checks.d.ts +5 -2
  35. package/dist/v1/language/policy/analysis/checks.js +12 -11
  36. package/dist/v1/language/policy/analysis/typing.d.ts +15 -2
  37. package/dist/v1/language/policy/analysis/typing.js +106 -4
  38. package/dist/v1/language/policy/model/policy.d.ts +13 -0
  39. package/dist/v1/language/policy/model/policy.js +4 -0
  40. package/dist/v1/language/policy/normalization/normalize.js +9 -2
  41. package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +125 -47
  42. package/dist/v1/schema/analysis/class.d.ts +0 -8
  43. package/dist/v1/schema/analysis/class.js +0 -28
  44. package/dist/v1/schema/compatibility/comparators/classes.d.ts +1 -1
  45. package/dist/v1/schema/compatibility/comparators/classes.js +1 -11
  46. package/dist/v1/schema/compatibility/evidence.js +12 -2
  47. package/dist/v1/schema/compatibility/fields.d.ts +2 -2
  48. package/dist/v1/schema/compatibility/fields.js +1 -1
  49. package/dist/v1/schema/diagnostic.d.ts +1 -1
  50. package/dist/v1/schema/enforcement/changes.d.ts +0 -6
  51. package/dist/v1/schema/enforcement/changes.js +0 -6
  52. package/dist/v1/schema/enforcement/derived.d.ts +0 -6
  53. package/dist/v1/schema/enforcement/derived.js +0 -6
  54. package/dist/v1/schema/enforcement/fields.d.ts +0 -1
  55. package/dist/v1/schema/enforcement/fields.js +0 -1
  56. package/dist/v1/schema/enforcement/write.d.ts +0 -7
  57. package/dist/v1/schema/enforcement/write.js +0 -7
  58. package/dist/v1/schema/normalization/domain.js +1 -1
  59. package/dist/v1/schema/resolution/origins.js +7 -2
  60. package/dist/v1/schema/rule.js +6 -10
  61. package/dist/v1/schema/validation/domain.json-schema.js +3 -41
  62. package/dist/v1/schema/validation/domain.structure.d.ts +5 -10
  63. package/dist/v1/schema/validation/domain.structure.js +31 -62
  64. package/dist/v1/schema/validation/policy/budgets.js +2 -1
  65. package/dist/v1/schema/validation/policy/context.d.ts +1 -0
  66. package/dist/v1/schema/validation/policy/context.js +3 -0
  67. package/dist/v1/schema/validation/policy/references.js +4 -1
  68. package/dist/v1/schema/validation/policy/typing.js +6 -0
  69. package/dist/v1/schema/validation/policy/uses.js +24 -2
  70. package/package.json +1 -1
  71. package/dist/v1/language/class/model/data.d.ts +0 -11
  72. package/dist/v1/language/class/model/data.js +0 -2
@@ -6,7 +6,7 @@ import type { PolicyCheckExpression, PolicyCheckObject, PolicyObjectRef } from '
6
6
  import type { Class } from '../class/handle.js';
7
7
  import type { ValueSchemaInput } from '../class/property.js';
8
8
  import type { CoreNode } from '../core/authoring.js';
9
- import type { Policy, PolicyInput } from '../policy/authoring.js';
9
+ import type { Policy } from '../policy/authoring.js';
10
10
  import type { Lazy } from '../schema/lazy.js';
11
11
  import type { TypedValueSchema } from '../value/schema.js';
12
12
  import type { View } from '../view/authoring.js';
@@ -26,7 +26,7 @@ export interface PolicyCheckContext<Object extends PolicyCheckObject = PolicyChe
26
26
  ref(member: PolicyObjectInput): Extract<Object, {
27
27
  readonly kind: 'ref';
28
28
  }>;
29
- check(policy: PolicyInput, object: Object): PolicyCheckExpression<PolicyRef, Object>;
29
+ check<Names extends string>(policy: Lazy<Policy<Names>>, bindings: Readonly<Record<NoInfer<Names>, Object>> | (string extends NoInfer<Names> ? Object : [NoInfer<Names>] extends ['object'] ? Object : never)): PolicyCheckExpression<PolicyRef, Object>;
30
30
  sameNode(left: Object, right: Object): PolicyCheckExpression<PolicyRef, Object>;
31
31
  allOf(first: PolicyCheckExpression<PolicyRef, Object>, ...rest: readonly PolicyCheckExpression<PolicyRef, Object>[]): PolicyCheckExpression<PolicyRef, Object>;
32
32
  anyOf(first: PolicyCheckExpression<PolicyRef, Object>, ...rest: readonly PolicyCheckExpression<PolicyRef, Object>[]): PolicyCheckExpression<PolicyRef, Object>;
@@ -22,7 +22,6 @@ export function nodeClass(config) {
22
22
  'description',
23
23
  'extends',
24
24
  'properties',
25
- 'data',
26
25
  'methods',
27
26
  'icon',
28
27
  'policies',
@@ -1,11 +1,10 @@
1
1
  import type { ClassRef } from '../../addressing/index.js';
2
2
  import type { Inheritance } from '../../language/class/model/class.js';
3
- import type { MediaType } from '../../language/class/model/data.js';
4
3
  import type { EdgeCount, EdgeLifetime } from '../../language/class/model/edge.js';
5
4
  import type { ResolvedClass } from '../../language/class/resolved.js';
6
5
  import type { ClassRuleChecks, ClassRuleObject, CreateRuleChecks, CreateRuleObject, EdgeRuleChecks } from '../../language/policy/model/policy.js';
7
6
  import type { Method, PolicyCheckContext } from '../callable/authoring.js';
8
- import type { Policy } from '../policy/authoring.js';
7
+ import type { Policy, PolicyForSlot } from '../policy/authoring.js';
9
8
  import type { Lazy } from '../schema/lazy.js';
10
9
  import type { Class, EdgeClass, NodeClass } from './handle.js';
11
10
  import type { PropertyRecordInput } from './property.js';
@@ -50,7 +49,7 @@ export interface ClassRuleContext extends PolicyCheckContext<ClassRuleObject> {
50
49
  }
51
50
  export type ClassRuleBuilder = (context: ClassRuleContext) => ClassRuleChecks;
52
51
  /** One Node Class slot: a local Policy, a constant value, or Policy checks. */
53
- export type NodeClassPolicyInput = ClassPolicyInput | ClassRuleBuilder;
52
+ export type NodeClassPolicyInput = boolean | Lazy<PolicyForSlot<'object'>> | ClassRuleBuilder;
54
53
  /**
55
54
  * Policy checks deciding the creation of a Node. The Node is not yet, so it has no `self`: `ref`
56
55
  * names each object, one exact member.
@@ -80,7 +79,7 @@ export interface EdgeRuleContext extends PolicyCheckContext<ClassRuleObject> {
80
79
  }
81
80
  export type EdgeRuleBuilder = (context: EdgeRuleContext) => EdgeRuleChecks;
82
81
  /** One Edge Class slot: a local Policy, a constant value, or Policy checks. */
83
- export type EdgeClassPolicyInput = ClassPolicyInput | EdgeRuleBuilder;
82
+ export type EdgeClassPolicyInput = boolean | Lazy<PolicyForSlot<'source' | 'target'>> | EdgeRuleBuilder;
84
83
  /** Local Policies of an Edge Class. */
85
84
  export interface EdgeClassPoliciesInput {
86
85
  readonly read?: EdgeClassPolicyInput;
@@ -97,7 +96,6 @@ export interface NodeClassInput {
97
96
  readonly description?: string;
98
97
  readonly extends?: readonly NodeClassReferenceInput[];
99
98
  readonly properties?: PropertyRecordInput;
100
- readonly data?: MediaType;
101
99
  readonly methods?: Readonly<Record<string, Method>>;
102
100
  readonly icon?: string;
103
101
  /** Local Policies; inherited by no descendant and forbidden on abstract Classes. */
@@ -24,7 +24,7 @@ export type { AuthoredPropertyProjection, AuthoredMethodProjection, ClassIdentit
24
24
  export type { FileAuthoring, FileSource } from './value/file.js';
25
25
  export type { PathAuthoring } from './value/path.js';
26
26
  export type { Lazy } from './schema/lazy.js';
27
- export type { EdgeRolesOf, MatchPolicyInput, Policy, PolicyBuilder as PolicyFactory, PolicyEdgeClassInput, PolicyEdgeEnds, PolicyEdgeOptions, PolicyEdgeRepeat, PolicyExistsContext, PolicyInput, PolicyNodeBinder, PolicyPatternContext, } from './policy/authoring.js';
27
+ export type { EdgeRolesOf, MatchPolicyInput, NamedMatchPolicyInput, NamedPolicy, PolicyForSlot, Policy, PolicyBuilder as PolicyFactory, PolicyEdgeClassInput, PolicyEdgeEnds, PolicyEdgeOptions, PolicyEdgeRepeat, PolicyExistsContext, PolicyInput, PolicyNodeBinder, PolicyPatternContext, } from './policy/authoring.js';
28
28
  export type { PolicyEdgeInput } from './policy/legacy/edge.js';
29
29
  export type { AutoOptions, AutoProperty, Property, PropertyFieldInput as PropertyField, PropertyOptions, ValueSchemaInput, } from './class/property.js';
30
30
  export type { CorePropertyInput } from './schema/projection.js';
@@ -26,7 +26,6 @@ export class V1DefinitionCompiler {
26
26
  nodeClass(value, name, pointer) {
27
27
  const input = classConfiguration(value);
28
28
  const facet = this.values.properties(input.properties, `${pointer}/properties`);
29
- const data = dataDeclaration(input.data);
30
29
  return {
31
30
  ref: { origin: this.context.origin, kind: 'class', name },
32
31
  kind: 'node',
@@ -36,7 +35,6 @@ export class V1DefinitionCompiler {
36
35
  extends: this.parents(input.extends, 'node', `${pointer}/extends`),
37
36
  properties: facet,
38
37
  methods: this.methods(input.methods, input.abstract ?? false, `${pointer}/methods`),
39
- ...(data === undefined ? {} : { data }),
40
38
  ...(input.icon === undefined ? {} : { icon: input.icon }),
41
39
  policies: this.classPolicies(input, 'node', `${pointer}/policies`),
42
40
  // Property names stay as authored until `canonicalizeUniquePropertyKeys` qualifies them
@@ -203,9 +201,6 @@ export class V1DefinitionCompiler {
203
201
  function declaredInheritance(inheritance) {
204
202
  return inheritance === undefined || inheritance === 'internal' ? {} : { inheritance };
205
203
  }
206
- function dataDeclaration(mediaType) {
207
- return mediaType === undefined ? undefined : { mediaType };
208
- }
209
204
  function directedConstraints(options) {
210
205
  return {
211
206
  ...(options.constraints?.noSelf === true ? { noSelf: true } : {}),
@@ -22,15 +22,28 @@ export class V1PolicyCompiler {
22
22
  expression: normalizePolicyExpression(input.operator === 'allOf' ? { allOf: refs } : { anyOf: refs }),
23
23
  };
24
24
  }
25
- const match = input.match(createPatternContext({
25
+ const pattern = createPatternContext({
26
26
  resolveObject: (member, refPointer) => this.context.resolvePolicyObject(member, refPointer),
27
27
  resolveEdgeClass: (definition, refPointer) => this.context.resolveEdgeClass(definition, refPointer),
28
28
  edgeRoles: (ref) => this.context.edgeRoles(ref),
29
29
  resolveNodeClass: (definition, refPointer) => this.context.resolveNodeClass(definition, refPointer),
30
30
  pointer,
31
- }));
31
+ });
32
+ const formals = input.input !== undefined
33
+ ? Object.fromEntries(Object.entries(input.input).map(([key, value]) => [
34
+ key,
35
+ this.context.resolveNodeClass(value, pointer + '/input/' + key),
36
+ ]))
37
+ : undefined;
38
+ const match = input.input !== undefined
39
+ ? input.match({
40
+ ...pattern,
41
+ input: Object.fromEntries(Object.keys(input.input).map((name) => [name, { kind: 'input', name }])),
42
+ })
43
+ : input.match(pattern);
32
44
  return {
33
45
  ref,
46
+ ...(formals === undefined ? {} : { input: formals }),
34
47
  ...(input.description === undefined ? {} : { description: input.description }),
35
48
  expression: normalizePolicyExpression({ match }),
36
49
  };
@@ -53,10 +66,15 @@ export function policyCheckContext(context, pointer, admit) {
53
66
  return Object.freeze({
54
67
  self: callableSelf(),
55
68
  ref: (member) => callableRef(context.resolvePolicyObject(member, `${pointer}/ref`)),
56
- check: (policy, value) => ({
57
- check: context.resolvePolicy(policy, `${pointer}/check`),
58
- object: object(value),
59
- }),
69
+ check: (policy, value) => {
70
+ const check = context.resolvePolicy(policy, pointer + '/check');
71
+ if (typeof value?.kind === 'string')
72
+ return { check, object: object(value) };
73
+ const input = Object.fromEntries(Object.entries(value).map(([name, operand]) => [name, object(operand)]));
74
+ return Object.keys(input).length === 1 && Object.hasOwn(input, 'object')
75
+ ? { check, object: input.object }
76
+ : { check, input };
77
+ },
60
78
  sameNode: (left, right) => ({
61
79
  sameNode: { left: object(left), right: object(right) },
62
80
  }),
@@ -35,7 +35,6 @@ export function convertZodToValueSchema(zodSchema, context, registry, pointer =
35
35
  path,
36
36
  zodSchema: source,
37
37
  });
38
- keepLoweredShape(source, jsonSchema);
39
38
  }
40
39
  },
41
40
  });
@@ -66,28 +65,6 @@ export function convertZodToValueSchema(zodSchema, context, registry, pointer =
66
65
  diagnostics: [],
67
66
  };
68
67
  }
69
- /**
70
- * The lowering keeps one spelling per contract, whatever Zod version renders it, so that a Domain
71
- * built from unchanged source keeps its schema digest. Every node lowers as its own Zod schema: a
72
- * union by `anyOf`, an intersection by `allOf`, a tuple by its `prefixItems` and rest alone. Zod
73
- * 4.6 compacts bare-type unions into a `type` array, folds object intersections, and closes tuples;
74
- * the marker leaves no node bare, so the first two do not apply, and the tuple bounds are removed.
75
- * `copyZodJson` drops the marker.
76
- */
77
- function keepLoweredShape(schema, jsonSchema) {
78
- const def = getSchemaDefinition(schema);
79
- if (def?.type === 'tuple' && Array.isArray(def.items)) {
80
- if (jsonSchema.items === false)
81
- delete jsonSchema.items;
82
- if (jsonSchema.maxItems === def.items.length)
83
- delete jsonSchema.maxItems;
84
- if (typeof jsonSchema.minItems === 'number' && jsonSchema.minItems <= def.items.length) {
85
- delete jsonSchema.minItems;
86
- }
87
- }
88
- jsonSchema[LOWERED_NODE] = true;
89
- }
90
- const LOWERED_NODE = '~astrale-lowered-node';
91
68
  function copyZodJson(value) {
92
69
  if (value === null || ['boolean', 'number', 'string'].includes(typeof value))
93
70
  return value;
@@ -100,8 +77,6 @@ function copyZodJson(value) {
100
77
  for (const key of Reflect.ownKeys(value)) {
101
78
  if (typeof key === 'symbol')
102
79
  throw new TypeError('Zod emitted symbol-keyed schema metadata.');
103
- if (key === LOWERED_NODE)
104
- continue;
105
80
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
106
81
  if (descriptor === undefined)
107
82
  continue;
@@ -7,6 +7,8 @@ import type { EdgeClassReferenceInput, NodeClassReferenceInput } from '../class/
7
7
  import type { AuthoringValue } from '../schema/handle.js';
8
8
  import type { Lazy } from '../schema/lazy.js';
9
9
  import type { ResolveLazy } from '../schema/projection/identity.js';
10
+ import type { MatchPolicyInput } from './legacy/inputs.js';
11
+ export type { MatchPolicyInput } from './legacy/inputs.js';
10
12
  import type { PolicyEdgeInput } from './legacy/edge.js';
11
13
  /** How many Edges of the Class a path between the two terms crosses, both bounds included. */
12
14
  export interface PolicyEdgeRepeat {
@@ -110,22 +112,46 @@ export interface PolicyPatternContext {
110
112
  allOf(first: PolicyPatternExpression, ...rest: readonly PolicyPatternExpression[]): PolicyPatternExpression;
111
113
  anyOf(first: PolicyPatternExpression, ...rest: readonly PolicyPatternExpression[]): PolicyPatternExpression;
112
114
  }
113
- export interface MatchPolicyInput {
115
+ type NodeInputs = Readonly<Record<string, NodeClassReferenceInput>>;
116
+ export interface NamedMatchPolicyInput<Inputs extends NodeInputs> {
114
117
  readonly description?: string;
115
- readonly match: (context: PolicyPatternContext) => PolicyPatternExpression;
118
+ readonly input: Inputs;
119
+ readonly match: (context: Omit<PolicyPatternContext, 'object' | 'source' | 'target'> & {
120
+ readonly input: {
121
+ readonly [Name in keyof Inputs]: CanonicalPolicyPatternTerm;
122
+ };
123
+ }) => PolicyPatternExpression;
116
124
  }
117
125
  interface PolicyComposition {
118
126
  readonly operator: 'allOf' | 'anyOf';
119
127
  readonly policies: readonly [PolicyInput, ...PolicyInput[]];
120
128
  }
121
- export interface Policy extends AuthoringValue<'policy'> {
129
+ declare const POLICY_INPUT: unique symbol;
130
+ export interface Policy<Names extends string = string> extends AuthoringValue<'policy'> {
131
+ readonly [POLICY_INPUT]?: Names;
132
+ }
133
+ declare const DECLARED_INPUTS: unique symbol;
134
+ declare const INPUT_SIGNATURE: unique symbol;
135
+ /** Names supplied by a Class slot. An implicit Policy gets its terms from the slot. */
136
+ export type PolicyForSlot<Names extends string> = Policy & {
137
+ readonly [DECLARED_INPUTS]?: Names;
138
+ };
139
+ /** A Policy that explicitly declares its inputs. */
140
+ export interface NamedPolicy<Names extends string> extends Policy<Names> {
141
+ readonly [DECLARED_INPUTS]: Names;
142
+ readonly [INPUT_SIGNATURE]: (name: Names) => Names;
122
143
  }
123
144
  export type PolicyInput = Lazy<Policy>;
124
- type PolicyDeclaration = MatchPolicyInput | PolicyComposition;
145
+ type PolicyDeclaration = MatchPolicyInput | NamedMatchPolicyInput<NodeInputs> | PolicyComposition;
125
146
  export interface PolicyBuilder {
126
- (input: MatchPolicyInput): Policy;
127
- readonly allOf: (first: PolicyInput, ...rest: readonly PolicyInput[]) => Policy;
128
- readonly anyOf: (first: PolicyInput, ...rest: readonly PolicyInput[]) => Policy;
147
+ <const Inputs extends NodeInputs>(input: NamedMatchPolicyInput<Inputs>): NamedPolicy<keyof Inputs & string>;
148
+ /** @deprecated Declare the Node inputs for new Policies. */
149
+ (input: MatchPolicyInput): Policy<'object'>;
150
+ readonly allOf: {
151
+ <Names extends string>(first: Lazy<NamedPolicy<Names>>, ...rest: readonly Lazy<NamedPolicy<NoInfer<Names>>>[]): NamedPolicy<Names>;
152
+ <Names extends string>(first: Lazy<Policy<Names> & PolicyForSlot<never>>, ...rest: readonly Lazy<Policy<NoInfer<Names>> & PolicyForSlot<never>>[]): Policy<Names>;
153
+ };
154
+ readonly anyOf: PolicyBuilder['allOf'];
129
155
  }
130
156
  export declare function policyDeclaration(value: Policy): PolicyDeclaration;
131
157
  export declare const policy: PolicyBuilder;
@@ -16,13 +16,16 @@ function createPolicy(input) {
16
16
  }
17
17
  }
18
18
  else {
19
- assertKnownKeys(input, ['description', 'match']);
19
+ assertKnownKeys(input, ['description', 'match', 'input']);
20
20
  }
21
21
  const value = authoringValue('policy', {});
22
22
  declarations.set(value, input);
23
23
  return value;
24
24
  }
25
- export const policy = Object.freeze(Object.assign(createPolicy, { allOf: composer('allOf'), anyOf: composer('anyOf') }));
25
+ export const policy = Object.freeze(Object.assign(createPolicy, {
26
+ allOf: composer('allOf'),
27
+ anyOf: composer('anyOf'),
28
+ }));
26
29
  function composer(operator) {
27
30
  return (first, ...rest) => createPolicy(composition(operator, first === undefined ? [] : [first, ...rest]));
28
31
  }
@@ -0,0 +1,8 @@
1
+ import type { PolicyPatternExpression } from '../../../language/policy/model/policy.js';
2
+ import type { PolicyPatternContext } from '../authoring.js';
3
+ /** @deprecated Declare the Node inputs for new Policies. */
4
+ export interface MatchPolicyInput {
5
+ readonly input?: never;
6
+ readonly description?: string;
7
+ readonly match: (context: PolicyPatternContext) => PolicyPatternExpression;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -37,20 +37,6 @@ export function analyzeClasses(classes) {
37
37
  entry: located.entry,
38
38
  });
39
39
  }
40
- let dataOwner;
41
- for (const parent of parents) {
42
- if (parent.dataOwner === undefined)
43
- continue;
44
- if (dataOwner !== undefined && Key.of(dataOwner) !== Key.of(parent.dataOwner)) {
45
- fail(located.pointer, 'Data has distinct inherited declaring owners.');
46
- }
47
- dataOwner = parent.dataOwner;
48
- }
49
- if (located.value.kind === 'node' && located.value.data !== undefined) {
50
- if (dataOwner !== undefined)
51
- fail(`${located.pointer}/data`, 'Data cannot redeclare an inherited contract.');
52
- dataOwner = located.value.ref;
53
- }
54
40
  const own = new Map((located.value.kind === 'node' ? located.value.methods : []).map((method) => [
55
41
  method.name,
56
42
  {
@@ -65,7 +51,6 @@ export function analyzeClasses(classes) {
65
51
  const analysis = {
66
52
  properties,
67
53
  ...composition,
68
- ...(dataOwner === undefined ? {} : { dataOwner }),
69
54
  };
70
55
  analyses.set(classKey, analysis);
71
56
  return analysis;
@@ -33,10 +33,9 @@ export interface EffectiveMethod {
33
33
  readonly declaration: CompiledMethod;
34
34
  readonly entry: CompiledSchemaEntry;
35
35
  }
36
- /** The effective Properties, Methods and Data owner of one Class. */
36
+ /** The effective Properties and Methods of one Class. */
37
37
  export interface ClassAnalysis extends MethodComposition<EffectiveMethod> {
38
38
  readonly properties: ReadonlyMap<PropertyKey, EffectiveProperty>;
39
- readonly dataOwner?: ClassRef;
40
39
  }
41
40
  /** Closure-wide declaration indexes and composed Class contracts. */
42
41
  export interface SemanticIndex {
@@ -1,5 +1,5 @@
1
1
  import { Key } from '../../../../addressing/index.js';
2
- import { PolicyComposition, } from '../../../../language/policy/model/policy.js';
2
+ import { checkBindings, PolicyComposition, } from '../../../../language/policy/model/policy.js';
3
3
  import { GRAPH_NODE_PATH_SCHEMA_ID } from '../../../../language/value/syntax/node-path/schema.js';
4
4
  import {} from '../../../model/schema.js';
5
5
  import { fail } from '../../diagnostic.js';
@@ -12,7 +12,7 @@ export function validateCallablePolicy(context, entry, expression, inputIndex, f
12
12
  (expression.check.origin !== entry.origin ||
13
13
  context.policies.get(Key.of(expression.check)) === undefined))
14
14
  fail(`${path}/check`, 'Callable Policy must reference a local named Policy.');
15
- const objects = 'check' in expression ? { object: expression.object } : expression.sameNode;
15
+ const objects = 'check' in expression ? checkBindings(expression) : expression.sameNode;
16
16
  for (const [side, object] of Object.entries(objects)) {
17
17
  if (object.kind === 'ref' && object.ref.kind === 'method')
18
18
  validatePolicyMethod(context, object.ref, `${path}/${side}/ref`);
@@ -14,9 +14,17 @@ import { compiledPolicyTyping } from './typing.js';
14
14
  export function validatePolicyParity(context, entry, entryIndex, policies, origins) {
15
15
  const normalized = new Map([...policies].map(([name, policy]) => [name, normalizePolicyExpression(policy.expression)]));
16
16
  const typing = compiledPolicyTyping(context, entry, normalized, origins);
17
- const measurePolicy = policyMeasurer(entry.origin, normalized, (ref) => ref.origin === entry.origin);
17
+ const measurePolicy = policyMeasurer(entry.origin, normalized, (ref) => ref.origin === entry.origin, (name) => policies.get(name)?.input);
18
18
  for (const [name, declaration] of policies) {
19
19
  const path = `/closure/${entryIndex}/definitions/policies/${declarationIndex(entry, 'policies', name)}`;
20
+ for (const ref of Object.values(declaration.input ?? {})) {
21
+ if (context.classes.get(Key.of(ref))?.value.kind !== 'node' ||
22
+ (ref.origin !== entry.origin &&
23
+ !Object.values(entry.dependencies).some((dep) => dep.origin === ref.origin)))
24
+ fail(path + '/input', 'Policy inputs must name local or direct dependency Node Classes.');
25
+ }
26
+ if (!typing.validDeclaration(name))
27
+ fail(path, 'Policy signature must agree with its branches and operands.');
20
28
  if ('match' in declaration.expression) {
21
29
  for (const branch of branchesOf(declaration.expression.match, name)) {
22
30
  if (targetMode(branch) === undefined) {
@@ -35,6 +43,8 @@ export function validatePolicyParity(context, entry, entryIndex, policies, origi
35
43
  if (branches !== undefined) {
36
44
  for (const branch of branches) {
37
45
  const mode = targetMode(branch);
46
+ if (mode === 'named')
47
+ continue;
38
48
  if (mode === undefined)
39
49
  fail(path, 'Expanded Policy branches must use one coherent target mode.');
40
50
  const use = mode === 'object'
@@ -105,12 +115,25 @@ function validatePolicyChecks(context, typing, entry, expression, input, receive
105
115
  PolicyComposition.of(value).operands.forEach((child, index) => visit(child, `${pointer}/${index}`));
106
116
  return;
107
117
  }
118
+ if ('input' in value) {
119
+ const actuals = Object.fromEntries(Object.entries(value.input).map(([key, operand]) => {
120
+ const contracts = callableObjectContracts(context, entry, input, receiver, operand);
121
+ if (!contracts)
122
+ fail(pointer, 'Named operand is unavailable here.');
123
+ return [key, contracts];
124
+ }));
125
+ const classes = typing.namedCheck(value.check.name, value.input, actuals);
126
+ if (!classes)
127
+ fail(pointer, 'Bindings must supply each declared input with a compatible Node.');
128
+ leaves.set(value, classes);
129
+ return;
130
+ }
108
131
  if (edge !== undefined && value.object.kind === 'self') {
109
132
  // An Edge is checked as an Edge Class Policy is: over every concrete endpoint pair.
110
133
  if (!typing.policyAcceptsEdgeClass(value.check.name, edge))
111
134
  fail(pointer, 'Named Policy is incompatible with an accepted Edge endpoint pair.');
112
135
  const name = Key.of(edge.ref);
113
- leaves.set(value, { accepted: [name], admitted: new Set([name]) });
136
+ leaves.set(value, [{ object: value.object, accepted: [name], admitted: new Set([name]) }]);
114
137
  return;
115
138
  }
116
139
  const contracts = callableObjectContracts(context, entry, input, receiver, value.object);
@@ -120,7 +143,7 @@ function validatePolicyChecks(context, typing, entry, expression, input, receive
120
143
  if (classes === undefined) {
121
144
  fail(pointer, `Named Policy is incompatible with ${label.objects}.`);
122
145
  }
123
- leaves.set(value, classes);
146
+ leaves.set(value, [{ ...classes, object: value.object }]);
124
147
  };
125
148
  visit(expression, path);
126
149
  const [never] = neverAdmittedClasses(expression, leaves);
@@ -9,7 +9,9 @@ export function compiledPolicyTyping(context, entry, normalized, origins) {
9
9
  const nodeClasses = [...context.classes.values()]
10
10
  .map(({ value }) => value)
11
11
  .filter((value) => value.kind === 'node' && origins.has(value.ref.origin));
12
+ const signatures = new Map(entry.definitions.policies.map((p) => [p.ref.name, p.input]));
12
13
  return new PolicyTyping({
14
+ inputOf: (name) => signatures.get(name),
13
15
  normalized,
14
16
  allNodeClasses: nodeClasses.map((value) => value.ref),
15
17
  concreteNodeClasses: nodeClasses.filter((value) => !value.abstract).map((value) => value.ref),
@@ -1,6 +1,5 @@
1
1
  import {} from '@astrale-os/kernel-dsl/value';
2
2
  import { Key } from '../../../addressing/index.js';
3
- import { MEDIA_TYPE_PATTERN } from '../../../language/class/model/data.js';
4
3
  import { compareEdgeUniqueTuples, compareNodeUniqueTuples, edgeUniqueTuple, nodeUniqueTuple, } from '../../../language/class/unique.js';
5
4
  import { CLASS_OPERATIONS, isClassObservation } from '../../../language/policy/model/policy.js';
6
5
  import {} from '../../model/schema.js';
@@ -28,7 +27,7 @@ export function compiledClass(input, values, path) {
28
27
  'properties',
29
28
  'policies',
30
29
  ], 'Compiled Class', path, value.kind === 'node'
31
- ? ['data', 'description', 'icon', 'inheritance', 'unique']
30
+ ? ['description', 'icon', 'inheritance', 'unique']
32
31
  : ['description', 'inheritance', 'unique']);
33
32
  definitionRef(value.ref, 'class', 'Class ref', `${path}/ref`);
34
33
  boolean(value.abstract, 'Class abstract', `${path}/abstract`);
@@ -44,8 +43,6 @@ export function compiledClass(input, values, path) {
44
43
  const properties = array(value.properties, 'Class properties', propertiesPath).map((property, index) => compiledProperty(property, values, value.kind === 'node', `${propertiesPath}/${index}`));
45
44
  unique(properties.map((property) => property.name), 'Class Properties', propertiesPath);
46
45
  if (value.kind === 'node') {
47
- if (value.data !== undefined)
48
- dataDefinition(value.data, `${path}/data`);
49
46
  boundedString(value.icon, 1, 8000, 'Class icon', `${path}/icon`);
50
47
  classPolicies(value.policies, 'node', `${path}/policies`);
51
48
  if (value.unique !== undefined)
@@ -174,9 +171,3 @@ function edgeEndpoint(input, count, label, path) {
174
171
  if (value.onDelete !== undefined && value.onDelete !== 'restrict' && value.onDelete !== 'detach')
175
172
  invalid(`${label} onDelete`, undefined, `${path}/onDelete`);
176
173
  }
177
- function dataDefinition(input, path) {
178
- const value = object(input, 'Class data', path);
179
- exact(value, ['mediaType'], 'Class data', path);
180
- if (typeof value.mediaType !== 'string' || !MEDIA_TYPE_PATTERN.test(value.mediaType))
181
- invalid('Class data mediaType', undefined, `${path}/mediaType`);
182
- }
@@ -2,6 +2,7 @@ import {} from '@astrale-os/kernel-dsl/value';
2
2
  import {} from '../../../addressing/index.js';
3
3
  import * as metadata from '../../../language/definition/metadata.js';
4
4
  import { indexValuePrograms } from '../../../language/value/compile/load.js';
5
+ import { codePointLength } from '../../../language/value/evaluate/assertions.js';
5
6
  import {} from '../../model/schema.js';
6
7
  import { invalid, pointer, withinEncodingLimits } from '../diagnostic.js';
7
8
  import { revisionOfCompiledEntry } from '../revision.js';
@@ -20,8 +21,10 @@ export function entry(input, entryIndex, path, machines) {
20
21
  exact(value, ['origin', 'revision', 'name', 'dependencies', 'definitions', 'facts', 'values'], 'entry', path, ['icon', 'entrypoint', 'patterns']);
21
22
  const origin = originValue(value.origin, 'entry origin', `${path}/origin`);
22
23
  const name = string(value.name, 'entry name', `${path}/name`);
23
- if (name.length < metadata.name.minLength ||
24
- name.length > metadata.name.maxLength ||
24
+ // The bounds count code points, as the metadata's JSON Schema `minLength` and `maxLength` do.
25
+ const nameLength = codePointLength(name);
26
+ if (nameLength < metadata.name.minLength ||
27
+ nameLength > metadata.name.maxLength ||
25
28
  !metadata.isDomainNameText(name))
26
29
  invalid('entry name', undefined, `${path}/name`);
27
30
  const icon = value.icon === undefined ? undefined : domainIcon(value.icon, `${path}/icon`);
@@ -13,7 +13,13 @@ const WIRE_DEPTH = 64;
13
13
  /** Decode a named Policy and its expression grammar. */
14
14
  export function compiledPolicy(input, path) {
15
15
  const value = object(input, 'Policy', path);
16
- exact(value, ['ref', 'expression'], 'Policy', path, ['description']);
16
+ exact(value, ['ref', 'expression'], 'Policy', path, ['description', 'input']);
17
+ if (value.input !== undefined) {
18
+ for (const [name, ref] of Object.entries(object(value.input, 'Policy inputs', path))) {
19
+ memberName(name, 'Policy input name', pointer(path, name));
20
+ definitionRef(ref, 'class', 'Policy input Class', pointer(path + '/input', name));
21
+ }
22
+ }
17
23
  definitionRef(value.ref, 'policy', 'Policy ref', `${path}/ref`);
18
24
  description(value.description, 'Policy description', `${path}/description`);
19
25
  policyExpression(value.expression, 0, `${path}/expression`);
@@ -112,6 +118,11 @@ function policyPattern(input, depth, path) {
112
118
  }
113
119
  function policyTerm(input, variableOnly, path) {
114
120
  const value = object(input, 'Policy pattern term', path);
121
+ if (!variableOnly && value.kind === 'input') {
122
+ exact(value, ['kind', 'name'], 'Policy input term', path);
123
+ memberName(value.name, 'Policy input name', path + '/name');
124
+ return;
125
+ }
115
126
  if (!variableOnly && value.kind === 'ref') {
116
127
  exact(value, ['kind', 'ref'], 'Policy reference term', path);
117
128
  policyObjectRef(value.ref, `${path}/ref`);
@@ -164,6 +175,15 @@ function policyCheck(input, depth, path, site = 'callable') {
164
175
  return;
165
176
  }
166
177
  if (Object.hasOwn(value, 'check')) {
178
+ if (Object.hasOwn(value, 'input')) {
179
+ exact(value, ['check', 'input'], name, path);
180
+ definitionRef(value.check, 'policy', name, path + '/check');
181
+ for (const [key, operand] of Object.entries(object(value.input, name, path + '/input'))) {
182
+ memberName(key, name, pointer(path + '/input', key));
183
+ policyCheckObject(operand, pointer(path + '/input', key), site);
184
+ }
185
+ return;
186
+ }
167
187
  exact(value, ['check', 'object'], `${name} check`, path);
168
188
  definitionRef(value.check, 'policy', `${name} ref`, `${path}/check`);
169
189
  policyCheckObject(value.object, `${path}/object`, site);
@@ -93,7 +93,6 @@ export const READMITTED_RULES = deepFreeze({
93
93
  DV_CORE_NODE_PROPERTIES: SOURCE,
94
94
  DV_CORE_NODE_UNIQUE: SOURCE,
95
95
  DV_CORE_REF: SOURCE,
96
- DV_DATA_COMPOSITION: SOURCE,
97
96
  DV_DEPENDENCY_ACYCLIC: WIRE,
98
97
  DV_DEPENDENCY_DIRECT: SOURCE,
99
98
  DV_DEPENDENCY_EXACT: WIRE,
@@ -27,13 +27,10 @@ export function createClasses(definitions, validation) {
27
27
  }
28
28
  const shell = {};
29
29
  const effectiveProperties = new Map();
30
- let inheritedData;
31
30
  for (const parent of parents) {
32
31
  for (const property of parent.properties) {
33
32
  effectiveProperties.set(property.key, property);
34
33
  }
35
- if (parent.kind === 'node' && inheritedData === undefined)
36
- inheritedData = parent.data;
37
34
  }
38
35
  const ownProperties = [];
39
36
  for (const [name, propertyDefinition] of Object.entries(definition.properties)) {
@@ -53,9 +50,6 @@ export function createClasses(definitions, validation) {
53
50
  }
54
51
  const ownInstanceMethods = [];
55
52
  const ownStaticMethods = [];
56
- const ownData = definition.kind === 'node' && definition.data !== undefined
57
- ? Object.freeze({ owner: shell, definition: definition.data })
58
- : undefined;
59
53
  if (definition.kind === 'node') {
60
54
  for (const [name, methodDefinition] of Object.entries(definition.methods)) {
61
55
  const methodKey = MethodKeyValue.of(ref, name);
@@ -95,12 +89,10 @@ export function createClasses(definitions, validation) {
95
89
  definition,
96
90
  extends: Object.freeze(parents),
97
91
  policies: definition.policies,
98
- data: definition.kind === 'node' ? (ownData ?? inheritedData) : undefined,
99
92
  properties: createPropertyCollection(effectiveProperties.values()),
100
93
  methods: createMethodCollection(ownInstanceMethods),
101
94
  static: Object.freeze({ methods: createMethodCollection(ownStaticMethods) }),
102
95
  self: Object.freeze({
103
- data: definition.kind === 'node' ? ownData : undefined,
104
96
  properties: createPropertyCollection(ownProperties),
105
97
  methods: createMethodCollection(ownInstanceMethods),
106
98
  static: Object.freeze({ methods: createMethodCollection(ownStaticMethods) }),
@@ -6,7 +6,7 @@ export type { EventOf, StateMachine, StateOf } from './language/state/index.js';
6
6
  export { PropertyValues } from './language/index.js';
7
7
  export * as metadata from './language/definition/metadata.js';
8
8
  export type { DomainIcon, DomainIconArt } from './language/definition/metadata.js';
9
- export type { AnyResolvedClass, BoundMethodOf, BoundMethodShortcutsOf, CallableResultOf, CallableInputOf, CallableInputModeOf, CallableOutputOf, ClassSatisfactionKeysOf, ClassDefinition, CoreDefinition, CoreEdge, FunctionAuth, FunctionDefinition, Inheritance, BinaryInput, BinaryInputProjection, CallableInputContract, MethodDefinition, MethodOwnerKeyOf, CallablePolicy, ClassPolicy, ClassRuleChecks, ClassRuleObject, ClassWritePolicy, CreateRuleChecks, EdgeClassPolicy, EdgeClassWritePolicy, EdgeRuleChecks, NodeClassCreatePolicy, NodeClassPolicy, NodeClassWritePolicy, PolicyCheckExpression, PolicyDefinition, PropertyImmutability, PropertyInputOf, PropertyAccessOf, PropertyOutputOf, PropertyShortcutsOf, PropertyValuesOf, ResolvedClass, ResolvedCoreDefinition, ResolvedCoreEndpoint, ResolvedData, ResolvedFunction, ExecutableMethod, ResolvedMethod, ResolvedMethodCollection, ResolvedPolicy, ResolvedProperty, ResolvedView, MethodAccessOf, SelfMethodsOf, SelfPropertiesOf, SelfStaticMethodsOf, StaticMethodsOf, ViewDefinition, } from './language/index.js';
9
+ export type { AnyResolvedClass, BoundMethodOf, BoundMethodShortcutsOf, CallableResultOf, CallableInputOf, CallableInputModeOf, CallableOutputOf, ClassSatisfactionKeysOf, ClassDefinition, CoreDefinition, CoreEdge, FunctionAuth, FunctionDefinition, Inheritance, BinaryInput, BinaryInputProjection, CallableInputContract, MethodDefinition, MethodOwnerKeyOf, CallablePolicy, ClassPolicy, ClassRuleChecks, ClassRuleObject, ClassWritePolicy, CreateRuleChecks, EdgeClassPolicy, EdgeClassWritePolicy, EdgeRuleChecks, NodeClassCreatePolicy, NodeClassPolicy, NodeClassWritePolicy, PolicyCheckExpression, PolicyDefinition, PropertyImmutability, PropertyInputOf, PropertyAccessOf, PropertyOutputOf, PropertyShortcutsOf, PropertyValuesOf, ResolvedClass, ResolvedCoreDefinition, ResolvedCoreEndpoint, ResolvedFunction, ExecutableMethod, ResolvedMethod, ResolvedMethodCollection, ResolvedPolicy, ResolvedProperty, ResolvedView, MethodAccessOf, SelfMethodsOf, SelfPropertiesOf, SelfStaticMethodsOf, StaticMethodsOf, ViewDefinition, } from './language/index.js';
10
10
  export { acceptDefinitionRef, callableAddress, ClassKey, equalDefinitionRefs, isDefinitionRef, Key, MethodKey, PropertyKey, } from './addressing/index.js';
11
11
  export type { ClassRef, CoreRef, DefinitionBase, DefinitionKey, DefinitionRef, FunctionRef, MethodAddress, PolicyRef, Revision, ViewRef, } from './addressing/index.js';
12
12
  export type { Definition } from './language/index.js';
@@ -1,5 +1,5 @@
1
1
  import { compareUnicode } from '../../addressing/ordering.js';
2
- import { PolicyComposition } from '../policy/model/policy.js';
2
+ import { checkBindings, PolicyComposition } from '../policy/model/policy.js';
3
3
  /**
4
4
  * The language ceiling of a declared admission age, in seconds. Raising it later widens the
5
5
  * language; lowering it would refuse accepted Schemas.
@@ -27,8 +27,10 @@ export function admissionInputFields(policy) {
27
27
  }
28
28
  function collectInputFields(expression, fields) {
29
29
  if ('check' in expression) {
30
- if (expression.object.kind === 'input')
31
- fields.add(expression.object.field);
30
+ for (const operand of Object.values(checkBindings(expression))) {
31
+ if (operand.kind === 'input')
32
+ fields.add(operand.field);
33
+ }
32
34
  return;
33
35
  }
34
36
  if ('sameNode' in expression) {
@@ -1,7 +1,6 @@
1
1
  import type { ClassRef, DefinitionBase, PropertyKey } from '../../../addressing/index.js';
2
2
  import type { MethodRecord } from '../../callable/model/callable.js';
3
3
  import type { EdgeClassPolicy, EdgeClassWritePolicy, NodeClassCreatePolicy, NodeClassPolicy, NodeClassWritePolicy } from '../../policy/model/policy.js';
4
- import type { DataFacet } from './data.js';
5
4
  import type { EdgeContract } from './edge.js';
6
5
  import type { EdgePropertyDefinition, NodePropertyDefinition, PropertyFacet } from './property.js';
7
6
  export type ClassKind = 'node' | 'edge';
@@ -42,7 +41,7 @@ export type NodeUniqueTuple = readonly [PropertyKey, ...PropertyKey[]];
42
41
  * backend announces it to enforce Node keys, so a tuple is never ignored where it is not.
43
42
  */
44
43
  export type NodeUniqueForm = readonly ['property'];
45
- export interface NodeClassDefinition extends DefinitionBase<ClassRef>, PropertyFacet<NodePropertyDefinition>, DataFacet {
44
+ export interface NodeClassDefinition extends DefinitionBase<ClassRef>, PropertyFacet<NodePropertyDefinition> {
46
45
  readonly kind: 'node';
47
46
  readonly abstract: boolean;
48
47
  /** Absent when `'internal'`, the default, so a Class that keeps the default keeps its revision. */