@astrale-os/kernel-dsl 1.0.0-beta.33 → 1.0.0-beta.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/v1/addressing/class-key.js +16 -4
- package/dist/v1/addressing/key.d.ts +2 -0
- package/dist/v1/addressing/key.js +2 -0
- package/dist/v1/addressing/property-key.js +14 -2
- package/dist/v1/builder/lowering/schema/lifetime.js +3 -5
- package/dist/v1/compiled/admission/semantics/policy/callable.js +7 -29
- package/dist/v1/compiled/admission/semantics/policy/parity.js +4 -11
- package/dist/v1/compiled/admission/wire/core.js +2 -6
- package/dist/v1/compiled/admission/wire/property.js +6 -19
- package/dist/v1/domain/projection/classes.js +5 -7
- package/dist/v1/language/class/inheritance.d.ts +26 -2
- package/dist/v1/language/class/inheritance.js +63 -40
- package/dist/v1/language/class/lifetime.d.ts +7 -15
- package/dist/v1/language/class/lifetime.js +19 -40
- package/dist/v1/language/class/property-values.d.ts +13 -0
- package/dist/v1/language/class/property-values.js +35 -4
- package/dist/v1/language/class/unique.js +2 -12
- package/dist/v1/language/limits.d.ts +3 -1
- package/dist/v1/language/limits.js +3 -1
- package/dist/v1/language/policy/analysis/branches.d.ts +5 -1
- package/dist/v1/language/policy/analysis/branches.js +21 -5
- package/dist/v1/language/policy/analysis/budgets.d.ts +2 -0
- package/dist/v1/language/policy/analysis/budgets.js +7 -1
- package/dist/v1/language/policy/analysis/typing.d.ts +9 -1
- package/dist/v1/language/policy/analysis/typing.js +44 -49
- package/dist/v1/language/policy/normalization/normalize.js +1 -1
- package/dist/v1/language/state/topology.d.ts +24 -0
- package/dist/v1/language/state/topology.js +60 -19
- package/dist/v1/language/value/syntax/node-path/schema.d.ts +7 -0
- package/dist/v1/language/value/syntax/node-path/schema.js +32 -0
- package/dist/v1/schema/compatibility/comparators/classes.js +10 -21
- package/dist/v1/schema/enforcement/derived.js +1 -1
- package/dist/v1/schema/enforcement/install.d.ts +2 -2
- package/dist/v1/schema/enforcement/install.js +8 -2
- package/dist/v1/schema/resolution/origins.js +3 -5
- package/dist/v1/schema/rule.js +2 -1
- package/dist/v1/schema/validation/class.js +38 -46
- package/dist/v1/schema/validation/policy/budgets.js +1 -0
- package/dist/v1/schema/validation/policy/typing.js +7 -20
- package/dist/v1/schema/validation/policy/uses.js +5 -25
- package/package.json +1 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { acceptDefinitionRef } from './definition-ref.js';
|
|
2
|
-
import { Key } from './key.js';
|
|
2
|
+
import { Key, KNOWN_KEYS } from './key.js';
|
|
3
|
+
/**
|
|
4
|
+
* Texts `ClassKey.is` found canonical, at most `KNOWN_KEYS` of them: the test depends on the text
|
|
5
|
+
* alone, and stored rows name the same Classes again and again.
|
|
6
|
+
*/
|
|
7
|
+
const knownClassKeys = new Set();
|
|
3
8
|
/** Admit exact canonical Class-key text. */
|
|
4
9
|
export function ClassKey(input) {
|
|
5
10
|
if (!ClassKey.is(input)) {
|
|
@@ -18,13 +23,20 @@ export function ClassKey(input) {
|
|
|
18
23
|
}
|
|
19
24
|
ClassKey.of = of;
|
|
20
25
|
function is(input) {
|
|
21
|
-
if (typeof input !== 'string'
|
|
26
|
+
if (typeof input !== 'string')
|
|
27
|
+
return false;
|
|
28
|
+
if (knownClassKeys.has(input))
|
|
29
|
+
return true;
|
|
30
|
+
if (!Key.is(input))
|
|
22
31
|
return false;
|
|
23
32
|
// Only the coordinate is tested: an origin label may itself be `property` or `method`.
|
|
24
33
|
const coordinate = input.slice(input.indexOf(':') + 1);
|
|
25
|
-
|
|
34
|
+
const canonical = coordinate.startsWith('class.') &&
|
|
26
35
|
!coordinate.includes('.property.') &&
|
|
27
|
-
!coordinate.includes('.method.')
|
|
36
|
+
!coordinate.includes('.method.');
|
|
37
|
+
if (canonical && knownClassKeys.size < KNOWN_KEYS)
|
|
38
|
+
knownClassKeys.add(input);
|
|
39
|
+
return canonical;
|
|
28
40
|
}
|
|
29
41
|
ClassKey.is = is;
|
|
30
42
|
function ref(input) {
|
|
@@ -5,6 +5,8 @@ export type DefinitionKey<Origin extends Key.Origin = Key.Origin, Kind extends D
|
|
|
5
5
|
export type CoreKey<Origin extends Key.Origin = Key.Origin, Name extends string = string> = DefinitionKey<Origin, 'core', Name>;
|
|
6
6
|
export type PropertyKey<Origin extends Key.Origin = Key.Origin, Owner extends string = string, Name extends string = string> = `${Origin}:class.${Owner}.property.${Name}`;
|
|
7
7
|
export type Key = DefinitionKey | PropertyKey | MethodKey;
|
|
8
|
+
/** How many canonical key texts a key family's `is` keeps, so that a test of one is read back. */
|
|
9
|
+
export declare const KNOWN_KEYS = 16384;
|
|
8
10
|
export declare function Key(input: string): Key;
|
|
9
11
|
/** Canonical origin-qualified address operations. */
|
|
10
12
|
export declare namespace Key {
|
|
@@ -4,6 +4,8 @@ const DEFINITION_KEY = /^(?:class|function|policy|view)\.([A-Za-z][A-Za-z0-9_]*)
|
|
|
4
4
|
// The slug is the whole rest of the coordinate, its own `.` included: no member follows a Core key.
|
|
5
5
|
const CORE_KEY = /^core\.((?=.{1,100}$)[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)*)$/u;
|
|
6
6
|
const MEMBER_KEY = /^class\.([A-Za-z][A-Za-z0-9_]*)\.(property|method)\.([A-Za-z][A-Za-z0-9_]*)$/u;
|
|
7
|
+
/** How many canonical key texts a key family's `is` keeps, so that a test of one is read back. */
|
|
8
|
+
export const KNOWN_KEYS = 16_384;
|
|
7
9
|
/** The keys of frozen Definition coordinates, derived once each. */
|
|
8
10
|
const derived = new WeakMap();
|
|
9
11
|
export function Key(input) {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { acceptDefinitionRef } from './definition-ref.js';
|
|
2
|
-
import { Key } from './key.js';
|
|
2
|
+
import { Key, KNOWN_KEYS } from './key.js';
|
|
3
3
|
import { MEMBER_NAME_PATTERN, PROPERTY_KEY_PATTERN } from './patterns.js';
|
|
4
|
+
/**
|
|
5
|
+
* Texts `PropertyKey.is` found canonical, at most `KNOWN_KEYS` of them: the test depends on the
|
|
6
|
+
* text alone, and stored rows name the same keys again and again.
|
|
7
|
+
*/
|
|
8
|
+
const knownPropertyKeys = new Set();
|
|
4
9
|
export function PropertyKey(input) {
|
|
5
10
|
if (!PropertyKey.is(input)) {
|
|
6
11
|
throw new TypeError(`Invalid canonical PropertyKey: ${JSON.stringify(input)}.`);
|
|
@@ -18,7 +23,14 @@ export function PropertyKey(input) {
|
|
|
18
23
|
}
|
|
19
24
|
PropertyKey.of = of;
|
|
20
25
|
function is(input) {
|
|
21
|
-
|
|
26
|
+
if (typeof input !== 'string')
|
|
27
|
+
return false;
|
|
28
|
+
if (knownPropertyKeys.has(input))
|
|
29
|
+
return true;
|
|
30
|
+
const canonical = Key.is(input) && PROPERTY_KEY_PATTERN.test(input);
|
|
31
|
+
if (canonical && knownPropertyKeys.size < KNOWN_KEYS)
|
|
32
|
+
knownPropertyKeys.add(input);
|
|
33
|
+
return canonical;
|
|
22
34
|
}
|
|
23
35
|
PropertyKey.is = is;
|
|
24
36
|
function address(input) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Key } from '../../../addressing/key.js';
|
|
2
2
|
import { definitionRefIndex } from '../../../addressing/ordering.js';
|
|
3
|
-
import { isGraphRoot } from '../../../language/class/inheritance.js';
|
|
4
|
-
import {
|
|
3
|
+
import { contractEndpoints, isGraphRoot } from '../../../language/class/inheritance.js';
|
|
4
|
+
import { edgeLifetimes, lifetimeScope, reachesAnotherDomain, requiredEndpoint, } from '../../../language/class/lifetime.js';
|
|
5
5
|
import { BuilderError, diagnostic, escapeToken } from '../../schema/diagnostic.js';
|
|
6
6
|
/**
|
|
7
7
|
* Authoring refuses two Edge Classes that acceptance keeps, because a stored Schema must decode
|
|
@@ -23,13 +23,11 @@ export function assertAuthoredLifetimes(schema, dependencies) {
|
|
|
23
23
|
return [];
|
|
24
24
|
const pointer = `/classes/${escapeToken(name)}`;
|
|
25
25
|
const endpoints = contractEndpoints(declaration);
|
|
26
|
-
const keys = declaration.orientation === 'directed' ? ['source', 'target'] : ['0', '1'];
|
|
27
|
-
const counts = declaration.orientation === 'directed' ? ['outgoing', 'incoming'] : ['incident', 'incident'];
|
|
28
26
|
const found = [];
|
|
29
27
|
const required = requiredEndpoint(declaration);
|
|
30
28
|
const reaching = endpoints.find(({ endpoint }) => reachesAnotherDomain(schema.origin, endpoint, scope));
|
|
31
29
|
if (required !== undefined && reaching !== undefined)
|
|
32
|
-
found.push(diagnostic('BUILDER_EDGE_LIFETIME', `${pointer}/endpoints/${
|
|
30
|
+
found.push(diagnostic('BUILDER_EDGE_LIFETIME', `${pointer}/endpoints/${required.key}/${required.countKey}`, `${Key.of(declaration.ref)} endpoint ${reaching.endpoint.role} can hold Nodes of another ` +
|
|
33
31
|
`Domain, so it cannot restrict their deletion, and endpoint ${required.endpoint.role} ` +
|
|
34
32
|
`requires ${required.count} Edges, so it cannot detach: make ${required.endpoint.role} optional.`));
|
|
35
33
|
const lifetimes = edgeLifetimes(declaration, scope);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Key } from '../../../../addressing/index.js';
|
|
2
2
|
import { checkBindings, PolicyComposition, } from '../../../../language/policy/model/policy.js';
|
|
3
|
-
import {
|
|
3
|
+
import { singleNodePathFieldAccepts } from '../../../../language/value/syntax/node-path/schema.js';
|
|
4
4
|
import {} from '../../../model/schema.js';
|
|
5
5
|
import { fail } from '../../diagnostic.js';
|
|
6
6
|
import {} from '../context.js';
|
|
@@ -22,7 +22,7 @@ export function validateCallablePolicy(context, entry, expression, inputIndex, f
|
|
|
22
22
|
(fields === undefined ||
|
|
23
23
|
fields[object.field] === undefined ||
|
|
24
24
|
!isSingleNodePathField(context, entry, inputIndex, object.field))) {
|
|
25
|
-
fail(`${path}/${side}`, 'Callable Policy input target must be a direct required single-Node Path field.');
|
|
25
|
+
fail(`${path}/${side}`, 'Callable Policy input target must be a direct required single-Node Path field of a closed object input, neither carrying a combinator.');
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
return;
|
|
@@ -30,33 +30,11 @@ export function validateCallablePolicy(context, entry, expression, inputIndex, f
|
|
|
30
30
|
PolicyComposition.of(expression).operands.forEach((child, index) => validateCallablePolicy(context, entry, child, inputIndex, fields, instanceMethod, `${path}/${index}`));
|
|
31
31
|
}
|
|
32
32
|
function isSingleNodePathField(context, entry, inputIndex, field) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (properties === null || typeof properties !== 'object' || Array.isArray(properties))
|
|
39
|
-
return false;
|
|
40
|
-
const schemaValue = properties[field];
|
|
41
|
-
if (schemaValue === null || typeof schemaValue !== 'object' || Array.isArray(schemaValue))
|
|
42
|
-
return false;
|
|
43
|
-
const schema = schemaValue;
|
|
44
|
-
const annotationValue = schema['x-astrale-path'];
|
|
45
|
-
if (annotationValue === null ||
|
|
46
|
-
typeof annotationValue !== 'object' ||
|
|
47
|
-
Array.isArray(annotationValue))
|
|
48
|
-
return false;
|
|
49
|
-
const annotation = annotationValue;
|
|
50
|
-
return (root.type === 'object' &&
|
|
51
|
-
root.additionalProperties === false &&
|
|
52
|
-
Array.isArray(root.required) &&
|
|
53
|
-
root.required.includes(field) &&
|
|
54
|
-
schema.$ref === GRAPH_NODE_PATH_SCHEMA_ID &&
|
|
55
|
-
annotation.target === 'node' &&
|
|
56
|
-
annotation.cardinality === 'one' &&
|
|
57
|
-
Array.isArray(annotation.accepts) &&
|
|
58
|
-
annotation.accepts.length > 0 &&
|
|
59
|
-
annotation.accepts.every((ref) => isNodeClassRef(context, ref)));
|
|
33
|
+
const program = entry.values[inputIndex];
|
|
34
|
+
const accepts = program === undefined
|
|
35
|
+
? undefined
|
|
36
|
+
: singleNodePathFieldAccepts(program.nodes[program.root]?.schema, field);
|
|
37
|
+
return accepts !== undefined && accepts.every((ref) => isNodeClassRef(context, ref));
|
|
60
38
|
}
|
|
61
39
|
function isNodeClassRef(context, value) {
|
|
62
40
|
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
@@ -39,19 +39,12 @@ export function validatePolicyParity(context, entry, entryIndex, policies, origi
|
|
|
39
39
|
if (measure !== undefined && exceededLimits(measure).length > 0) {
|
|
40
40
|
fail(path, 'Policy expansion exceeds the V1 depth, branch, Edge, or Domain budget.');
|
|
41
41
|
}
|
|
42
|
-
const branches = typing.expandedBranches(name
|
|
42
|
+
const branches = typing.expandedBranches(name);
|
|
43
43
|
if (branches !== undefined) {
|
|
44
|
-
for (const
|
|
45
|
-
|
|
46
|
-
if (mode === 'named')
|
|
47
|
-
continue;
|
|
48
|
-
if (mode === undefined)
|
|
44
|
+
for (const { kind } of typing.defaultUseFaults(branches)) {
|
|
45
|
+
if (kind === 'target')
|
|
49
46
|
fail(path, 'Expanded Policy branches must use one coherent target mode.');
|
|
50
|
-
|
|
51
|
-
? { kind: 'object', object: { kind: 'default' } }
|
|
52
|
-
: { kind: 'edge', source: { kind: 'default' }, target: { kind: 'default' } };
|
|
53
|
-
if (!typing.branchIsTyped(branch, use))
|
|
54
|
-
fail(path, 'A Policy branch has contradictory endpoint or repeat contracts.');
|
|
47
|
+
fail(path, 'A Policy branch has contradictory endpoint or repeat contracts.');
|
|
55
48
|
}
|
|
56
49
|
}
|
|
57
50
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {} from '@astrale-os/kernel-dsl/value';
|
|
2
|
-
import {
|
|
2
|
+
import { validatePropertyValues } from '../../../language/class/property-values.js';
|
|
3
3
|
import { invalid } from '../diagnostic.js';
|
|
4
4
|
import { definitionRef, coreEndpoint } from './reference.js';
|
|
5
5
|
import { object, exact } from './value.js';
|
|
@@ -23,10 +23,6 @@ export function compiledCoreEdge(input, path) {
|
|
|
23
23
|
return value;
|
|
24
24
|
}
|
|
25
25
|
function propertyValues(input, label, path) {
|
|
26
|
-
|
|
27
|
-
PropertyValues.accept(input, path);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
26
|
+
if (!validatePropertyValues(input, path).ok)
|
|
30
27
|
invalid(label, undefined, path);
|
|
31
|
-
}
|
|
32
28
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {} from '@astrale-os/kernel-dsl/value';
|
|
2
2
|
import {} from '../../../language/state/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import { holdsStates, validateStateTopology } from '../../../language/state/topology.js';
|
|
4
4
|
import { classifyValueProgramOrdering } from '../../../language/value/ordering.js';
|
|
5
5
|
import {} from '../../model/schema.js';
|
|
6
6
|
import { invalid } from '../diagnostic.js';
|
|
@@ -31,29 +31,16 @@ export function compiledProperty(input, values, node, path) {
|
|
|
31
31
|
if (value.state !== undefined) {
|
|
32
32
|
if (!node)
|
|
33
33
|
invalid('Property state placement', 'COMPILED_SOURCE_INVALID', `${path}/state`);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
topology = admitStateTopology(value.state);
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
34
|
+
const result = validateStateTopology(value.state);
|
|
35
|
+
if (!result.ok)
|
|
39
36
|
invalid('Property state topology', 'COMPILED_SOURCE_INVALID', `${path}/state`);
|
|
40
|
-
}
|
|
41
37
|
const program = values[valueIndex];
|
|
42
38
|
const schema = program.nodes[program.root].schema;
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const schemaMatches = schema !== null &&
|
|
46
|
-
typeof schema === 'object' &&
|
|
47
|
-
!Array.isArray(schema) &&
|
|
48
|
-
Object.keys(schemaObject).length === 2 &&
|
|
49
|
-
schemaObject.type === 'string' &&
|
|
50
|
-
Array.isArray(schemaObject.enum) &&
|
|
51
|
-
schemaObject.enum.length === states.length &&
|
|
52
|
-
schemaObject.enum.every((state, index) => state === states[index]);
|
|
53
|
-
if (!value.required || value.auto !== undefined || !schemaMatches) {
|
|
39
|
+
const { required, auto } = value;
|
|
40
|
+
if (!holdsStates({ required, auto }, schema, result.topology, 'canonical')) {
|
|
54
41
|
invalid('Property state contract', 'COMPILED_SOURCE_INVALID', `${path}/state`);
|
|
55
42
|
}
|
|
56
|
-
state = topology;
|
|
43
|
+
state = result.topology;
|
|
57
44
|
}
|
|
58
45
|
const { ordering: _, ...declared } = value;
|
|
59
46
|
const ordering = classifyValueProgramOrdering(values[valueIndex]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Key, MethodKey as MethodKeyValue, PropertyKey as PropertyKeyValue, } from '../../addressing/index.js';
|
|
2
2
|
import { isMethodExecutable } from '../../language/callable/executable.js';
|
|
3
3
|
import { classSatisfies } from '../../language/class/inheritance.js';
|
|
4
|
-
import {
|
|
4
|
+
import { validatePropertyValues } from '../../language/class/property-values.js';
|
|
5
5
|
import { appendPointer } from '../../language/value/syntax/pointer.js';
|
|
6
6
|
import { createMethodCollection, createPropertyCollection } from '../namespace/member-collection.js';
|
|
7
7
|
export function createClasses(definitions, validation) {
|
|
@@ -123,19 +123,17 @@ function validateProperties(abstract, properties, input) {
|
|
|
123
123
|
},
|
|
124
124
|
];
|
|
125
125
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
values = acceptPropertyValues(input, '/properties');
|
|
129
|
-
}
|
|
130
|
-
catch (cause) {
|
|
126
|
+
const accepted = validatePropertyValues(input, '/properties');
|
|
127
|
+
if (!accepted.ok) {
|
|
131
128
|
return [
|
|
132
129
|
{
|
|
133
130
|
code: 'DOMAIN_PROPERTY_INPUT_INVALID',
|
|
134
131
|
pointer: '/properties',
|
|
135
|
-
message:
|
|
132
|
+
message: accepted.error.message,
|
|
136
133
|
},
|
|
137
134
|
];
|
|
138
135
|
}
|
|
136
|
+
const { values } = accepted;
|
|
139
137
|
const diagnostics = [];
|
|
140
138
|
for (const key of Object.keys(values)) {
|
|
141
139
|
if (!properties.has(key)) {
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import type { ClassRef } from '../../addressing/index.js';
|
|
2
2
|
import type { ClassKind, Inheritance } from './model/class.js';
|
|
3
|
-
import type { EdgeContract, EdgeCount } from './model/edge.js';
|
|
4
|
-
/** A Class as
|
|
3
|
+
import type { EdgeContract, EdgeCount, EdgeEndpointBase } from './model/edge.js';
|
|
4
|
+
/** A Class as its ancestry reads it, shared by source, compiled and resolved Class admission. */
|
|
5
5
|
export interface ClassAncestry {
|
|
6
6
|
readonly ref: ClassRef;
|
|
7
7
|
readonly kind: ClassKind;
|
|
8
8
|
readonly extends: readonly ClassRef[];
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* `start` and each Class it inherits from, each once, in the order a depth-first walk of the
|
|
12
|
+
* declared parents meets them: `start` first, a Class before its own parents. `resolve` reads a
|
|
13
|
+
* parent; one it cannot read, or of another kind, is not walked, nor what it extends.
|
|
14
|
+
*/
|
|
15
|
+
export declare function ancestry<Class extends ClassAncestry>(start: Class, resolve: (ref: ClassRef) => Class | undefined): Iterable<Class>;
|
|
16
|
+
/**
|
|
17
|
+
* Each node `roots` reach through `parentsOf`, roots included, once, in the order a depth-first
|
|
18
|
+
* walk meets it: a node before its parents, read one at a time as the walk reaches them, so the
|
|
19
|
+
* order is that of the recursive walk. A chain can be as long as a document allows, so the walk
|
|
20
|
+
* holds its own stack.
|
|
21
|
+
*/
|
|
22
|
+
export declare function walkAncestry<Node>(roots: Iterable<Node>, parentsOf: (node: Node) => Iterable<Node>): Generator<Node, void, undefined>;
|
|
10
23
|
/** The origin of the Kernel, whose Schema every Domain depends on. */
|
|
11
24
|
export declare const KERNEL_ORIGIN = "kernel.astrale.ai";
|
|
12
25
|
/** Kernel graph roots are intrinsic supertypes, not authored structural Edge contracts. */
|
|
@@ -24,6 +37,17 @@ export declare function inheritanceOf(declaration: {
|
|
|
24
37
|
export declare function admitsForeignSubclass(declaration: {
|
|
25
38
|
readonly inheritance?: Inheritance;
|
|
26
39
|
}): boolean;
|
|
40
|
+
/** One endpoint of an Edge contract, where it is declared, and how many Edges each Node in it has. */
|
|
41
|
+
export interface ContractEndpoint {
|
|
42
|
+
/** Its key under `endpoints`: `source` or `target`, or `0` or `1` when undirected. */
|
|
43
|
+
readonly key: 'source' | 'target' | '0' | '1';
|
|
44
|
+
readonly endpoint: EdgeEndpointBase;
|
|
45
|
+
/** The key of the endpoint its count is declared under. */
|
|
46
|
+
readonly countKey: 'outgoing' | 'incoming' | 'incident';
|
|
47
|
+
readonly count: EdgeCount;
|
|
48
|
+
}
|
|
49
|
+
/** The endpoints of an Edge contract in order: source then target, or the two incident ones. */
|
|
50
|
+
export declare function contractEndpoints(contract: EdgeContract): readonly [ContractEndpoint, ContractEndpoint];
|
|
27
51
|
/**
|
|
28
52
|
* Whether `child` safely refines its parent Edge contract `parent`: same orientation, at least the
|
|
29
53
|
* parent's constraints, and endpoints whose accepted Classes `satisfies` one the paired parent
|
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
import { cycleEdges } from '../cycle.js';
|
|
2
|
+
/**
|
|
3
|
+
* `start` and each Class it inherits from, each once, in the order a depth-first walk of the
|
|
4
|
+
* declared parents meets them: `start` first, a Class before its own parents. `resolve` reads a
|
|
5
|
+
* parent; one it cannot read, or of another kind, is not walked, nor what it extends.
|
|
6
|
+
*/
|
|
7
|
+
export function ancestry(start, resolve) {
|
|
8
|
+
return walkAncestry([start], function* parents(value) {
|
|
9
|
+
for (const ref of value.extends) {
|
|
10
|
+
const parent = resolve(ref);
|
|
11
|
+
if (parent !== undefined && parent.kind === value.kind)
|
|
12
|
+
yield parent;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Each node `roots` reach through `parentsOf`, roots included, once, in the order a depth-first
|
|
18
|
+
* walk meets it: a node before its parents, read one at a time as the walk reaches them, so the
|
|
19
|
+
* order is that of the recursive walk. A chain can be as long as a document allows, so the walk
|
|
20
|
+
* holds its own stack.
|
|
21
|
+
*/
|
|
22
|
+
export function* walkAncestry(roots, parentsOf) {
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
const stack = [roots[Symbol.iterator]()];
|
|
25
|
+
while (stack.length > 0) {
|
|
26
|
+
const next = stack.at(-1).next();
|
|
27
|
+
if (next.done === true)
|
|
28
|
+
stack.pop();
|
|
29
|
+
else if (!seen.has(next.value)) {
|
|
30
|
+
seen.add(next.value);
|
|
31
|
+
yield next.value;
|
|
32
|
+
stack.push(parentsOf(next.value)[Symbol.iterator]());
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
1
36
|
/** The origin of the Kernel, whose Schema every Domain depends on. */
|
|
2
37
|
export const KERNEL_ORIGIN = 'kernel.astrale.ai';
|
|
3
38
|
/** Kernel graph roots are intrinsic supertypes, not authored structural Edge contracts. */
|
|
@@ -11,19 +46,10 @@ export function classSatisfies(candidate, required, resolve) {
|
|
|
11
46
|
return false;
|
|
12
47
|
if (isGraphRoot(required))
|
|
13
48
|
return true;
|
|
14
|
-
const
|
|
15
|
-
const visit = (value) => {
|
|
49
|
+
for (const value of ancestry(candidate, resolve))
|
|
16
50
|
if (value.ref.origin === required.ref.origin && value.ref.name === required.ref.name)
|
|
17
51
|
return true;
|
|
18
|
-
|
|
19
|
-
return false;
|
|
20
|
-
seen.add(value);
|
|
21
|
-
return value.extends.some((ref) => {
|
|
22
|
-
const parent = resolve(ref);
|
|
23
|
-
return parent !== undefined && parent.kind === required.kind && visit(parent);
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
return visit(candidate);
|
|
52
|
+
return false;
|
|
27
53
|
}
|
|
28
54
|
/** The inheritance a Class declares, `'internal'` when it declares none. */
|
|
29
55
|
export function inheritanceOf(declaration) {
|
|
@@ -36,6 +62,21 @@ export function inheritanceOf(declaration) {
|
|
|
36
62
|
export function admitsForeignSubclass(declaration) {
|
|
37
63
|
return inheritanceOf(declaration) === 'open';
|
|
38
64
|
}
|
|
65
|
+
/** The endpoints of an Edge contract in order: source then target, or the two incident ones. */
|
|
66
|
+
export function contractEndpoints(contract) {
|
|
67
|
+
if (contract.orientation === 'directed') {
|
|
68
|
+
const { source, target } = contract.endpoints;
|
|
69
|
+
return [
|
|
70
|
+
{ key: 'source', endpoint: source, countKey: 'outgoing', count: source.outgoing },
|
|
71
|
+
{ key: 'target', endpoint: target, countKey: 'incoming', count: target.incoming },
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
const [first, second] = contract.endpoints;
|
|
75
|
+
return [
|
|
76
|
+
{ key: '0', endpoint: first, countKey: 'incident', count: first.incident },
|
|
77
|
+
{ key: '1', endpoint: second, countKey: 'incident', count: second.incident },
|
|
78
|
+
];
|
|
79
|
+
}
|
|
39
80
|
/**
|
|
40
81
|
* Whether `child` safely refines its parent Edge contract `parent`: same orientation, at least the
|
|
41
82
|
* parent's constraints, and endpoints whose accepted Classes `satisfies` one the paired parent
|
|
@@ -48,21 +89,17 @@ export function edgeContractRefines(child, parent, satisfies) {
|
|
|
48
89
|
return false;
|
|
49
90
|
if (parent.constraints.acyclic === true && child.constraints.acyclic !== true)
|
|
50
91
|
return false;
|
|
51
|
-
|
|
52
|
-
if (child.orientation === 'directed' && parent.orientation === 'directed') {
|
|
53
|
-
return (endpointRefines(child.endpoints.source, parent.endpoints.source) &&
|
|
54
|
-
countRefines(child.endpoints.source.outgoing, parent.endpoints.source.outgoing) &&
|
|
55
|
-
endpointRefines(child.endpoints.target, parent.endpoints.target) &&
|
|
56
|
-
countRefines(child.endpoints.target.incoming, parent.endpoints.target.incoming));
|
|
57
|
-
}
|
|
58
|
-
if (child.orientation !== 'undirected' || parent.orientation !== 'undirected')
|
|
92
|
+
if (child.orientation !== parent.orientation)
|
|
59
93
|
return false;
|
|
60
|
-
const refines = (
|
|
61
|
-
countRefines(
|
|
62
|
-
const
|
|
63
|
-
|
|
94
|
+
const refines = (own, inherited) => own.endpoint.accepts.every((accepted) => satisfies(accepted, inherited.endpoint.accepts)) &&
|
|
95
|
+
countRefines(own.count, inherited.count);
|
|
96
|
+
const [first, second] = contractEndpoints(child);
|
|
97
|
+
const [parentFirst, parentSecond] = contractEndpoints(parent);
|
|
98
|
+
if (refines(first, parentFirst) && refines(second, parentSecond))
|
|
64
99
|
return true;
|
|
65
|
-
return
|
|
100
|
+
return (child.orientation === 'undirected' &&
|
|
101
|
+
refines(first, parentSecond) &&
|
|
102
|
+
refines(second, parentFirst));
|
|
66
103
|
}
|
|
67
104
|
function countRefines(child, parent) {
|
|
68
105
|
const [childMinimum, childMaximum] = countBounds(child);
|
|
@@ -90,20 +127,6 @@ export function hasDirectedCycle(edges) {
|
|
|
90
127
|
targets.push(edge.target.key);
|
|
91
128
|
outgoing.set(edge.source.key, targets);
|
|
92
129
|
}
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
const visit = (key) => {
|
|
96
|
-
if (visiting.has(key))
|
|
97
|
-
return true;
|
|
98
|
-
if (visited.has(key))
|
|
99
|
-
return false;
|
|
100
|
-
visiting.add(key);
|
|
101
|
-
for (const target of outgoing.get(key) ?? [])
|
|
102
|
-
if (visit(target))
|
|
103
|
-
return true;
|
|
104
|
-
visiting.delete(key);
|
|
105
|
-
visited.add(key);
|
|
106
|
-
return false;
|
|
107
|
-
};
|
|
108
|
-
return [...outgoing.keys()].some(visit);
|
|
130
|
+
const [cycle] = cycleEdges(outgoing.keys(), (key) => outgoing.get(key) ?? []);
|
|
131
|
+
return cycle !== undefined;
|
|
109
132
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ClassRef } from '../../addressing/index.js';
|
|
2
2
|
import type { ClassDefinition, EdgeClassDefinition } from './model/class.js';
|
|
3
|
-
import type { EdgeContract,
|
|
3
|
+
import type { EdgeContract, EdgeEndpointBase, EdgeLifetime } from './model/edge.js';
|
|
4
|
+
import { type ContractEndpoint } from './inheritance.js';
|
|
4
5
|
export type { EdgeLifetime } from './model/edge.js';
|
|
5
6
|
/** The Classes lifetimes read: those of an Edge Class's Domain and of its dependency closure. */
|
|
6
7
|
export interface LifetimeScope {
|
|
@@ -12,13 +13,6 @@ export interface LifetimeScope {
|
|
|
12
13
|
}
|
|
13
14
|
/** The lifetime scope of `classes`. */
|
|
14
15
|
export declare function lifetimeScope(classes: Iterable<ClassDefinition>): LifetimeScope;
|
|
15
|
-
/** One endpoint of an Edge contract and how many Edges of the Class each Node in it has. */
|
|
16
|
-
export interface ContractEndpoint {
|
|
17
|
-
readonly endpoint: EdgeEndpointBase;
|
|
18
|
-
readonly count: EdgeCount;
|
|
19
|
-
}
|
|
20
|
-
/** The endpoints of an Edge contract in order: source then target, or the two incident ones. */
|
|
21
|
-
export declare function contractEndpoints(contract: EdgeContract): readonly [ContractEndpoint, ContractEndpoint];
|
|
22
16
|
/**
|
|
23
17
|
* Whether an endpoint of an Edge Class of `origin` can hold a Node of another Domain: it accepts a
|
|
24
18
|
* Class `origin` does not own, or one another Domain may extend. The Kernel's own relations are the
|
|
@@ -36,9 +30,9 @@ export declare function reachesAnotherDomain(origin: ClassRef['origin'], endpoin
|
|
|
36
30
|
* detaching could break (`requiredEndpoint`). Every other endpoint restricts.
|
|
37
31
|
*/
|
|
38
32
|
export declare function edgeLifetimes(edge: EdgeClassDefinition, scope: LifetimeScope): readonly [EdgeLifetime, EdgeLifetime];
|
|
39
|
-
/** One breach of the lifetime laws at one endpoint of an Edge Class: its
|
|
33
|
+
/** One breach of the lifetime laws at one endpoint of an Edge Class: its key and why. */
|
|
40
34
|
export interface LifetimeBreach {
|
|
41
|
-
readonly
|
|
35
|
+
readonly key: ContractEndpoint['key'];
|
|
42
36
|
readonly reason: string;
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
@@ -48,9 +42,7 @@ export interface LifetimeBreach {
|
|
|
48
42
|
*/
|
|
49
43
|
export declare function lifetimeBreaches(edge: EdgeClassDefinition, scope: LifetimeScope): readonly LifetimeBreach[];
|
|
50
44
|
/**
|
|
51
|
-
* The first endpoint of an Edge Class that requires an Edge, if one does
|
|
52
|
-
*
|
|
45
|
+
* The first endpoint of an Edge Class that requires an Edge, if one does. Detaching there could
|
|
46
|
+
* leave a Node below its count, so an endpoint of such a Class never detaches.
|
|
53
47
|
*/
|
|
54
|
-
export declare function requiredEndpoint(edge: EdgeContract):
|
|
55
|
-
readonly index: 0 | 1;
|
|
56
|
-
}) | undefined;
|
|
48
|
+
export declare function requiredEndpoint(edge: EdgeContract): ContractEndpoint | undefined;
|
|
@@ -1,39 +1,26 @@
|
|
|
1
1
|
import { definitionRefIndex } from '../../addressing/ordering.js';
|
|
2
|
-
import { KERNEL_ORIGIN } from './inheritance.js';
|
|
2
|
+
import { contractEndpoints, KERNEL_ORIGIN, walkAncestry, } from './inheritance.js';
|
|
3
3
|
/** The lifetime scope of `classes`. */
|
|
4
4
|
export function lifetimeScope(classes) {
|
|
5
5
|
const declarations = new Map();
|
|
6
6
|
for (const declaration of classes)
|
|
7
7
|
declarations.set(definitionRefIndex(declaration.ref), declaration);
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
open(declaration.ref);
|
|
8
|
+
const open = [...declarations.values()]
|
|
9
|
+
.filter((declaration) => declaration.kind === 'node' && declaration.inheritance === 'open')
|
|
10
|
+
.map((declaration) => definitionRefIndex(declaration.ref));
|
|
11
|
+
// A Node of another Domain may be of an open Class, so of each Class of its Domain it extends.
|
|
12
|
+
const extendable = new Set(walkAncestry(open, (key) => {
|
|
13
|
+
const declaration = declarations.get(key);
|
|
14
|
+
if (declaration === undefined)
|
|
15
|
+
return [];
|
|
16
|
+
return declaration.extends
|
|
17
|
+
.filter((parent) => parent.origin === declaration.ref.origin)
|
|
18
|
+
.map(definitionRefIndex);
|
|
19
|
+
}));
|
|
21
20
|
return Object.freeze({
|
|
22
21
|
extendable: (ref) => extendable.has(definitionRefIndex(ref)),
|
|
23
22
|
});
|
|
24
23
|
}
|
|
25
|
-
/** The endpoints of an Edge contract in order: source then target, or the two incident ones. */
|
|
26
|
-
export function contractEndpoints(contract) {
|
|
27
|
-
return contract.orientation === 'directed'
|
|
28
|
-
? [
|
|
29
|
-
{ endpoint: contract.endpoints.source, count: contract.endpoints.source.outgoing },
|
|
30
|
-
{ endpoint: contract.endpoints.target, count: contract.endpoints.target.incoming },
|
|
31
|
-
]
|
|
32
|
-
: [
|
|
33
|
-
{ endpoint: contract.endpoints[0], count: contract.endpoints[0].incident },
|
|
34
|
-
{ endpoint: contract.endpoints[1], count: contract.endpoints[1].incident },
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
24
|
/**
|
|
38
25
|
* Whether an endpoint of an Edge Class of `origin` can hold a Node of another Domain: it accepts a
|
|
39
26
|
* Class `origin` does not own, or one another Domain may extend. The Kernel's own relations are the
|
|
@@ -65,31 +52,23 @@ export function edgeLifetimes(edge, scope) {
|
|
|
65
52
|
*/
|
|
66
53
|
export function lifetimeBreaches(edge, scope) {
|
|
67
54
|
const required = requiredEndpoint(edge)?.count;
|
|
68
|
-
return Object.freeze(contractEndpoints(edge).flatMap(({ endpoint }
|
|
69
|
-
const at = index;
|
|
55
|
+
return Object.freeze(contractEndpoints(edge).flatMap(({ key, endpoint }) => {
|
|
70
56
|
if (endpoint.onDelete === 'restrict' &&
|
|
71
57
|
reachesAnotherDomain(edge.ref.origin, endpoint, scope))
|
|
72
58
|
return [
|
|
73
|
-
{
|
|
74
|
-
index: at,
|
|
75
|
-
reason: 'can hold Nodes of another Domain and cannot restrict their deletion.',
|
|
76
|
-
},
|
|
59
|
+
{ key, reason: 'can hold Nodes of another Domain and cannot restrict their deletion.' },
|
|
77
60
|
];
|
|
78
61
|
if (endpoint.onDelete === 'detach' && required !== undefined)
|
|
79
62
|
return [
|
|
80
|
-
{
|
|
81
|
-
index: at,
|
|
82
|
-
reason: `cannot detach: an endpoint of the Class requires ${required} Edges.`,
|
|
83
|
-
},
|
|
63
|
+
{ key, reason: `cannot detach: an endpoint of the Class requires ${required} Edges.` },
|
|
84
64
|
];
|
|
85
65
|
return [];
|
|
86
66
|
}));
|
|
87
67
|
}
|
|
88
68
|
/**
|
|
89
|
-
* The first endpoint of an Edge Class that requires an Edge, if one does
|
|
90
|
-
*
|
|
69
|
+
* The first endpoint of an Edge Class that requires an Edge, if one does. Detaching there could
|
|
70
|
+
* leave a Node below its count, so an endpoint of such a Class never detaches.
|
|
91
71
|
*/
|
|
92
72
|
export function requiredEndpoint(edge) {
|
|
93
|
-
|
|
94
|
-
return index === -1 ? undefined : { ...contractEndpoints(edge)[index], index: index };
|
|
73
|
+
return contractEndpoints(edge).find(({ count }) => count === '1' || count === '1..*');
|
|
95
74
|
}
|
|
@@ -9,6 +9,19 @@ export interface PropertyValuesOperations {
|
|
|
9
9
|
accept(input: unknown, pointer?: string): PropertyValues;
|
|
10
10
|
create(entries: Iterable<readonly [PropertyKey, PortableValue]>): PropertyValues;
|
|
11
11
|
}
|
|
12
|
+
/** PropertyValues, or the TypeError that says why an input holds none. */
|
|
13
|
+
export type PropertyValuesResult = {
|
|
14
|
+
readonly ok: true;
|
|
15
|
+
readonly values: PropertyValues;
|
|
16
|
+
} | {
|
|
17
|
+
readonly ok: false;
|
|
18
|
+
readonly error: TypeError;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The PropertyValues `input` holds, or why it holds none: the value boundary's own BoundaryError,
|
|
22
|
+
* or a TypeError for a root that is not an object or a key that is not a canonical PropertyKey.
|
|
23
|
+
*/
|
|
24
|
+
export declare function validatePropertyValues(input: unknown, pointer?: string): PropertyValuesResult;
|
|
12
25
|
export declare function acceptPropertyValues(input: unknown, pointer?: string): PropertyValues;
|
|
13
26
|
export declare function createPropertyValues(entries: Iterable<readonly [PropertyKey, PortableValue]>): PropertyValues;
|
|
14
27
|
export declare const PropertyValues: PropertyValuesOperations;
|