@astrale-os/kernel-dsl 1.0.0-beta.34 → 1.0.0-beta.36
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/builder/lowering/schema/lifetime.js +3 -5
- package/dist/v1/builder/lowering/value/zod.js +3 -1
- 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.d.ts +1 -1
- package/dist/v1/language/class/unique.js +3 -13
- package/dist/v1/language/index.d.ts +2 -0
- package/dist/v1/language/index.js +2 -0
- 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/state/topology.d.ts +24 -0
- package/dist/v1/language/state/topology.js +60 -19
- package/dist/v1/language/validation/rule.js +1 -1
- package/dist/v1/language/value/evaluate/evaluator.js +4 -0
- package/dist/v1/language/value/evaluate/validity.optimization.js +4 -1
- package/dist/v1/language/value/inclusion/evidence.js +1 -1
- package/dist/v1/language/value/model/date.d.ts +8 -0
- package/dist/v1/language/value/model/date.js +19 -0
- package/dist/v1/language/value/model/instant.d.ts +0 -1
- package/dist/v1/language/value/model/instant.js +2 -15
- package/dist/v1/language/value/ordering.d.ts +6 -2
- package/dist/v1/language/value/ordering.js +36 -8
- package/dist/v1/language/value/profile/rules.js +3 -2
- package/dist/v1/language/value/profile/vocabulary.d.ts +1 -1
- package/dist/v1/language/value/profile/vocabulary.js +5 -0
- 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/.spec/schemas/domain-schema.schema.json +3 -0
- package/dist/v1/schema/compatibility/comparators/classes.js +10 -21
- package/dist/v1/schema/enforcement/derived.d.ts +5 -0
- package/dist/v1/schema/enforcement/derived.js +7 -2
- package/dist/v1/schema/enforcement/dispose.d.ts +16 -6
- package/dist/v1/schema/enforcement/dispose.js +16 -6
- package/dist/v1/schema/resolution/origins.js +3 -5
- package/dist/v1/schema/rule.js +4 -3
- package/dist/v1/schema/validation/class.js +39 -47
- 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/dist/v1/schema/validation/value-api.d.ts +2 -1
- package/dist/v1/schema/validation/value-api.js +2 -1
- package/dist/v1/schema/validation/value.json-schema.js +3 -3
- package/dist/value/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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);
|
|
@@ -169,7 +169,9 @@ function inspectCheck(def, pointer, diagnostics) {
|
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
171
|
if (def.check === 'string_format' && def.format !== 'regex') {
|
|
172
|
-
diagnostics.push(diagnostic('ZOD_SCHEMA_NOT_LOSSLESS', pointer,
|
|
172
|
+
diagnostics.push(diagnostic('ZOD_SCHEMA_NOT_LOSSLESS', pointer, def.format === 'date'
|
|
173
|
+
? 'Declare a calendar date with schema.values.date. Zod date formats are not lowered.'
|
|
174
|
+
: `Zod format ${String(def.format)} asserts acceptance, while V1 format is annotation-only.`));
|
|
173
175
|
return;
|
|
174
176
|
}
|
|
175
177
|
if (def.check === 'string_format' && def.format === 'regex' && def.pattern instanceof RegExp) {
|
|
@@ -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;
|
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
import { acceptPropertyRoot } from '../../../value/accept.js';
|
|
2
|
+
import { BoundaryError } from '../../../value/error.js';
|
|
2
3
|
import { isImmutableSnapshot } from '../../../value/immutable.optimization.js';
|
|
3
4
|
import { PropertyKey as admitPropertyKey } from '../../addressing/index.js';
|
|
4
5
|
import { compareCodeUnits } from '../../addressing/ordering.js';
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The PropertyValues `input` holds, or why it holds none: the value boundary's own BoundaryError,
|
|
8
|
+
* or a TypeError for a root that is not an object or a key that is not a canonical PropertyKey.
|
|
9
|
+
*/
|
|
10
|
+
export function validatePropertyValues(input, pointer = '') {
|
|
11
|
+
let admitted;
|
|
12
|
+
try {
|
|
13
|
+
admitted = acceptPropertyRoot(input);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
// The value boundary refuses with a BoundaryError, a host reflection failure included.
|
|
17
|
+
if (error instanceof BoundaryError)
|
|
18
|
+
return { ok: false, error };
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
7
21
|
if (admitted === null || typeof admitted !== 'object' || Array.isArray(admitted)) {
|
|
8
|
-
|
|
22
|
+
return refused(`Expected PropertyValues object at ${pointer || '/'}.`);
|
|
23
|
+
}
|
|
24
|
+
const entries = Object.entries(admitted);
|
|
25
|
+
const invalid = entries.find(([key]) => !admitPropertyKey.is(key));
|
|
26
|
+
if (invalid !== undefined) {
|
|
27
|
+
return refused(`Invalid canonical PropertyKey: ${JSON.stringify(invalid[0])}.`);
|
|
9
28
|
}
|
|
10
|
-
return
|
|
29
|
+
return {
|
|
30
|
+
ok: true,
|
|
31
|
+
values: createPropertyValues(entries.map(([key, value]) => [admitPropertyKey(key), value])),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function acceptPropertyValues(input, pointer = '') {
|
|
35
|
+
const result = validatePropertyValues(input, pointer);
|
|
36
|
+
if (!result.ok)
|
|
37
|
+
throw result.error;
|
|
38
|
+
return result.values;
|
|
11
39
|
}
|
|
12
40
|
export function createPropertyValues(entries) {
|
|
13
41
|
const output = Object.create(null);
|
|
@@ -20,6 +48,9 @@ export const PropertyValues = Object.freeze({
|
|
|
20
48
|
accept: acceptPropertyValues,
|
|
21
49
|
create: createPropertyValues,
|
|
22
50
|
});
|
|
51
|
+
function refused(message) {
|
|
52
|
+
return { ok: false, error: new TypeError(message) };
|
|
53
|
+
}
|
|
23
54
|
function freeze(value) {
|
|
24
55
|
if (value === null || typeof value !== 'object')
|
|
25
56
|
return value;
|
|
@@ -80,7 +80,7 @@ export declare function edgeUniqueForm(value: unknown): EdgeUniqueForm | undefin
|
|
|
80
80
|
export declare function enforcesEdgeUniqueTuple(forms: readonly EdgeUniqueForm[], value: unknown): boolean;
|
|
81
81
|
/**
|
|
82
82
|
* Whether a Property may be a key field (D-S1): a single-kind scalar by its ordering facet, a
|
|
83
|
-
* string, number, boolean or
|
|
83
|
+
* string, number, boolean, instant or date, that no automatic program writes.
|
|
84
84
|
*/
|
|
85
85
|
export declare function keyableProperty(ordering: OrderingKind | undefined, auto: unknown): boolean;
|
|
86
86
|
/**
|