@astrale-os/kernel-core 0.9.0-beta.52 → 0.9.0-beta.54
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/auth/authority/accept.js +4 -0
- package/dist/auth/authority/admission/admission.js +3 -0
- package/dist/auth/authority/normalization/normalize.js +7 -2
- package/dist/auth/authority/ownership.optimization.d.ts +5 -1
- package/dist/auth/authority/ownership.optimization.js +73 -0
- package/dist/schema/callables/function.d.ts +3430 -3
- package/dist/schema/callables/function.js +3 -2
- package/dist/schema/identity/identity.d.ts +15 -15
- package/dist/schema/kernel/projection/project.js +12 -5
- package/dist/schema/kernel/schema.d.ts +4000 -573
- package/dist/schema/kernel/syscalls/declarations/index.d.ts +23 -23
- package/dist/schema/kernel/syscalls/declarations/mutate.d.ts +23 -23
- package/package.json +3 -3
|
@@ -3,8 +3,12 @@ import { AuthValueError } from '../error.js';
|
|
|
3
3
|
import { admitAuthorityExpr } from './admission/index.js';
|
|
4
4
|
import { AUTHORITY_PREDICATE_VERSION } from './language/index.js';
|
|
5
5
|
import { canonicalizeAdmitted } from './normalization/index.js';
|
|
6
|
+
import { ownsCanonical } from './ownership.optimization.js';
|
|
6
7
|
/** Re-admit one persisted or crossing canonical authority predicate. */
|
|
7
8
|
export function accept(input) {
|
|
9
|
+
// The owner retains only deeply immutable, detached canonical predicates.
|
|
10
|
+
if (ownsCanonical(input))
|
|
11
|
+
return input;
|
|
8
12
|
try {
|
|
9
13
|
const admitted = portable.accept(input);
|
|
10
14
|
if (admitted === null || Array.isArray(admitted) || typeof admitted !== 'object') {
|
|
@@ -2,6 +2,7 @@ import { patterns } from '@astrale-os/kernel-dsl/v1/addressing';
|
|
|
2
2
|
import { isNodeId } from '../../../graph/node/index.js';
|
|
3
3
|
import { AuthValueError } from '../../error.js';
|
|
4
4
|
import { accept as acceptGrant } from '../../grant/index.js';
|
|
5
|
+
import { ownsExpression } from '../ownership.optimization.js';
|
|
5
6
|
export const limits = Object.freeze({
|
|
6
7
|
expressionDepth: 64,
|
|
7
8
|
operandsPerExpression: 512,
|
|
@@ -16,6 +17,8 @@ export function admitAuthorityExpr(input) {
|
|
|
16
17
|
function admit(input, path, locals, subjectBound, depth) {
|
|
17
18
|
if (depth > limits.expressionDepth)
|
|
18
19
|
invalid(path, 'Authority expression exceeds its depth limit');
|
|
20
|
+
if (locals.size === 0 && ownsExpression(input, limits.expressionDepth - depth))
|
|
21
|
+
return input;
|
|
19
22
|
const value = record(input, path);
|
|
20
23
|
switch (value.op) {
|
|
21
24
|
case 'true':
|
|
@@ -4,10 +4,13 @@ import { AuthValueError } from '../../error.js';
|
|
|
4
4
|
import { canonicalize as canonicalizeGrant } from '../../grant/index.js';
|
|
5
5
|
import { admitAuthorityExpr, limits } from '../admission/index.js';
|
|
6
6
|
import { AUTHORITY_PREDICATE_VERSION } from '../language/index.js';
|
|
7
|
-
import { ownCanonical } from '../ownership.optimization.js';
|
|
7
|
+
import { ownCanonical, ownedExpression, ownsExpression } from '../ownership.optimization.js';
|
|
8
8
|
/** Validate and canonicalize one authority expression into its versioned crossing envelope. */
|
|
9
9
|
export function canonicalize(expr) {
|
|
10
|
-
const
|
|
10
|
+
const owned = ownedExpression(expr);
|
|
11
|
+
if (owned !== undefined)
|
|
12
|
+
return owned;
|
|
13
|
+
const admitted = admitAuthorityExpr(portable.acceptForRead(expr));
|
|
11
14
|
return canonicalizeAdmitted(admitted);
|
|
12
15
|
}
|
|
13
16
|
export function canonicalizeAdmitted(expr) {
|
|
@@ -17,6 +20,8 @@ export function canonicalizeAdmitted(expr) {
|
|
|
17
20
|
}));
|
|
18
21
|
}
|
|
19
22
|
function normalize(expr, path, locals, subjectBound) {
|
|
23
|
+
if (ownsExpression(expr))
|
|
24
|
+
return expr;
|
|
20
25
|
switch (expr.op) {
|
|
21
26
|
case 'true':
|
|
22
27
|
case 'false':
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AuthorityExpr, type AuthorityPredicate } from './language/index.js';
|
|
2
2
|
/** Called only by the owner after detachment, admission and immutable normalization. */
|
|
3
3
|
export declare function ownCanonical(predicate: AuthorityPredicate): AuthorityPredicate;
|
|
4
|
+
/** Closed subprograms retain their lexical proof when composed outside another local binder. */
|
|
5
|
+
export declare function ownsExpression(expression: unknown, remainingDepth?: number): boolean;
|
|
6
|
+
/** Rewrap only owner-proven closed expressions, never a leaf borrowed from a lexical binder. */
|
|
7
|
+
export declare function ownedExpression(expression: AuthorityExpr): AuthorityPredicate | undefined;
|
|
4
8
|
export declare function ownsCanonical(input: unknown): boolean;
|
|
@@ -1,10 +1,83 @@
|
|
|
1
|
+
import * as portable from '@astrale-os/kernel-dsl/value';
|
|
2
|
+
import { AUTHORITY_PREDICATE_VERSION, } from './language/index.js';
|
|
1
3
|
// Static construction provenance only. No evaluated authority or graph facts live here.
|
|
2
4
|
const canonical = new WeakSet();
|
|
5
|
+
const expressions = new WeakMap();
|
|
6
|
+
const depths = new WeakMap();
|
|
3
7
|
/** Called only by the owner after detachment, admission and immutable normalization. */
|
|
4
8
|
export function ownCanonical(predicate) {
|
|
9
|
+
// Carry immutable structural provenance through containing Plans as well as Core calls.
|
|
10
|
+
// The normalized envelope can exceed a portable boundary's default budget even when the
|
|
11
|
+
// constructor's expression fits. In that case retain Core ownership only: a later crossing
|
|
12
|
+
// still applies its own limits, without adding a new constructor failure here.
|
|
13
|
+
try {
|
|
14
|
+
predicate = Object.freeze({
|
|
15
|
+
...predicate,
|
|
16
|
+
predicate: portable.acceptImmutable(predicate.predicate),
|
|
17
|
+
});
|
|
18
|
+
predicate = portable.acceptImmutable(predicate);
|
|
19
|
+
}
|
|
20
|
+
catch (cause) {
|
|
21
|
+
if (!(cause instanceof portable.BoundaryError) || cause.code !== 'VALUE_LIMIT')
|
|
22
|
+
throw cause;
|
|
23
|
+
}
|
|
5
24
|
canonical.add(predicate);
|
|
25
|
+
retainClosedExpression(predicate.predicate);
|
|
26
|
+
expressions.set(predicate.predicate, predicate);
|
|
6
27
|
return predicate;
|
|
7
28
|
}
|
|
29
|
+
/** Closed subprograms retain their lexical proof when composed outside another local binder. */
|
|
30
|
+
export function ownsExpression(expression, remainingDepth = Infinity) {
|
|
31
|
+
if (expression === null ||
|
|
32
|
+
typeof expression !== 'object' ||
|
|
33
|
+
!expressions.has(expression))
|
|
34
|
+
return false;
|
|
35
|
+
if (remainingDepth === Infinity)
|
|
36
|
+
return true;
|
|
37
|
+
const value = expression;
|
|
38
|
+
return expressionDepth(value) <= remainingDepth;
|
|
39
|
+
}
|
|
40
|
+
function expressionDepth(expression) {
|
|
41
|
+
const known = depths.get(expression);
|
|
42
|
+
if (known !== undefined)
|
|
43
|
+
return known;
|
|
44
|
+
const children = expression.op === 'all' || expression.op === 'any'
|
|
45
|
+
? expression.predicates
|
|
46
|
+
: expression.op === 'not'
|
|
47
|
+
? [expression.predicate]
|
|
48
|
+
: expression.op === 'grant' || expression.op === 'exists'
|
|
49
|
+
? [expression.where]
|
|
50
|
+
: [];
|
|
51
|
+
const depth = children.length === 0 ? 0 : 1 + Math.max(...children.map(expressionDepth));
|
|
52
|
+
depths.set(expression, depth);
|
|
53
|
+
return depth;
|
|
54
|
+
}
|
|
55
|
+
/** Rewrap only owner-proven closed expressions, never a leaf borrowed from a lexical binder. */
|
|
56
|
+
export function ownedExpression(expression) {
|
|
57
|
+
const known = expressions.get(expression);
|
|
58
|
+
if (known === undefined)
|
|
59
|
+
return undefined;
|
|
60
|
+
if (known !== null)
|
|
61
|
+
return known;
|
|
62
|
+
const predicate = ownCanonical(Object.freeze({
|
|
63
|
+
version: AUTHORITY_PREDICATE_VERSION,
|
|
64
|
+
predicate: expression,
|
|
65
|
+
}));
|
|
66
|
+
expressions.set(expression, predicate);
|
|
67
|
+
return predicate;
|
|
68
|
+
}
|
|
69
|
+
function retainClosedExpression(expression) {
|
|
70
|
+
if (expressions.has(expression))
|
|
71
|
+
return;
|
|
72
|
+
expressions.set(expression, null);
|
|
73
|
+
if (expression.op === 'all' || expression.op === 'any') {
|
|
74
|
+
for (const child of expression.predicates)
|
|
75
|
+
retainClosedExpression(child);
|
|
76
|
+
}
|
|
77
|
+
else if (expression.op === 'not')
|
|
78
|
+
retainClosedExpression(expression.predicate);
|
|
79
|
+
// A complete Grant or existential is closed, but its body may depend on its binder.
|
|
80
|
+
}
|
|
8
81
|
export function ownsCanonical(input) {
|
|
9
82
|
return input !== null && typeof input === 'object' && canonical.has(input);
|
|
10
83
|
}
|