@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
|
@@ -16,3 +16,35 @@ export function hasNodePathAnnotation(schema) {
|
|
|
16
16
|
schema.$ref === GRAPH_NODE_PATH_SCHEMA_ID &&
|
|
17
17
|
Object.hasOwn(schema, 'x-astrale-path'));
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* The `accepts` of `field` where the callable input `input` binds it to one Node: a direct required
|
|
21
|
+
* single-Node Path field of a closed object input, neither of them carrying a combinator, so that
|
|
22
|
+
* the field's own annotation alone states the Classes of its Node. Otherwise the input binds no Node
|
|
23
|
+
* there: `undefined`. Source and compiled admission both read a Policy input binding through it.
|
|
24
|
+
*/
|
|
25
|
+
export function singleNodePathFieldAccepts(input, field) {
|
|
26
|
+
if (!isJsonObject(input) || hasCombinator(input))
|
|
27
|
+
return undefined;
|
|
28
|
+
const { properties, required } = input;
|
|
29
|
+
if (input.type !== 'object' ||
|
|
30
|
+
input.additionalProperties !== false ||
|
|
31
|
+
!Array.isArray(required) ||
|
|
32
|
+
!required.includes(field) ||
|
|
33
|
+
!isJsonObject(properties) ||
|
|
34
|
+
!Object.hasOwn(properties, field))
|
|
35
|
+
return undefined;
|
|
36
|
+
const schema = properties[field];
|
|
37
|
+
if (!isJsonObject(schema) || hasCombinator(schema) || schema.$ref !== GRAPH_NODE_PATH_SCHEMA_ID)
|
|
38
|
+
return undefined;
|
|
39
|
+
const annotation = schema['x-astrale-path'];
|
|
40
|
+
return isJsonObject(annotation) &&
|
|
41
|
+
annotation.target === 'node' &&
|
|
42
|
+
annotation.cardinality === 'one' &&
|
|
43
|
+
Array.isArray(annotation.accepts) &&
|
|
44
|
+
annotation.accepts.length > 0
|
|
45
|
+
? annotation.accepts
|
|
46
|
+
: undefined;
|
|
47
|
+
}
|
|
48
|
+
function hasCombinator(schema) {
|
|
49
|
+
return ['allOf', 'anyOf', 'oneOf', 'not', 'if', 'then', 'else'].some((keyword) => Object.hasOwn(schema, keyword));
|
|
50
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { compareUnicode } from '../../../addressing/ordering.js';
|
|
2
|
+
import { contractEndpoints, walkAncestry, } from '../../../language/class/inheritance.js';
|
|
2
3
|
import { compareEdgeUniqueTuples, coveringEdgeUniqueTuples, } from '../../../language/class/unique.js';
|
|
3
4
|
import { deepFreeze } from '../../../language/freeze.js';
|
|
4
5
|
import { isClassRuleChecks } from '../../../language/policy/model/policy.js';
|
|
@@ -62,20 +63,19 @@ export function edgeEndpoints(context, coordinate) {
|
|
|
62
63
|
const declaration = context.schemas.get(coordinate.ref.origin)?.classes[coordinate.ref.name];
|
|
63
64
|
if (declaration?.kind !== 'edge')
|
|
64
65
|
return undefined;
|
|
65
|
-
const accepts = ({
|
|
66
|
+
const accepts = ({ endpoint }) => endpoint.accepts.map(keyForDefinitionRef).sort(compareUnicode);
|
|
67
|
+
const [first, second] = contractEndpoints(declaration);
|
|
66
68
|
return deepFreeze(declaration.orientation === 'directed'
|
|
67
69
|
? {
|
|
68
70
|
coordinate: 'class',
|
|
69
71
|
orientation: 'directed',
|
|
70
|
-
source: accepts(
|
|
71
|
-
target: accepts(
|
|
72
|
+
source: accepts(first),
|
|
73
|
+
target: accepts(second),
|
|
72
74
|
}
|
|
73
75
|
: {
|
|
74
76
|
coordinate: 'class',
|
|
75
77
|
orientation: 'undirected',
|
|
76
|
-
endpoints:
|
|
77
|
-
.map(accepts)
|
|
78
|
-
.sort((left, right) => compareUnicode(left.join('\n'), right.join('\n'))),
|
|
78
|
+
endpoints: [accepts(first), accepts(second)].sort((left, right) => compareUnicode(left.join('\n'), right.join('\n'))),
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
export function propertyMeaning(field) {
|
|
@@ -88,21 +88,10 @@ export function propertyMeaning(field) {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
function ancestorKeys(context, ref) {
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return;
|
|
96
|
-
for (const parent of declaration.extends) {
|
|
97
|
-
const key = keyForDefinitionRef(parent);
|
|
98
|
-
if (seen.has(key))
|
|
99
|
-
continue;
|
|
100
|
-
seen.add(key);
|
|
101
|
-
visit(parent);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
visit(ref);
|
|
105
|
-
return [...seen].sort(compareUnicode);
|
|
91
|
+
// Each declared parent ref is walked once; one its schema lacks still names an ancestor.
|
|
92
|
+
const parentsOf = (current) => context.schemas.get(current.origin)?.classes[current.name]?.extends ?? [];
|
|
93
|
+
const keys = new Set(Array.from(walkAncestry(parentsOf(ref), parentsOf), keyForDefinitionRef));
|
|
94
|
+
return [...keys].sort(compareUnicode);
|
|
106
95
|
}
|
|
107
96
|
/**
|
|
108
97
|
* The uniqueness tuples covering an Edge Class (`coveringEdgeUniqueTuples`): those it and each of
|
|
@@ -172,7 +172,7 @@ const rows = {
|
|
|
172
172
|
},
|
|
173
173
|
DEFINITION_PROJECTION: {
|
|
174
174
|
subjects: ['fact.projection'],
|
|
175
|
-
statement: 'Installing a Domain projects each of its Definitions as one Node at its canonical NodePath with exactly one `of_domain` Edge, its member locator. The Domain Node holds the name and, as `iconSmall`, `iconMedium` or `iconLarge`, the drawing of each size its icon declares, and one `entrypoint` Edge joins it to the View it declares, none without one. A Core Edge endpoint that is no Core Node is a path into the projected declarations.',
|
|
175
|
+
statement: 'Installing a Domain projects each of its Definitions as one Node at its canonical NodePath with exactly one `of_domain` Edge, its member locator. The Domain Node holds the name, as `Named.name` and as the deprecated `Domain.name`, and, as `iconSmall`, `iconMedium` or `iconLarge`, the drawing of each size its icon declares, and one `entrypoint` Edge joins it to the View it declares, none without one. A Core Edge endpoint that is no Core Node is a path into the projected declarations.',
|
|
176
176
|
laws: [
|
|
177
177
|
'KS-DECLARATION-LOCATORS',
|
|
178
178
|
'KS-PROJECTION',
|
|
@@ -188,8 +188,8 @@ export declare const INSTALL: Readonly<{
|
|
|
188
188
|
readonly refusal: {
|
|
189
189
|
readonly code: 'SCHEMA_ARTIFACT_INVALID';
|
|
190
190
|
};
|
|
191
|
-
readonly statement: 'What a source answers stays within the limits of the protocol.';
|
|
192
|
-
readonly laws: readonly ["SB-LIMITS", "SB-RELEASE-FIRST", "SB-PUBLICATION-VERSION"];
|
|
191
|
+
readonly statement: 'What a source answers stays within the limits of the protocol: an answer over its bound, or a Bundle declared over it, is refused at once, and retrying it does not help.';
|
|
192
|
+
readonly laws: readonly ["SB-LIMITS", "SB-OVER-BOUND-REFUSED", "SB-RELEASE-FIRST", "SB-PUBLICATION-VERSION", "INSTALLATION-OVER-BOUND-SOURCE"];
|
|
193
193
|
};
|
|
194
194
|
readonly SOURCE_RELEASE_DRIFT: {
|
|
195
195
|
readonly phase: 'install';
|
|
@@ -154,8 +154,14 @@ export const INSTALL = deepFreeze({
|
|
|
154
154
|
subjects: ['install.source'],
|
|
155
155
|
does: 'refuse',
|
|
156
156
|
refusal: ARTIFACT,
|
|
157
|
-
statement: 'What a source answers stays within the limits of the protocol.',
|
|
158
|
-
laws: [
|
|
157
|
+
statement: 'What a source answers stays within the limits of the protocol: an answer over its bound, or a Bundle declared over it, is refused at once, and retrying it does not help.',
|
|
158
|
+
laws: [
|
|
159
|
+
'SB-LIMITS',
|
|
160
|
+
'SB-OVER-BOUND-REFUSED',
|
|
161
|
+
'SB-RELEASE-FIRST',
|
|
162
|
+
'SB-PUBLICATION-VERSION',
|
|
163
|
+
'INSTALLATION-OVER-BOUND-SOURCE',
|
|
164
|
+
],
|
|
159
165
|
},
|
|
160
166
|
SOURCE_RELEASE_DRIFT: {
|
|
161
167
|
phase: 'install',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { compareDefinitionRefs, definitionRefIndex } from '../../addressing/ordering.js';
|
|
2
2
|
import { isBinaryInput } from '../../language/callable/model/callable.js';
|
|
3
|
+
import { contractEndpoints } from '../../language/class/inheritance.js';
|
|
3
4
|
import { checkBindings } from '../../language/policy/model/policy.js';
|
|
4
5
|
import { CLASS_OPERATIONS, isClassRuleChecks, PolicyComposition, policyVariableClass, } from '../../language/policy/model/policy.js';
|
|
5
6
|
import { isValueObject as isJsonObject } from '../../language/value/model/object.js';
|
|
@@ -68,11 +69,8 @@ export function collectClassPolicyRefs(declaration, add) {
|
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
export function collectEndpointRefs(declaration, add) {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
: declaration.endpoints;
|
|
74
|
-
endpoints[0].accepts.forEach((ref) => add(ref, 'endpoint'));
|
|
75
|
-
endpoints[1].accepts.forEach((ref) => add(ref, 'endpoint'));
|
|
72
|
+
for (const { endpoint } of contractEndpoints(declaration))
|
|
73
|
+
endpoint.accepts.forEach((ref) => add(ref, 'endpoint'));
|
|
76
74
|
}
|
|
77
75
|
export function collectCallableRefs(declaration, add) {
|
|
78
76
|
collectCallableContractRefs(declaration, add);
|
package/dist/v1/schema/rule.js
CHANGED
|
@@ -256,10 +256,11 @@ const DECLARED = {
|
|
|
256
256
|
PL_BUDGET: {
|
|
257
257
|
stage: 'rule',
|
|
258
258
|
positions: ['/policies/{policy}', ...CHECKS],
|
|
259
|
-
statement: `A Policy declares at most ${policy.inputs} Node inputs and stays within its budgets once expanded: pattern depth ${policy.patternDepth}, ${policy.normalizedBranches} normalized branches, ${policy.edgePredicates} Edge predicates a branch and ${policy.referencedDomains} referenced Domains; and checks within depth ${policy.checkDepth}, ${policy.checkBranches} branches and ${policy.checkLeaves} leaves.`,
|
|
259
|
+
statement: `A Policy declares at most ${policy.inputs} Node inputs and stays within its budgets once expanded: pattern depth ${policy.patternDepth}, ${policy.existsDepth} nested exists scopes, ${policy.normalizedBranches} normalized branches, ${policy.edgePredicates} Edge predicates a branch and ${policy.referencedDomains} referenced Domains; and checks within depth ${policy.checkDepth}, ${policy.checkBranches} branches and ${policy.checkLeaves} leaves.`,
|
|
260
260
|
limits: [
|
|
261
261
|
'policy.inputs',
|
|
262
262
|
'policy.patternDepth',
|
|
263
|
+
'policy.existsDepth',
|
|
263
264
|
'policy.normalizedBranches',
|
|
264
265
|
'policy.edgePredicates',
|
|
265
266
|
'policy.referencedDomains',
|
|
@@ -2,10 +2,10 @@ import { equalDefinitionRefs } from '../../addressing/definition-ref.js';
|
|
|
2
2
|
import { Key } from '../../addressing/key.js';
|
|
3
3
|
import { definitionRefIndex } from '../../addressing/ordering.js';
|
|
4
4
|
import { isMethodExecutable } from '../../language/callable/executable.js';
|
|
5
|
-
import { classSatisfies as satisfiesClass, edgeContractRefines as refinesEdgeContract, } from '../../language/class/inheritance.js';
|
|
5
|
+
import { classSatisfies as satisfiesClass, contractEndpoints, edgeContractRefines as refinesEdgeContract, } from '../../language/class/inheritance.js';
|
|
6
6
|
import { lifetimeBreaches, lifetimeScope } from '../../language/class/lifetime.js';
|
|
7
7
|
import { keyableProperty } from '../../language/class/unique.js';
|
|
8
|
-
import {
|
|
8
|
+
import { holdsStates, validateStateTopology } from '../../language/state/topology.js';
|
|
9
9
|
import { isBlobValueSchema } from '../../language/value/model/blob.js';
|
|
10
10
|
import { classifyOrdering } from '../../language/value/ordering.js';
|
|
11
11
|
import { escapePointerToken } from '../../language/value/syntax/pointer.js';
|
|
@@ -58,24 +58,10 @@ function validateFacet(valueRegistry, declaration, pointer, diagnostics) {
|
|
|
58
58
|
diagnostics.push(diagnostic('DV_VALUE_SCHEMA', `${propertyPointer}/schema/x-astrale-value-kind`, 'Blob values are allowed only on non-automatic, non-state Node properties.'));
|
|
59
59
|
}
|
|
60
60
|
if (property.state !== undefined) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const schemaMatches = schema !== null &&
|
|
66
|
-
typeof schema === 'object' &&
|
|
67
|
-
!Array.isArray(schema) &&
|
|
68
|
-
Object.keys(schema).length === 2 &&
|
|
69
|
-
schema.type === 'string' &&
|
|
70
|
-
Array.isArray(schema.enum) &&
|
|
71
|
-
schema.enum.length === expected.length &&
|
|
72
|
-
[...schema.enum].sort().every((state, index) => state === expected[index]);
|
|
73
|
-
if (!property.required || property.auto !== undefined || !schemaMatches) {
|
|
74
|
-
diagnostics.push(diagnostic('DV_PROPERTY_STATE', `${propertyPointer}/state`, 'A State Property is required, non-automatic, and has exactly its declared states.'));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
diagnostics.push(diagnostic('DV_PROPERTY_STATE', `${propertyPointer}/state`, error instanceof Error ? error.message : 'Invalid State topology.'));
|
|
61
|
+
const result = validateStateTopology(property.state);
|
|
62
|
+
const breach = result.ok ? stateContractBreach(property, result.topology) : result.message;
|
|
63
|
+
if (breach !== undefined) {
|
|
64
|
+
diagnostics.push(diagnostic('DV_PROPERTY_STATE', `${propertyPointer}/state`, breach));
|
|
79
65
|
}
|
|
80
66
|
}
|
|
81
67
|
if (property.immutable !== undefined) {
|
|
@@ -129,26 +115,27 @@ function validateParents(environment, owner, ownerKind, parents, diagnostics) {
|
|
|
129
115
|
}
|
|
130
116
|
}
|
|
131
117
|
}
|
|
118
|
+
/** Why an authored State Property cannot hold the States of `topology`, if it cannot. */
|
|
119
|
+
function stateContractBreach(property, topology) {
|
|
120
|
+
try {
|
|
121
|
+
if (holdsStates(property, property.schema, topology, 'any'))
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
// Sorting the enum as strings throws for a member with its own `toString`: reported as before.
|
|
126
|
+
if (!(error instanceof TypeError))
|
|
127
|
+
throw error;
|
|
128
|
+
return error.message;
|
|
129
|
+
}
|
|
130
|
+
return 'A State Property is required, non-automatic, and has exactly its declared states.';
|
|
131
|
+
}
|
|
132
132
|
function validateEdgeContract(environment, owner, declaration, pointer, diagnostics) {
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
: declaration.endpoints;
|
|
137
|
-
const keys = directed ? ['source', 'target'] : ['0', '1'];
|
|
138
|
-
if (endpoints[0].role === endpoints[1].role) {
|
|
139
|
-
diagnostics.push(diagnostic('DV_EDGE_ROLE', `${pointer}/endpoints/${keys[1]}/role`, `${formatDefinitionRef(owner)} has equal endpoint roles.`));
|
|
133
|
+
const [first, second] = contractEndpoints(declaration);
|
|
134
|
+
if (first.endpoint.role === second.endpoint.role) {
|
|
135
|
+
diagnostics.push(diagnostic('DV_EDGE_ROLE', `${pointer}/endpoints/${second.key}/role`, `${formatDefinitionRef(owner)} has equal endpoint roles.`));
|
|
140
136
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
['outgoing', declaration.endpoints.source.outgoing],
|
|
144
|
-
['incoming', declaration.endpoints.target.incoming],
|
|
145
|
-
]
|
|
146
|
-
: [
|
|
147
|
-
['incident', declaration.endpoints[0].incident],
|
|
148
|
-
['incident', declaration.endpoints[1].incident],
|
|
149
|
-
];
|
|
150
|
-
validateEndpoint(environment, owner, endpoints[0], counts[0], directed ? 'source' : 'first endpoint', `${pointer}/endpoints/${keys[0]}`, diagnostics);
|
|
151
|
-
validateEndpoint(environment, owner, endpoints[1], counts[1], directed ? 'target' : 'second endpoint', `${pointer}/endpoints/${keys[1]}`, diagnostics);
|
|
137
|
+
validateEndpoint(environment, owner, first, pointer, diagnostics);
|
|
138
|
+
validateEndpoint(environment, owner, second, pointer, diagnostics);
|
|
152
139
|
}
|
|
153
140
|
/**
|
|
154
141
|
* Each Property a key tuple names is one of the Class's own or inherited Properties, and keyable:
|
|
@@ -186,13 +173,22 @@ function validateUniqueProperties(registryOf, analysis, owner, declaration, poin
|
|
|
186
173
|
check(field.property, `${pointer}/unique/${t}/${f}/property`);
|
|
187
174
|
}));
|
|
188
175
|
}
|
|
176
|
+
/** How a refusal names an endpoint by its key: by its direction, or by its position. */
|
|
177
|
+
const sides = {
|
|
178
|
+
source: 'source',
|
|
179
|
+
target: 'target',
|
|
180
|
+
0: 'first endpoint',
|
|
181
|
+
1: 'second endpoint',
|
|
182
|
+
};
|
|
189
183
|
// The structure refuses a repeated accepted Class before semantics: `accepts` is a set.
|
|
190
|
-
function validateEndpoint(environment, owner, endpoint,
|
|
184
|
+
function validateEndpoint(environment, owner, { key, endpoint, countKey, count }, classPointer, diagnostics) {
|
|
185
|
+
const pointer = `${classPointer}/endpoints/${key}`;
|
|
186
|
+
const side = sides[key];
|
|
191
187
|
// An Edge Class binds only the Nodes of its Domain and its dependents: it cannot oblige the
|
|
192
188
|
// Nodes of a Class another Domain owns to carry its Edges.
|
|
193
189
|
const foreign = endpoint.accepts.find((ref) => ref.origin !== owner.origin);
|
|
194
190
|
if (foreign !== undefined && (count === '1' || count === '1..*')) {
|
|
195
|
-
diagnostics.push(diagnostic('DV_EDGE_FOREIGN_MINIMUM', `${pointer}/${
|
|
191
|
+
diagnostics.push(diagnostic('DV_EDGE_FOREIGN_MINIMUM', `${pointer}/${countKey}`, `${formatDefinitionRef(owner)} ${side} accepts ${formatDefinitionRef(foreign)} of another Domain and cannot require ${count} Edges.`));
|
|
196
192
|
}
|
|
197
193
|
for (const [index, ref] of endpoint.accepts.entries()) {
|
|
198
194
|
const resolved = environment.resolve(ref);
|
|
@@ -208,12 +204,8 @@ function validateEndpoint(environment, owner, endpoint, [countField, count], sid
|
|
|
208
204
|
* declares nothing is never refused here: a stored Registry decoded again keeps it.
|
|
209
205
|
*/
|
|
210
206
|
function validateEdgeLifetimes(scope, owner, declaration, pointer, diagnostics) {
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
: ['first endpoint', 'second endpoint'];
|
|
214
|
-
const keys = declaration.orientation === 'directed' ? ['source', 'target'] : ['0', '1'];
|
|
215
|
-
for (const { index, reason } of lifetimeBreaches(declaration, scope)) {
|
|
216
|
-
diagnostics.push(diagnostic('DV_EDGE_LIFETIME', `${pointer}/endpoints/${keys[index]}/onDelete`, `${formatDefinitionRef(owner)} ${sides[index]} ${reason}`));
|
|
207
|
+
for (const { key, reason } of lifetimeBreaches(declaration, scope)) {
|
|
208
|
+
diagnostics.push(diagnostic('DV_EDGE_LIFETIME', `${pointer}/endpoints/${key}/onDelete`, `${formatDefinitionRef(owner)} ${sides[key]} ${reason}`));
|
|
217
209
|
}
|
|
218
210
|
}
|
|
219
211
|
/**
|
|
@@ -70,6 +70,7 @@ export function validateCheckBudget(context, pointer, measure) {
|
|
|
70
70
|
const REFUSAL = {
|
|
71
71
|
inputs: (measure) => `Policy declares ${measure.inputs} Node inputs. The maximum is ${limits.policy.inputs}.`,
|
|
72
72
|
patternDepth: (measure) => `Expanded Pattern depth ${measure.patternDepth} exceeds ${limits.policy.patternDepth}.`,
|
|
73
|
+
existsDepth: (measure) => `Pattern nests ${measure.existsDepth} exists scopes; the maximum is ${limits.policy.existsDepth}.`,
|
|
73
74
|
normalizedBranches: () => `Expanded Pattern has more than ${limits.policy.normalizedBranches} normalized branches.`,
|
|
74
75
|
edgePredicates: (measure) => `A normalized branch contains ${measure.edgePredicates} graph predicates; the maximum is ${limits.policy.edgePredicates}.`,
|
|
75
76
|
referencedDomains: (measure) => `Expanded Pattern references ${measure.referencedDomains} Domains; the maximum is ${limits.policy.referencedDomains}.`,
|
|
@@ -1,34 +1,21 @@
|
|
|
1
|
-
import { targetMode } from '../../../language/policy/analysis/branches.js';
|
|
2
1
|
import { escapePointerToken } from '../../../language/value/syntax/pointer.js';
|
|
3
2
|
/** Type every expanded branch of each named Policy at its own default use. */
|
|
4
3
|
export function validatePolicyTyping(context, typing) {
|
|
5
4
|
for (const name of Object.keys(context.environment.candidate.policies)) {
|
|
6
|
-
const branches = typing.expandedBranches(name
|
|
5
|
+
const branches = typing.expandedBranches(name);
|
|
7
6
|
if (branches === undefined)
|
|
8
7
|
continue;
|
|
9
8
|
if (!typing.validDeclaration(name)) {
|
|
10
9
|
context.add('PL_USE', '/policies/' + escapePointerToken(name), 'Policy branches and operands must agree with the declared input names and Classes.');
|
|
11
10
|
continue;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
if (mode === undefined) {
|
|
18
|
-
if (!('match' in context.environment.candidate.policies[name].expression)) {
|
|
19
|
-
context.add('PL_TARGET', `/policies/${escapePointerToken(name)}`, `Expanded normalized branch ${index} must use object or at least one of source and target, without mixing target modes.`);
|
|
20
|
-
}
|
|
21
|
-
continue;
|
|
12
|
+
const path = `/policies/${escapePointerToken(name)}`;
|
|
13
|
+
for (const { index, kind } of typing.defaultUseFaults(branches)) {
|
|
14
|
+
if (kind === 'typing') {
|
|
15
|
+
context.add('PL_TYPING', path, `Expanded normalized branch ${index} has contradictory endpoint or repeat contracts.`);
|
|
22
16
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
: {
|
|
26
|
-
kind: 'edge',
|
|
27
|
-
source: { kind: 'default' },
|
|
28
|
-
target: { kind: 'default' },
|
|
29
|
-
};
|
|
30
|
-
if (!typing.branchIsTyped(branch, use)) {
|
|
31
|
-
context.add('PL_TYPING', `/policies/${escapePointerToken(name)}`, `Expanded normalized branch ${index} has contradictory endpoint or repeat contracts.`);
|
|
17
|
+
else if (!('match' in context.environment.candidate.policies[name].expression)) {
|
|
18
|
+
context.add('PL_TARGET', path, `Expanded normalized branch ${index} must use object or at least one of source and target, without mixing target modes.`);
|
|
32
19
|
}
|
|
33
20
|
}
|
|
34
21
|
}
|
|
@@ -4,7 +4,7 @@ import { isBinaryInput } from '../../../language/callable/model/callable.js';
|
|
|
4
4
|
import { neverAdmittedClasses, } from '../../../language/policy/analysis/checks.js';
|
|
5
5
|
import { CLASS_OPERATIONS, checksNameTheCaller, isClassRuleChecks, PolicyComposition, } from '../../../language/policy/model/policy.js';
|
|
6
6
|
import { normalizePolicyChecks } from '../../../language/policy/normalization/normalize.js';
|
|
7
|
-
import {
|
|
7
|
+
import { singleNodePathFieldAccepts } from '../../../language/value/syntax/node-path/schema.js';
|
|
8
8
|
import { escapePointerToken } from '../../../language/value/syntax/pointer.js';
|
|
9
9
|
import { declaredContracts } from '../callable.js';
|
|
10
10
|
import { referenceContracts } from './objects.js';
|
|
@@ -172,30 +172,13 @@ function selfContracts(validation, context, pointer) {
|
|
|
172
172
|
return [contractOfNodeDefinition(context.receiver)];
|
|
173
173
|
}
|
|
174
174
|
function inputContracts(validation, context, field, pointer) {
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const required = input?.required;
|
|
179
|
-
const rootValid = input?.type === 'object' &&
|
|
180
|
-
properties !== undefined &&
|
|
181
|
-
Array.isArray(required) &&
|
|
182
|
-
required.includes(field) &&
|
|
183
|
-
input.additionalProperties === false &&
|
|
184
|
-
!hasCombinator(input);
|
|
185
|
-
const annotation = asRecord(fieldSchema?.['x-astrale-path']);
|
|
186
|
-
const fieldValid = rootValid &&
|
|
187
|
-
fieldSchema?.$ref === GRAPH_NODE_PATH_SCHEMA_ID &&
|
|
188
|
-
!hasCombinator(fieldSchema) &&
|
|
189
|
-
annotation?.target === 'node' &&
|
|
190
|
-
annotation.cardinality === 'one' &&
|
|
191
|
-
Array.isArray(annotation.accepts) &&
|
|
192
|
-
annotation.accepts.length > 0;
|
|
193
|
-
if (!fieldValid) {
|
|
194
|
-
validation.add('PL_USE', pointer, `input.${field} must be one direct required single-Node x-astrale-path field of a closed object input.`);
|
|
175
|
+
const accepts = singleNodePathFieldAccepts(context.input, field);
|
|
176
|
+
if (accepts === undefined) {
|
|
177
|
+
validation.add('PL_USE', pointer, `input.${field} must be one direct required single-Node x-astrale-path field of a closed object input, neither carrying a combinator.`);
|
|
195
178
|
return undefined;
|
|
196
179
|
}
|
|
197
180
|
const contracts = [];
|
|
198
|
-
for (const ref of
|
|
181
|
+
for (const ref of accepts) {
|
|
199
182
|
if (!isDefinitionRef(ref)) {
|
|
200
183
|
validation.add('PL_USE', pointer, `input.${field} has a non-Node acceptance ref.`);
|
|
201
184
|
return undefined;
|
|
@@ -214,9 +197,6 @@ function asRecord(value) {
|
|
|
214
197
|
? value
|
|
215
198
|
: undefined;
|
|
216
199
|
}
|
|
217
|
-
function hasCombinator(value) {
|
|
218
|
-
return ['allOf', 'anyOf', 'oneOf', 'not', 'if', 'then', 'else'].some((key) => Object.hasOwn(value, key));
|
|
219
|
-
}
|
|
220
200
|
function isDefinitionRef(value) {
|
|
221
201
|
const record = asRecord(value);
|
|
222
202
|
return (record !== undefined &&
|