@astrale-os/kernel-dsl 1.0.0-beta.2 → 1.0.0-beta.20
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 +3 -3
- package/dist/v1/addressing/definition-ref.js +21 -37
- package/dist/v1/addressing/domain-dependency.d.ts +0 -6
- package/dist/v1/addressing/domain-dependency.js +1 -6
- package/dist/v1/addressing/key.d.ts +4 -1
- package/dist/v1/addressing/key.js +23 -3
- package/dist/v1/addressing/ordering.d.ts +2 -0
- package/dist/v1/addressing/ordering.js +4 -0
- package/dist/v1/addressing/patterns.d.ts +1 -1
- package/dist/v1/addressing/patterns.js +2 -6
- package/dist/v1/builder/callable/authoring.d.ts +11 -5
- package/dist/v1/builder/callable/authoring.js +2 -0
- package/dist/v1/builder/class/authoring.d.ts +94 -224
- package/dist/v1/builder/class/authoring.js +31 -33
- package/dist/v1/builder/class/handle.d.ts +27 -0
- package/dist/v1/builder/class/handle.js +1 -0
- package/dist/v1/builder/class/input.d.ts +159 -0
- package/dist/v1/builder/class/projection.d.ts +129 -0
- package/dist/v1/builder/class/projection.js +1 -0
- package/dist/v1/builder/class/property.d.ts +3 -9
- package/dist/v1/builder/class/property.js +1 -0
- package/dist/v1/builder/core/authoring.d.ts +1 -1
- package/dist/v1/builder/index.d.ts +5 -2
- package/dist/v1/builder/lowering/callable.js +1 -0
- package/dist/v1/builder/lowering/class.d.ts +9 -1
- package/dist/v1/builder/lowering/class.js +62 -17
- package/dist/v1/builder/lowering/policy.js +2 -0
- package/dist/v1/builder/lowering/property-keys.d.ts +27 -0
- package/dist/v1/builder/lowering/property-keys.js +108 -0
- package/dist/v1/builder/lowering/schema/compile.js +11 -6
- package/dist/v1/builder/lowering/schema/context.d.ts +9 -1
- package/dist/v1/builder/lowering/schema/context.js +36 -4
- package/dist/v1/builder/lowering/schema/lifetime.d.ts +11 -0
- package/dist/v1/builder/lowering/schema/lifetime.js +55 -0
- package/dist/v1/builder/lowering/value/path.d.ts +1 -1
- package/dist/v1/builder/lowering/value/path.js +2 -4
- package/dist/v1/builder/lowering/value/zod.js +1 -3
- package/dist/v1/builder/policy/authoring.d.ts +85 -5
- package/dist/v1/builder/policy/authoring.js +107 -68
- package/dist/v1/builder/schema/define.d.ts +0 -1
- package/dist/v1/builder/schema/diagnostic.d.ts +3 -2
- package/dist/v1/builder/schema/diagnostic.js +5 -10
- package/dist/v1/builder/schema/input.d.ts +1 -1
- package/dist/v1/builder/schema/projection/callable.d.ts +7 -5
- package/dist/v1/builder/schema/projection/class.d.ts +118 -15
- package/dist/v1/builder/schema/projection/core-input.d.ts +2 -1
- package/dist/v1/builder/schema/projection/identity.d.ts +2 -1
- package/dist/v1/builder/schema/projection/model.d.ts +4 -2
- package/dist/v1/builder/schema/projection/property.d.ts +1 -1
- package/dist/v1/builder/schema/projection/resolved-class.d.ts +2 -1
- package/dist/v1/builder/schema/projection.d.ts +1 -1
- package/dist/v1/builder/value/full-match.d.ts +0 -1
- package/dist/v1/builder/value/full-match.js +0 -1
- package/dist/v1/builder/value/path-metadata.d.ts +1 -1
- package/dist/v1/builder/value/path.d.ts +1 -1
- package/dist/v1/bundle/codec.js +11 -13
- package/dist/v1/bundle/diagnostic.d.ts +2 -0
- package/dist/v1/bundle/diagnostic.js +9 -7
- package/dist/v1/bundle/model.js +1 -1
- package/dist/v1/bundle/structure.js +4 -6
- package/dist/v1/compiled/admission/accept.js +4 -10
- package/dist/v1/compiled/admission/closure.js +2 -2
- package/dist/v1/compiled/admission/diagnostic.d.ts +1 -1
- package/dist/v1/compiled/admission/diagnostic.js +1 -3
- package/dist/v1/compiled/admission/revision.d.ts +9 -1
- package/dist/v1/compiled/admission/revision.js +6 -3
- package/dist/v1/compiled/admission/semantics/class.d.ts +4 -1
- package/dist/v1/compiled/admission/semantics/class.js +37 -12
- package/dist/v1/compiled/admission/semantics/core.d.ts +1 -24
- package/dist/v1/compiled/admission/semantics/core.js +56 -24
- package/dist/v1/compiled/admission/semantics/edge.d.ts +2 -4
- package/dist/v1/compiled/admission/semantics/edge.js +6 -65
- package/dist/v1/compiled/admission/semantics/policy/callable.js +0 -2
- package/dist/v1/compiled/admission/semantics/policy/contracts.d.ts +5 -20
- package/dist/v1/compiled/admission/semantics/policy/contracts.js +8 -21
- package/dist/v1/compiled/admission/semantics/policy/parity.js +40 -43
- package/dist/v1/compiled/admission/semantics/policy/pattern.d.ts +4 -1
- package/dist/v1/compiled/admission/semantics/policy/pattern.js +4 -16
- package/dist/v1/compiled/admission/semantics/policy/typing.d.ts +2 -24
- package/dist/v1/compiled/admission/semantics/policy/typing.js +19 -201
- package/dist/v1/compiled/admission/wire/callable.js +11 -1
- package/dist/v1/compiled/admission/wire/class.js +73 -21
- package/dist/v1/compiled/admission/wire/policy.d.ts +4 -3
- package/dist/v1/compiled/admission/wire/policy.js +8 -7
- package/dist/v1/compiled/compiler/compile.js +8 -8
- package/dist/v1/compiled/diagnostic.js +2 -3
- package/dist/v1/compiled/loader/load.d.ts +3 -2
- package/dist/v1/compiled/loader/load.js +11 -45
- package/dist/v1/domain/create.js +5 -6
- package/dist/v1/domain/model/domain.d.ts +2 -7
- package/dist/v1/domain/model/input.d.ts +2 -1
- package/dist/v1/domain/namespace/member-collection.js +4 -6
- package/dist/v1/domain/projection/classes.js +4 -1
- package/dist/v1/domain/validation/create.d.ts +6 -3
- package/dist/v1/domain/validation/create.js +21 -69
- package/dist/v1/index.d.ts +2 -1
- package/dist/v1/language/.spec/schemas/draft-2020-12.schema.json +462 -0
- package/dist/v1/language/.spec/schemas/value-schema.schema.json +22 -0
- package/dist/v1/language/callable/admission.d.ts +15 -0
- package/dist/v1/language/callable/admission.js +43 -0
- package/dist/v1/language/callable/model/callable.d.ts +10 -0
- package/dist/v1/language/callable/resolved.d.ts +16 -3
- package/dist/v1/language/class/inheritance.d.ts +36 -5
- package/dist/v1/language/class/inheritance.js +87 -1
- package/dist/v1/language/class/lifetime.d.ts +50 -11
- package/dist/v1/language/class/lifetime.js +89 -20
- package/dist/v1/language/class/model/class.d.ts +45 -9
- package/dist/v1/language/class/model/edge.d.ts +31 -2
- package/dist/v1/language/class/model/property.d.ts +16 -7
- package/dist/v1/language/class/property-values.js +2 -4
- package/dist/v1/language/class/unique.d.ts +143 -0
- package/dist/v1/language/class/unique.js +264 -0
- package/dist/v1/language/core/facts.d.ts +85 -0
- package/dist/v1/language/core/facts.js +116 -0
- package/dist/v1/language/definition/metadata.d.ts +5 -0
- package/dist/v1/language/definition/metadata.js +7 -0
- package/dist/v1/language/freeze.d.ts +5 -0
- package/dist/v1/{schema/canonical → language}/freeze.js +4 -0
- package/dist/v1/language/index.d.ts +7 -2
- package/dist/v1/language/index.js +5 -1
- package/dist/v1/language/limits.d.ts +64 -0
- package/dist/v1/language/limits.js +60 -0
- package/dist/v1/language/policy/analysis/branches.d.ts +8 -0
- package/dist/v1/language/policy/analysis/branches.js +2 -1
- package/dist/v1/language/policy/analysis/budgets.d.ts +45 -12
- package/dist/v1/language/policy/analysis/budgets.js +133 -19
- package/dist/v1/language/policy/analysis/checks.js +3 -2
- package/dist/v1/language/policy/analysis/typing.d.ts +51 -0
- package/dist/v1/language/policy/analysis/typing.js +455 -0
- package/dist/v1/language/policy/model/policy.d.ts +49 -9
- package/dist/v1/language/policy/model/policy.js +14 -0
- package/dist/v1/language/policy/normalization/normalize.d.ts +6 -6
- package/dist/v1/language/policy/normalization/normalize.js +22 -21
- package/dist/v1/language/validation/diagnostic.d.ts +15 -1
- package/dist/v1/language/validation/diagnostic.js +21 -0
- package/dist/v1/language/validation/rule.d.ts +45 -0
- package/dist/v1/language/validation/rule.js +109 -0
- package/dist/v1/language/value/compile/fields.js +4 -8
- package/dist/v1/language/value/evaluate/program.d.ts +2 -1
- package/dist/v1/language/value/evaluate/program.js +2 -2
- package/dist/v1/language/value/evaluate/validate.d.ts +2 -2
- package/dist/v1/language/value/evaluate/validate.js +6 -2
- package/dist/v1/language/value/evaluate/validity.optimization.d.ts +14 -0
- package/dist/v1/language/value/evaluate/validity.optimization.js +342 -0
- package/dist/v1/language/value/inclusion/arrays.d.ts +3 -0
- package/dist/v1/language/value/inclusion/arrays.js +85 -0
- package/dist/v1/language/value/inclusion/assertions.d.ts +18 -0
- package/dist/v1/language/value/inclusion/assertions.js +29 -0
- package/dist/v1/language/value/inclusion/combinators.d.ts +3 -0
- package/dist/v1/language/value/inclusion/combinators.js +67 -0
- package/dist/v1/language/value/inclusion/equivalence.d.ts +4 -0
- package/dist/v1/language/value/inclusion/equivalence.js +74 -0
- package/dist/v1/language/value/inclusion/evidence.d.ts +34 -0
- package/dist/v1/language/value/inclusion/evidence.js +138 -0
- package/dist/v1/language/value/inclusion/includes.d.ts +17 -0
- package/dist/v1/language/value/inclusion/includes.js +25 -719
- package/dist/v1/language/value/inclusion/keywords.d.ts +5 -0
- package/dist/v1/language/value/inclusion/keywords.js +31 -0
- package/dist/v1/language/value/inclusion/kinds.d.ts +17 -0
- package/dist/v1/language/value/inclusion/kinds.js +57 -0
- package/dist/v1/language/value/inclusion/location.d.ts +24 -0
- package/dist/v1/language/value/inclusion/location.js +63 -0
- package/dist/v1/language/value/inclusion/numbers.d.ts +3 -0
- package/dist/v1/language/value/inclusion/numbers.js +41 -0
- package/dist/v1/language/value/inclusion/objects.d.ts +3 -0
- package/dist/v1/language/value/inclusion/objects.js +190 -0
- package/dist/v1/language/value/inclusion/strings.d.ts +3 -0
- package/dist/v1/language/value/inclusion/strings.js +29 -0
- package/dist/v1/language/value/inclusion/types.d.ts +3 -0
- package/dist/v1/language/value/inclusion/types.js +11 -0
- package/dist/v1/language/value/ordering.d.ts +14 -0
- package/dist/v1/language/value/ordering.js +86 -9
- package/dist/v1/language/value/profile/canonicalize.js +6 -5
- package/dist/v1/language/value/profile/json.validate.d.ts +3 -1
- package/dist/v1/language/value/profile/json.validate.js +3 -2
- package/dist/v1/language/value/profile/meta-schema.compiled.js +4 -1
- package/dist/v1/language/value/profile/rules.js +17 -43
- package/dist/v1/language/value/profile/validate.js +1 -10
- package/dist/v1/language/value/profile/vocabulary.d.ts +35 -2
- package/dist/v1/language/value/profile/vocabulary.js +52 -5
- package/dist/v1/language/value/reference/closure.js +3 -4
- package/dist/v1/language/value/reference/recursion.js +2 -22
- package/dist/v1/language/value/reference/registry.index.d.ts +2 -0
- package/dist/v1/language/value/reference/registry.index.js +33 -16
- package/dist/v1/language/value/regexp/ast.js +6 -7
- package/dist/v1/language/value/regexp/compile.d.ts +5 -11
- package/dist/v1/language/value/regexp/compile.js +14 -12
- package/dist/v1/language/value/regexp/syntax.js +3 -2
- package/dist/v1/language/value/syntax/keywords.d.ts +3 -3
- package/dist/v1/language/value/syntax/keywords.js +4 -20
- package/dist/v1/language/value/syntax/node-path/validate.js +2 -3
- package/dist/v1/language/value/syntax/pointer.d.ts +2 -0
- package/dist/v1/language/value/syntax/pointer.js +5 -2
- package/dist/v1/language/value/syntax/walk.d.ts +2 -0
- package/dist/v1/language/value/syntax/walk.js +19 -20
- package/dist/v1/schema/.spec/schemas/domain-schema.schema.json +2519 -0
- package/dist/v1/schema/admission/accept.js +3 -14
- package/dist/v1/schema/admission/callable.d.ts +21 -0
- package/dist/v1/schema/admission/callable.js +96 -0
- package/dist/v1/schema/analysis/class.js +33 -15
- package/dist/v1/schema/canonical/revision.js +4 -4
- package/dist/v1/schema/compatibility/api.d.ts +2 -1
- package/dist/v1/schema/compatibility/api.js +1 -0
- package/dist/v1/schema/compatibility/comparators/callables.js +1 -1
- package/dist/v1/schema/compatibility/comparators/classes.d.ts +9 -4
- package/dist/v1/schema/compatibility/comparators/classes.js +29 -8
- package/dist/v1/schema/compatibility/comparators/index.d.ts +1 -1
- package/dist/v1/schema/compatibility/comparators/members.js +1 -1
- package/dist/v1/schema/compatibility/comparators/values.js +2 -2
- package/dist/v1/schema/compatibility/coordinate.js +3 -3
- package/dist/v1/schema/compatibility/diff.js +2 -4
- package/dist/v1/schema/compatibility/extension.d.ts +11 -0
- package/dist/v1/schema/compatibility/extension.js +22 -0
- package/dist/v1/schema/compatibility/fields.d.ts +20 -4
- package/dist/v1/schema/compatibility/fields.js +13 -3
- package/dist/v1/schema/compatibility/meaning/footprint.js +16 -50
- package/dist/v1/schema/compatibility/model.d.ts +17 -5
- package/dist/v1/schema/compatibility/report.js +1 -1
- package/dist/v1/schema/compatibility/scope.d.ts +2 -0
- package/dist/v1/schema/compatibility/scope.js +4 -1
- package/dist/v1/schema/compatibility/structure/index.js +6 -4
- package/dist/v1/schema/compatibility/structure/requirements.js +57 -58
- package/dist/v1/schema/compatibility/versioning/index.js +1 -1
- package/dist/v1/schema/compatibility/versioning/surface.d.ts +1 -1
- package/dist/v1/schema/compatibility/versioning/surface.js +30 -2
- package/dist/v1/schema/compatibility/walk.d.ts +17 -0
- package/dist/v1/schema/compatibility/walk.js +41 -0
- package/dist/v1/schema/diagnostic.d.ts +17 -3
- package/dist/v1/schema/diagnostic.js +14 -11
- package/dist/v1/schema/index.d.ts +10 -1
- package/dist/v1/schema/index.js +4 -0
- package/dist/v1/schema/model/schema.d.ts +20 -1
- package/dist/v1/schema/model/schema.js +1 -1
- package/dist/v1/schema/normalization/domain.d.ts +2 -0
- package/dist/v1/schema/normalization/domain.js +29 -9
- package/dist/v1/schema/resolution/closure.js +2 -1
- package/dist/v1/schema/resolution/context.js +13 -13
- package/dist/v1/schema/resolution/domain.d.ts +5 -0
- package/dist/v1/schema/resolution/domain.js +2 -2
- package/dist/v1/schema/resolution/origins.js +3 -2
- package/dist/v1/schema/rule.d.ts +26 -0
- package/dist/v1/schema/rule.js +440 -0
- package/dist/v1/schema/validation/callable.d.ts +35 -2
- package/dist/v1/schema/validation/callable.js +65 -9
- package/dist/v1/schema/validation/class.d.ts +6 -2
- package/dist/v1/schema/validation/class.js +127 -104
- package/dist/v1/schema/validation/core.js +90 -168
- package/dist/v1/schema/validation/domain.js +4 -13
- package/dist/v1/schema/validation/domain.json-schema.d.ts +15 -0
- package/dist/v1/schema/validation/domain.json-schema.js +197 -0
- package/dist/v1/schema/validation/domain.route.d.ts +6 -1
- package/dist/v1/schema/validation/domain.route.js +18 -0
- package/dist/v1/schema/validation/domain.structure.d.ts +7780 -0
- package/dist/v1/schema/validation/domain.structure.js +398 -147
- package/dist/v1/schema/validation/json.json-schema.d.ts +40 -0
- package/dist/v1/schema/validation/json.json-schema.js +46 -0
- package/dist/v1/schema/validation/policy/budgets.d.ts +33 -2
- package/dist/v1/schema/validation/policy/budgets.js +87 -121
- package/dist/v1/schema/validation/policy/context.d.ts +6 -5
- package/dist/v1/schema/validation/policy/context.js +7 -10
- package/dist/v1/schema/validation/policy/objects.d.ts +1 -1
- package/dist/v1/schema/validation/policy/objects.js +6 -14
- package/dist/v1/schema/validation/policy/references.js +11 -27
- package/dist/v1/schema/validation/policy/typing.d.ts +3 -18
- package/dist/v1/schema/validation/policy/typing.js +22 -356
- package/dist/v1/schema/validation/policy/uses.d.ts +40 -3
- package/dist/v1/schema/validation/policy/uses.js +66 -89
- package/dist/v1/schema/validation/policy/validate.js +5 -5
- package/dist/v1/schema/validation/value-api.d.ts +22 -0
- package/dist/v1/schema/validation/value-api.js +34 -1
- package/dist/v1/schema/validation/value.d.ts +3 -0
- package/dist/v1/schema/validation/value.js +9 -17
- package/dist/v1/schema/validation/value.json-schema.d.ts +49 -0
- package/dist/v1/schema/validation/value.json-schema.js +137 -0
- package/dist/v1/schema/validation/view.js +4 -8
- package/dist/value/canonical.d.ts +6 -0
- package/dist/value/canonical.js +36 -0
- package/dist/value/decode.d.ts +7 -0
- package/dist/value/decode.js +159 -9
- package/dist/value/index.d.ts +1 -1
- package/dist/value/json.d.ts +2 -2
- package/dist/value/json.js +2 -2
- package/dist/value/types.d.ts +6 -0
- package/dist/value/unicode.d.ts +2 -1
- package/dist/value/unicode.js +2 -0
- package/package.json +8 -1
- package/dist/v1/builder/lowering/core-properties.d.ts +0 -10
- package/dist/v1/builder/lowering/core-properties.js +0 -76
- package/dist/v1/compiled/admission/semantics/cardinality.d.ts +0 -5
- package/dist/v1/compiled/admission/semantics/cardinality.js +0 -113
- package/dist/v1/compiled/admission/semantics/policy/equality.d.ts +0 -8
- package/dist/v1/compiled/admission/semantics/policy/equality.js +0 -27
- package/dist/v1/compiled/admission/semantics/policy/measure.d.ts +0 -9
- package/dist/v1/compiled/admission/semantics/policy/measure.js +0 -81
- package/dist/v1/compiled/admission/semantics/policy/variants.d.ts +0 -10
- package/dist/v1/compiled/admission/semantics/policy/variants.js +0 -65
- package/dist/v1/language/class/index.d.ts +0 -8
- package/dist/v1/language/class/index.js +0 -1
- package/dist/v1/language/core/index.d.ts +0 -2
- package/dist/v1/language/value/index.d.ts +0 -11
- package/dist/v1/language/value/index.js +0 -8
- package/dist/v1/schema/canonical/domain.d.ts +0 -3
- package/dist/v1/schema/canonical/domain.digest.d.ts +0 -3
- package/dist/v1/schema/canonical/domain.digest.js +0 -5
- package/dist/v1/schema/canonical/domain.js +0 -5
- package/dist/v1/schema/canonical/freeze.d.ts +0 -1
- /package/dist/v1/{language/core/index.js → builder/class/input.js} +0 -0
|
@@ -1,366 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
#expansions = new Map();
|
|
15
|
-
constructor(context) {
|
|
16
|
-
this.context = context;
|
|
17
|
-
}
|
|
18
|
-
validatePolicies() {
|
|
19
|
-
for (const name of Object.keys(this.context.environment.candidate.policies)) {
|
|
20
|
-
const branches = this.#expandedBranches(name, new Set(), `$${name}`);
|
|
21
|
-
if (branches === undefined)
|
|
22
|
-
continue;
|
|
23
|
-
for (const [index, branch] of branches.entries()) {
|
|
24
|
-
const mode = targetMode(branch);
|
|
25
|
-
if (mode === undefined) {
|
|
26
|
-
if (!('match' in this.context.environment.candidate.policies[name].expression)) {
|
|
27
|
-
this.context.add('PL_TARGET', `/policies/${escapePointer(name)}`, `Expanded normalized branch ${index} must use object or at least one of source and target, without mixing target modes.`);
|
|
28
|
-
}
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
const use = mode === 'object'
|
|
32
|
-
? { kind: 'object', object: { kind: 'default' } }
|
|
33
|
-
: {
|
|
34
|
-
kind: 'edge',
|
|
35
|
-
source: { kind: 'default' },
|
|
36
|
-
target: { kind: 'default' },
|
|
37
|
-
};
|
|
38
|
-
if (!this.#branchIsTyped(branch, use)) {
|
|
39
|
-
this.context.add('PL_TYPING', `/policies/${escapePointer(name)}`, `Expanded normalized branch ${index} has contradictory endpoint or repeat contracts.`);
|
|
1
|
+
import { targetMode } from '../../../language/policy/analysis/branches.js';
|
|
2
|
+
import { escapePointerToken } from '../../../language/value/syntax/pointer.js';
|
|
3
|
+
/** Type every expanded branch of each named Policy at its own default use. */
|
|
4
|
+
export function validatePolicyTyping(context, typing) {
|
|
5
|
+
for (const name of Object.keys(context.environment.candidate.policies)) {
|
|
6
|
+
const branches = typing.expandedBranches(name, `$${name}`);
|
|
7
|
+
if (branches === undefined)
|
|
8
|
+
continue;
|
|
9
|
+
for (const [index, branch] of branches.entries()) {
|
|
10
|
+
const mode = targetMode(branch);
|
|
11
|
+
if (mode === undefined) {
|
|
12
|
+
if (!('match' in context.environment.candidate.policies[name].expression)) {
|
|
13
|
+
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.`);
|
|
40
14
|
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
policyAccepts(name, object) {
|
|
45
|
-
return this.policyBranchTyping(name, object)?.every(Boolean) ?? false;
|
|
46
|
-
}
|
|
47
|
-
/** Whether each normalized branch of the Policy is typed for an object of this contract. */
|
|
48
|
-
policyBranchTyping(name, object) {
|
|
49
|
-
const branches = this.#expandedBranches(name, new Set(), `$use:${name}`);
|
|
50
|
-
const use = { kind: 'object', object };
|
|
51
|
-
return branches?.map((branch) => this.#branchIsTyped(branch, use));
|
|
52
|
-
}
|
|
53
|
-
policyAcceptsEdge(name, source, target) {
|
|
54
|
-
const branches = this.#expandedBranches(name, new Set(), `$edge-use:${name}`);
|
|
55
|
-
const use = { kind: 'edge', source, target };
|
|
56
|
-
return branches !== undefined && branches.every((branch) => this.#branchIsTyped(branch, use));
|
|
57
|
-
}
|
|
58
|
-
concreteEndpointClasses(accepts) {
|
|
59
|
-
return this.context.concreteNodeClasses.filter((candidate) => this.#classSatisfiesEndpoint(candidate, accepts));
|
|
60
|
-
}
|
|
61
|
-
endpointsOverlap(left, right) {
|
|
62
|
-
const seed = [{ kind: 'open', requirements: [] }];
|
|
63
|
-
const afterLeft = this.#applyEndpoint(seed, left);
|
|
64
|
-
return this.#applyEndpoint(afterLeft, right).length > 0;
|
|
65
|
-
}
|
|
66
|
-
#expandedBranches(name, visiting, namespace) {
|
|
67
|
-
if (visiting.has(name))
|
|
68
|
-
return undefined;
|
|
69
|
-
const cached = this.#expansions.get(name);
|
|
70
|
-
if (cached !== undefined || this.#expansions.has(name))
|
|
71
|
-
return cached;
|
|
72
|
-
const expanded = this.#expandDeclaration(name, visiting, namespace);
|
|
73
|
-
this.#expansions.set(name, expanded);
|
|
74
|
-
return expanded;
|
|
75
|
-
}
|
|
76
|
-
#expandDeclaration(name, visiting, namespace) {
|
|
77
|
-
const declaration = this.context.normalized.get(name);
|
|
78
|
-
if (declaration === undefined)
|
|
79
|
-
return undefined;
|
|
80
|
-
if ('match' in declaration)
|
|
81
|
-
return branchesOf(declaration.match, namespace);
|
|
82
|
-
const nested = new Set(visiting);
|
|
83
|
-
nested.add(name);
|
|
84
|
-
const refs = 'allOf' in declaration ? declaration.allOf : declaration.anyOf;
|
|
85
|
-
const children = [];
|
|
86
|
-
for (const [index, ref] of refs.entries()) {
|
|
87
|
-
if (!this.context.isLocalPolicy(ref))
|
|
88
|
-
return undefined;
|
|
89
|
-
const expanded = this.#expandedBranches(ref.name, nested, `${namespace}/${index}:${ref.name}`);
|
|
90
|
-
if (expanded === undefined)
|
|
91
|
-
return undefined;
|
|
92
|
-
children.push(expanded);
|
|
93
|
-
}
|
|
94
|
-
return 'allOf' in declaration ? branchProduct(children) : capBranches(children.flat());
|
|
95
|
-
}
|
|
96
|
-
#branchIsTyped(branch, use) {
|
|
97
|
-
if (targetMode(branch) !== use.kind)
|
|
98
|
-
return false;
|
|
99
|
-
const alternatives = edgeAlternatives(branch.edges, this);
|
|
100
|
-
return alternatives.some((variants) => this.#constraintsAreSatisfiable(branch, variants, use));
|
|
101
|
-
}
|
|
102
|
-
#constraintsAreSatisfiable(branch, variants, use) {
|
|
103
|
-
const terms = new Set(use.kind === 'object' ? ['subject', 'object'] : ['subject', 'source', 'target']);
|
|
104
|
-
for (const key of branch.variables.keys())
|
|
105
|
-
terms.add(key);
|
|
106
|
-
for (const key of branch.terms.keys())
|
|
107
|
-
terms.add(key);
|
|
108
|
-
for (const edge of branch.edges) {
|
|
109
|
-
terms.add(termKey(edge.pattern.source, edge.namespace));
|
|
110
|
-
terms.add(termKey(edge.pattern.target, edge.namespace));
|
|
111
|
-
}
|
|
112
|
-
const union = new UnionFind(terms);
|
|
113
|
-
for (const [left, right] of branch.equalities)
|
|
114
|
-
union.join(left, right);
|
|
115
|
-
for (const variant of variants) {
|
|
116
|
-
for (const [left, right] of variant.equalities)
|
|
117
|
-
union.join(left, right);
|
|
118
|
-
}
|
|
119
|
-
const constraints = new Map();
|
|
120
|
-
for (const variant of variants) {
|
|
121
|
-
for (const [term, accepts] of variant.constraints) {
|
|
122
|
-
const root = union.find(term);
|
|
123
|
-
const values = constraints.get(root) ?? [];
|
|
124
|
-
values.push(accepts);
|
|
125
|
-
constraints.set(root, values);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
const groups = new Map();
|
|
129
|
-
for (const term of terms) {
|
|
130
|
-
const root = union.find(term);
|
|
131
|
-
const members = groups.get(root) ?? [];
|
|
132
|
-
members.push(term);
|
|
133
|
-
groups.set(root, members);
|
|
134
|
-
}
|
|
135
|
-
for (const [root, members] of groups) {
|
|
136
|
-
const endpointConstraints = constraints.get(root) ?? [];
|
|
137
|
-
let candidates = [{ kind: 'open', requirements: [] }];
|
|
138
|
-
for (const member of members) {
|
|
139
|
-
candidates = this.#applyInitial(candidates, member, branch, use);
|
|
140
|
-
if (candidates.length === 0)
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
for (const endpoint of endpointConstraints) {
|
|
144
|
-
candidates = this.#applyEndpoint(candidates, endpoint);
|
|
145
|
-
if (candidates.length === 0)
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
#applyInitial(candidates, term, branch, use) {
|
|
152
|
-
if (term === 'subject')
|
|
153
|
-
return this.#applyAnyNodeClass(candidates);
|
|
154
|
-
const contract = targetContract(term, use);
|
|
155
|
-
if (contract !== undefined) {
|
|
156
|
-
if (contract.kind === 'exact')
|
|
157
|
-
return this.#applyExact(candidates, contract.ref);
|
|
158
|
-
if (contract.kind === 'default') {
|
|
159
|
-
return uniqueCandidates(this.context.allNodeClasses.flatMap((ref) => this.#applyExact(candidates, ref)));
|
|
160
|
-
}
|
|
161
|
-
return candidates;
|
|
162
|
-
}
|
|
163
|
-
const referenced = branch.terms.get(term);
|
|
164
|
-
if (referenced?.kind === 'ref') {
|
|
165
|
-
const contract = referenceContracts(this.context, referenced.ref, '/policies')?.[0];
|
|
166
|
-
return contract?.kind === 'exact' ? this.#applyExact(candidates, contract.ref) : [];
|
|
167
|
-
}
|
|
168
|
-
const selector = branch.variables.get(term);
|
|
169
|
-
if (selector === undefined)
|
|
170
|
-
return [];
|
|
171
|
-
if (selector.kind === 'exact')
|
|
172
|
-
return this.#applyExact(candidates, selector.class);
|
|
173
|
-
if (selector.kind === 'any')
|
|
174
|
-
return candidates;
|
|
175
|
-
return this.#applyRequirement(candidates, selector.class);
|
|
176
|
-
}
|
|
177
|
-
#applyExact(candidates, exact) {
|
|
178
|
-
const result = [];
|
|
179
|
-
for (const candidate of candidates) {
|
|
180
|
-
if (candidate.kind === 'exact') {
|
|
181
|
-
if (definitionRefIndex(candidate.ref) === definitionRefIndex(exact))
|
|
182
|
-
result.push(candidate);
|
|
183
|
-
}
|
|
184
|
-
else if (candidate.requirements.every((required) => this.context.classExtends(exact, required))) {
|
|
185
|
-
result.push({ kind: 'exact', ref: exact });
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return uniqueCandidates(result);
|
|
189
|
-
}
|
|
190
|
-
#applyAnyNodeClass(candidates) {
|
|
191
|
-
return uniqueCandidates(candidates.flatMap((candidate) => candidate.kind === 'exact'
|
|
192
|
-
? [candidate]
|
|
193
|
-
: this.context.allNodeClasses
|
|
194
|
-
.filter((ref) => candidate.requirements.every((required) => this.context.classExtends(ref, required)))
|
|
195
|
-
.map((ref) => ({ kind: 'exact', ref }))));
|
|
196
|
-
}
|
|
197
|
-
#applyRequirement(candidates, required) {
|
|
198
|
-
const result = [];
|
|
199
|
-
for (const candidate of candidates) {
|
|
200
|
-
if (candidate.kind === 'exact') {
|
|
201
|
-
if (this.context.classExtends(candidate.ref, required))
|
|
202
|
-
result.push(candidate);
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
result.push({
|
|
206
|
-
kind: 'open',
|
|
207
|
-
requirements: uniqueClasses([...candidate.requirements, required]),
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return uniqueCandidates(result);
|
|
212
|
-
}
|
|
213
|
-
#applyEndpoint(candidates, accepts) {
|
|
214
|
-
const result = [];
|
|
215
|
-
for (const candidate of candidates) {
|
|
216
|
-
if (candidate.kind === 'exact') {
|
|
217
|
-
if (this.#classSatisfiesEndpoint(candidate.ref, accepts))
|
|
218
|
-
result.push(candidate);
|
|
219
15
|
continue;
|
|
220
16
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
17
|
+
const use = mode === 'object'
|
|
18
|
+
? { kind: 'object', object: { kind: 'default' } }
|
|
19
|
+
: {
|
|
20
|
+
kind: 'edge',
|
|
21
|
+
source: { kind: 'default' },
|
|
22
|
+
target: { kind: 'default' },
|
|
23
|
+
};
|
|
24
|
+
if (!typing.branchIsTyped(branch, use)) {
|
|
25
|
+
context.add('PL_TYPING', `/policies/${escapePointerToken(name)}`, `Expanded normalized branch ${index} has contradictory endpoint or repeat contracts.`);
|
|
226
26
|
}
|
|
227
27
|
}
|
|
228
|
-
return uniqueCandidates(result);
|
|
229
28
|
}
|
|
230
|
-
#classSatisfiesEndpoint(candidate, accepts) {
|
|
231
|
-
return accepts.some((accept) => this.context.classExtends(candidate, accept));
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
function targetContract(term, use) {
|
|
235
|
-
if (use.kind === 'object')
|
|
236
|
-
return term === 'object' ? use.object : undefined;
|
|
237
|
-
if (term === 'source')
|
|
238
|
-
return use.source;
|
|
239
|
-
if (term === 'target')
|
|
240
|
-
return use.target;
|
|
241
|
-
return undefined;
|
|
242
29
|
}
|
|
243
30
|
export function contractOfNodeDefinition(ref) {
|
|
244
31
|
return { kind: 'exact', ref };
|
|
245
32
|
}
|
|
246
|
-
function edgeAlternatives(edges, typing) {
|
|
247
|
-
let result = [[]];
|
|
248
|
-
for (const edge of edges) {
|
|
249
|
-
const variants = variantsForEdge(edge, typing);
|
|
250
|
-
if (variants.length === 0)
|
|
251
|
-
return [];
|
|
252
|
-
const next = [];
|
|
253
|
-
for (const prefix of result) {
|
|
254
|
-
for (const variant of variants)
|
|
255
|
-
next.push([...prefix, variant]);
|
|
256
|
-
}
|
|
257
|
-
result = next;
|
|
258
|
-
}
|
|
259
|
-
return result;
|
|
260
|
-
}
|
|
261
|
-
function variantsForEdge(use, typing) {
|
|
262
|
-
const edge = use.pattern;
|
|
263
|
-
const declaration = typing.context.edgeDeclaration(edge.class);
|
|
264
|
-
if (declaration === undefined)
|
|
265
|
-
return [];
|
|
266
|
-
const endpoints = declaration.orientation === 'directed'
|
|
267
|
-
? [declaration.endpoints.source, declaration.endpoints.target]
|
|
268
|
-
: declaration.endpoints;
|
|
269
|
-
const bounds = edge.repeat ?? { min: 1, max: 1 };
|
|
270
|
-
if (!Number.isInteger(bounds.min) ||
|
|
271
|
-
!Number.isInteger(bounds.max) ||
|
|
272
|
-
bounds.min < 0 ||
|
|
273
|
-
bounds.max < bounds.min ||
|
|
274
|
-
bounds.max > MAX_REPEAT) {
|
|
275
|
-
return [];
|
|
276
|
-
}
|
|
277
|
-
const sourceKey = termKey(edge.source, use.namespace);
|
|
278
|
-
const targetKey = termKey(edge.target, use.namespace);
|
|
279
|
-
const variants = [];
|
|
280
|
-
for (let length = bounds.min; length <= bounds.max; length++) {
|
|
281
|
-
if (length === 0) {
|
|
282
|
-
variants.push({ constraints: [], equalities: [[sourceKey, targetKey]] });
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
const orientationCount = declaration.orientation === 'undirected' ? 2 ** length : 1;
|
|
286
|
-
for (let mask = 0; mask < orientationCount; mask++) {
|
|
287
|
-
const orientations = Array.from({ length }, (_, index) => declaration.orientation === 'undirected' && (mask & (1 << index)) !== 0);
|
|
288
|
-
let transitionsValid = true;
|
|
289
|
-
for (let index = 0; index + 1 < length; index++) {
|
|
290
|
-
const incoming = endEndpoint(endpoints, orientations[index] ?? false);
|
|
291
|
-
const outgoing = startEndpoint(endpoints, orientations[index + 1] ?? false);
|
|
292
|
-
if (!typing.endpointsOverlap(incoming.accepts, outgoing.accepts)) {
|
|
293
|
-
transitionsValid = false;
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (!transitionsValid)
|
|
298
|
-
continue;
|
|
299
|
-
const first = startEndpoint(endpoints, orientations[0] ?? false);
|
|
300
|
-
const last = endEndpoint(endpoints, orientations[length - 1] ?? false);
|
|
301
|
-
variants.push({
|
|
302
|
-
constraints: [
|
|
303
|
-
[sourceKey, first.accepts],
|
|
304
|
-
[targetKey, last.accepts],
|
|
305
|
-
],
|
|
306
|
-
equalities: [],
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return uniqueEdgeVariants(variants);
|
|
311
|
-
}
|
|
312
|
-
function startEndpoint(endpoints, reversed) {
|
|
313
|
-
return reversed ? endpoints[1] : endpoints[0];
|
|
314
|
-
}
|
|
315
|
-
function endEndpoint(endpoints, reversed) {
|
|
316
|
-
return reversed ? endpoints[0] : endpoints[1];
|
|
317
|
-
}
|
|
318
|
-
function uniqueEdgeVariants(values) {
|
|
319
|
-
const result = new Map();
|
|
320
|
-
for (const value of values) {
|
|
321
|
-
const key = `${value.constraints
|
|
322
|
-
.map(([term, accepts]) => `${term}:${accepts.map(definitionRefIndex).sort().join(',')}`)
|
|
323
|
-
.join('|')}=${value.equalities.map(([left, right]) => `${left}:${right}`).join('|')}`;
|
|
324
|
-
result.set(key, value);
|
|
325
|
-
}
|
|
326
|
-
return [...result.values()];
|
|
327
|
-
}
|
|
328
|
-
function uniqueCandidates(values) {
|
|
329
|
-
const result = new Map();
|
|
330
|
-
for (const value of values) {
|
|
331
|
-
const key = value.kind === 'exact'
|
|
332
|
-
? `exact:${definitionRefIndex(value.ref)}`
|
|
333
|
-
: `open:${value.requirements.map(definitionRefIndex).sort().join('|')}`;
|
|
334
|
-
result.set(key, value);
|
|
335
|
-
}
|
|
336
|
-
return [...result.values()];
|
|
337
|
-
}
|
|
338
|
-
function uniqueClasses(values) {
|
|
339
|
-
return [...new Map(values.map((value) => [definitionRefIndex(value), value])).values()];
|
|
340
|
-
}
|
|
341
|
-
class UnionFind {
|
|
342
|
-
#parents = new Map();
|
|
343
|
-
constructor(values) {
|
|
344
|
-
for (const value of values)
|
|
345
|
-
this.add(value);
|
|
346
|
-
}
|
|
347
|
-
add(value) {
|
|
348
|
-
if (!this.#parents.has(value))
|
|
349
|
-
this.#parents.set(value, value);
|
|
350
|
-
}
|
|
351
|
-
find(value) {
|
|
352
|
-
this.add(value);
|
|
353
|
-
const parent = this.#parents.get(value);
|
|
354
|
-
if (parent === value)
|
|
355
|
-
return value;
|
|
356
|
-
const root = this.find(parent);
|
|
357
|
-
this.#parents.set(value, root);
|
|
358
|
-
return root;
|
|
359
|
-
}
|
|
360
|
-
join(left, right) {
|
|
361
|
-
const a = this.find(left);
|
|
362
|
-
const b = this.find(right);
|
|
363
|
-
if (a !== b)
|
|
364
|
-
this.#parents.set(b, a);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
@@ -1,5 +1,42 @@
|
|
|
1
|
+
import type { CallableDefinition } from '../../../language/callable/model/callable.js';
|
|
2
|
+
import type { EdgeContract } from '../../../language/class/model/edge.js';
|
|
3
|
+
import type { PolicyTyping } from '../../../language/policy/analysis/typing.js';
|
|
4
|
+
import type { PolicyCheckExpression } from '../../../language/policy/model/policy.js';
|
|
5
|
+
import type { JsonSchema } from '../../../language/value/model/schema.js';
|
|
1
6
|
import type { PolicyValidationContext } from './context.js';
|
|
2
|
-
import { type
|
|
3
|
-
|
|
4
|
-
|
|
7
|
+
import { type ClassRef } from '../../../addressing/index.js';
|
|
8
|
+
interface CheckContext {
|
|
9
|
+
readonly site: keyof typeof SITE;
|
|
10
|
+
readonly pointer: string;
|
|
11
|
+
readonly input: JsonSchema;
|
|
12
|
+
/** The Node Class that receives the call, which the checks name `self`; none, and none is named. */
|
|
13
|
+
readonly receiver?: ClassRef;
|
|
14
|
+
/** In an Edge Class rule, the Edge `self` names, in place of a receiver. */
|
|
15
|
+
readonly edge?: EdgeUse;
|
|
16
|
+
}
|
|
17
|
+
/** One Edge Class, whose declaration fixes the concrete Node Classes of its endpoints. */
|
|
18
|
+
interface EdgeUse {
|
|
19
|
+
readonly ref: ClassRef;
|
|
20
|
+
readonly declaration: EdgeContract;
|
|
21
|
+
}
|
|
22
|
+
/** How a refusal names the checks of each site and the contract of their objects. */
|
|
23
|
+
export declare const SITE: {
|
|
24
|
+
readonly callable: {
|
|
25
|
+
readonly checks: 'Callable checks';
|
|
26
|
+
readonly objects: 'the callable object contract';
|
|
27
|
+
};
|
|
28
|
+
readonly class: {
|
|
29
|
+
readonly checks: 'Class rule checks';
|
|
30
|
+
readonly objects: 'the Class rule object contract';
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/** Type every Class slot: its Policy against the instance it decides, or its Policy checks. */
|
|
34
|
+
export declare function validateClassUses(context: PolicyValidationContext, typing: PolicyTyping): void;
|
|
5
35
|
export declare function validateCallableUses(context: PolicyValidationContext, typing: PolicyTyping): void;
|
|
36
|
+
/**
|
|
37
|
+
* Validate the Policy of one callable contract written at `pointer`, wherever it is declared:
|
|
38
|
+
* `self` names the Node of the `receiver` Class, and nothing where the call has no receiver.
|
|
39
|
+
*/
|
|
40
|
+
export declare function validateContractPolicy(context: PolicyValidationContext, typing: PolicyTyping, contract: CallableDefinition, pointer: string, receiver: ClassRef | undefined): void;
|
|
41
|
+
export declare function validateChecks(validation: PolicyValidationContext, typing: PolicyTyping, expression: PolicyCheckExpression, context: CheckContext): void;
|
|
42
|
+
export {};
|