@astrale-os/kernel-core 0.9.0-beta.53 → 0.9.0-beta.55

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.
Files changed (52) hide show
  1. package/dist/auth/authority/admission/admission.d.ts +2 -0
  2. package/dist/auth/authority/admission/admission.js +7 -0
  3. package/dist/auth/authority/admission/index.d.ts +1 -1
  4. package/dist/auth/authority/admission/index.js +1 -1
  5. package/dist/auth/authority/index.d.ts +2 -0
  6. package/dist/auth/authority/index.js +2 -0
  7. package/dist/auth/authority/normalization/index.d.ts +1 -1
  8. package/dist/auth/authority/normalization/index.js +1 -1
  9. package/dist/auth/authority/normalization/normalize.d.ts +2 -0
  10. package/dist/auth/authority/normalization/normalize.js +11 -2
  11. package/dist/auth/authority/ownership.optimization.d.ts +5 -1
  12. package/dist/auth/authority/ownership.optimization.js +61 -0
  13. package/dist/auth/authority/prepare-grant-body.d.ts +4 -0
  14. package/dist/auth/authority/prepare-grant-body.js +27 -0
  15. package/dist/callable/contract/body.d.ts +10 -0
  16. package/dist/callable/contract/body.js +7 -0
  17. package/dist/callable/contract/index.d.ts +2 -1
  18. package/dist/callable/contract/index.js +1 -1
  19. package/dist/callable/contract/output.d.ts +8 -0
  20. package/dist/callable/index.d.ts +2 -1
  21. package/dist/callable/index.js +1 -0
  22. package/dist/schema/callables/function.d.ts +3430 -3
  23. package/dist/schema/callables/function.js +3 -2
  24. package/dist/schema/domain/domain.d.ts +30 -30
  25. package/dist/schema/identity/identity.d.ts +17 -17
  26. package/dist/schema/kernel/schema.d.ts +3907 -432
  27. package/dist/schema/kernel/schema.js +2 -0
  28. package/dist/schema/kernel/syscalls/contracts/blob.d.ts +21 -0
  29. package/dist/schema/kernel/syscalls/contracts/blob.js +16 -0
  30. package/dist/schema/kernel/syscalls/contracts/delegate.d.ts +1 -1
  31. package/dist/schema/kernel/syscalls/contracts/delegate.js +2 -1
  32. package/dist/schema/kernel/syscalls/contracts/index.d.ts +1 -0
  33. package/dist/schema/kernel/syscalls/contracts/index.js +1 -0
  34. package/dist/schema/kernel/syscalls/declarations/delegate.d.ts +1 -1
  35. package/dist/schema/kernel/syscalls/declarations/download.d.ts +7 -0
  36. package/dist/schema/kernel/syscalls/declarations/download.js +10 -0
  37. package/dist/schema/kernel/syscalls/declarations/index.d.ts +44 -24
  38. package/dist/schema/kernel/syscalls/declarations/index.js +4 -0
  39. package/dist/schema/kernel/syscalls/declarations/upload.d.ts +15 -0
  40. package/dist/schema/kernel/syscalls/declarations/upload.js +10 -0
  41. package/dist/schema/kernel/syscalls/descriptors/functions.d.ts +2 -0
  42. package/dist/schema/kernel/syscalls/descriptors/functions.js +2 -0
  43. package/dist/schema/kernel/syscalls/descriptors/identity.d.ts +1 -1
  44. package/dist/schema/kernel/syscalls/descriptors/index.d.ts +1 -1
  45. package/dist/schema/kernel/syscalls/descriptors/index.js +1 -1
  46. package/dist/schema/kernel/syscalls/index.d.ts +1 -1
  47. package/dist/schema/kernel/syscalls/index.js +1 -1
  48. package/dist/schema/kernel/syscalls/references/functions.d.ts +10 -0
  49. package/dist/schema/kernel/syscalls/references/functions.js +2 -0
  50. package/dist/schema/kernel/syscalls/references/index.d.ts +1 -1
  51. package/dist/schema/kernel/syscalls/references/index.js +1 -1
  52. package/package.json +3 -3
@@ -9,3 +9,5 @@ export declare const limits: {
9
9
  };
10
10
  export declare const MAX_BOOLEAN_OPERANDS: 512;
11
11
  export declare function admitAuthorityExpr(input: portable.Value): AuthorityExpr;
12
+ /** Internal constructor admission: the outer Grant binds subject, but no local escapes into it. */
13
+ export declare function admitGrantBody(input: portable.Value): AuthorityExpr;
@@ -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,
@@ -13,9 +14,15 @@ export const MAX_BOOLEAN_OPERANDS = limits.operandsPerExpression;
13
14
  export function admitAuthorityExpr(input) {
14
15
  return admit(input, '/predicate', new Set(), false, 0);
15
16
  }
17
+ /** Internal constructor admission: the outer Grant binds subject, but no local escapes into it. */
18
+ export function admitGrantBody(input) {
19
+ return admit(input, '/predicate/where', new Set(), true, 1);
20
+ }
16
21
  function admit(input, path, locals, subjectBound, depth) {
17
22
  if (depth > limits.expressionDepth)
18
23
  invalid(path, 'Authority expression exceeds its depth limit');
24
+ if (locals.size === 0 && ownsExpression(input, limits.expressionDepth - depth))
25
+ return input;
19
26
  const value = record(input, path);
20
27
  switch (value.op) {
21
28
  case 'true':
@@ -1 +1 @@
1
- export { admitAuthorityExpr, limits } from './admission.js';
1
+ export { admitAuthorityExpr, admitGrantBody, limits } from './admission.js';
@@ -1 +1 @@
1
- export { admitAuthorityExpr, limits } from './admission.js';
1
+ export { admitAuthorityExpr, admitGrantBody, limits } from './admission.js';
@@ -1,5 +1,7 @@
1
1
  export { accept } from './accept.js';
2
2
  export { isCanonical } from './canonical.js';
3
+ export { ownsCanonical } from './ownership.optimization.js';
4
+ export { prepareGrantBody } from './prepare-grant-body.js';
3
5
  export { limits } from './admission/index.js';
4
6
  export { canonicalize } from './normalization/index.js';
5
7
  export { AUTHORITY_PREDICATE_VERSION } from './language/index.js';
@@ -1,5 +1,7 @@
1
1
  export { accept } from './accept.js';
2
2
  export { isCanonical } from './canonical.js';
3
+ export { ownsCanonical } from './ownership.optimization.js';
4
+ export { prepareGrantBody } from './prepare-grant-body.js';
3
5
  export { limits } from './admission/index.js';
4
6
  export { canonicalize } from './normalization/index.js';
5
7
  export { AUTHORITY_PREDICATE_VERSION } from './language/index.js';
@@ -1 +1 @@
1
- export { canonicalize, canonicalizeAdmitted } from './normalize.js';
1
+ export { canonicalize, canonicalizeAdmitted, normalizeGrantBodyAdmitted } from './normalize.js';
@@ -1 +1 @@
1
- export { canonicalize, canonicalizeAdmitted } from './normalize.js';
1
+ export { canonicalize, canonicalizeAdmitted, normalizeGrantBodyAdmitted } from './normalize.js';
@@ -2,3 +2,5 @@ import type { AuthorityExpr, AuthorityPredicate } from '../language/index.js';
2
2
  /** Validate and canonicalize one authority expression into its versioned crossing envelope. */
3
3
  export declare function canonicalize(expr: AuthorityExpr): AuthorityPredicate;
4
4
  export declare function canonicalizeAdmitted(expr: AuthorityExpr): AuthorityPredicate;
5
+ /** Internal scoped normalization; this body is not a closed owned authority expression. */
6
+ export declare function normalizeGrantBodyAdmitted(expr: AuthorityExpr): AuthorityExpr;
@@ -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 admitted = admitAuthorityExpr(portable.accept(expr));
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) {
@@ -16,7 +19,13 @@ export function canonicalizeAdmitted(expr) {
16
19
  predicate: normalize(expr, '/predicate', new Set(), false),
17
20
  }));
18
21
  }
22
+ /** Internal scoped normalization; this body is not a closed owned authority expression. */
23
+ export function normalizeGrantBodyAdmitted(expr) {
24
+ return normalize(expr, '/predicate/where', new Set(), true);
25
+ }
19
26
  function normalize(expr, path, locals, subjectBound) {
27
+ if (ownsExpression(expr))
28
+ return expr;
20
29
  switch (expr.op) {
21
30
  case 'true':
22
31
  case 'false':
@@ -1,4 +1,8 @@
1
- import type { AuthorityPredicate } from './language/index.js';
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,6 +1,9 @@
1
1
  import * as portable from '@astrale-os/kernel-dsl/value';
2
+ import { AUTHORITY_PREDICATE_VERSION, } from './language/index.js';
2
3
  // Static construction provenance only. No evaluated authority or graph facts live here.
3
4
  const canonical = new WeakSet();
5
+ const expressions = new WeakMap();
6
+ const depths = new WeakMap();
4
7
  /** Called only by the owner after detachment, admission and immutable normalization. */
5
8
  export function ownCanonical(predicate) {
6
9
  // Carry immutable structural provenance through containing Plans as well as Core calls.
@@ -8,6 +11,10 @@ export function ownCanonical(predicate) {
8
11
  // constructor's expression fits. In that case retain Core ownership only: a later crossing
9
12
  // still applies its own limits, without adding a new constructor failure here.
10
13
  try {
14
+ predicate = Object.freeze({
15
+ ...predicate,
16
+ predicate: portable.acceptImmutable(predicate.predicate),
17
+ });
11
18
  predicate = portable.acceptImmutable(predicate);
12
19
  }
13
20
  catch (cause) {
@@ -15,8 +22,62 @@ export function ownCanonical(predicate) {
15
22
  throw cause;
16
23
  }
17
24
  canonical.add(predicate);
25
+ retainClosedExpression(predicate.predicate);
26
+ expressions.set(predicate.predicate, predicate);
18
27
  return predicate;
19
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
+ }
20
81
  export function ownsCanonical(input) {
21
82
  return input !== null && typeof input === 'object' && canonical.has(input);
22
83
  }
@@ -0,0 +1,4 @@
1
+ import type { Grant } from '../grant/index.js';
2
+ import type { AuthorityExpr, AuthorityPredicate } from './language/index.js';
3
+ /** Prepare one body in a fresh Grant subject scope, independently of any concrete Grant. */
4
+ export declare function prepareGrantBody(where: AuthorityExpr): (grant: Grant) => AuthorityPredicate;
@@ -0,0 +1,27 @@
1
+ import * as portable from '@astrale-os/kernel-dsl/value';
2
+ import { accept as acceptGrant, canonicalize as canonicalizeGrant } from '../grant/index.js';
3
+ import { admitGrantBody } from './admission/index.js';
4
+ import { AUTHORITY_PREDICATE_VERSION } from './language/index.js';
5
+ import { normalizeGrantBodyAdmitted } from './normalization/index.js';
6
+ import { ownCanonical } from './ownership.optimization.js';
7
+ /** Prepare one body in a fresh Grant subject scope, independently of any concrete Grant. */
8
+ export function prepareGrantBody(where) {
9
+ const admitted = admitGrantBody(portable.acceptForRead(where));
10
+ const body = portable.acceptImmutable(normalizeGrantBodyAdmitted(admitted));
11
+ return grantBinder(body);
12
+ }
13
+ // A distinct closure scope retains only the normalized body, never an initial Grant or caller input.
14
+ function grantBinder(where) {
15
+ return (grant) => {
16
+ // Charge the entire expression on every binding, including the body and its outer container.
17
+ const value = portable.acceptForRead({ op: 'grant', grant, where });
18
+ return ownCanonical(Object.freeze({
19
+ version: AUTHORITY_PREDICATE_VERSION,
20
+ predicate: Object.freeze({
21
+ op: 'grant',
22
+ grant: canonicalizeGrant(acceptGrant(value.grant)),
23
+ where,
24
+ }),
25
+ }));
26
+ };
27
+ }
@@ -0,0 +1,10 @@
1
+ /** One root invocation's already bounded, single-consumer binary request body. */
2
+ export interface BinaryRequestBody {
3
+ readonly body: ReadableStream<Uint8Array>;
4
+ readonly length: number;
5
+ }
6
+ /** The streamed request ended early or exceeded its declared Content-Length. */
7
+ export declare class BinaryBodyLengthError extends Error {
8
+ readonly name = "BinaryBodyLengthError";
9
+ constructor();
10
+ }
@@ -0,0 +1,7 @@
1
+ /** The streamed request ended early or exceeded its declared Content-Length. */
2
+ export class BinaryBodyLengthError extends Error {
3
+ name = 'BinaryBodyLengthError';
4
+ constructor() {
5
+ super('Binary request length mismatch.');
6
+ }
7
+ }
@@ -1,5 +1,6 @@
1
1
  export type { CallOf } from './call.js';
2
+ export { BinaryBodyLengthError, type BinaryRequestBody } from './body.js';
2
3
  export type { InputOf } from './input.js';
3
- export type { BinaryOutput, BufferedBinaryResult, OutputContractOf, OutputOf, StreamingBinaryResult, TypedCallableOutput, } from './output.js';
4
+ export type { BinaryOutput, BinaryDeliveryBudget, BufferedBinaryResult, OutputContractOf, OutputOf, StreamingBinaryResult, TypedCallableOutput, } from './output.js';
4
5
  export type { CallableSignature } from './signature.js';
5
6
  export type { Callable, SignatureOf } from './witness.js';
@@ -1 +1 @@
1
- export {};
1
+ export { BinaryBodyLengthError } from './body.js';
@@ -1,4 +1,9 @@
1
1
  import type { SignatureOf } from './witness.js';
2
+ /** Optional owner-selected lifetime for a large HTTP binary result. */
3
+ export interface BinaryDeliveryBudget {
4
+ readonly maximumDurationMs: number;
5
+ readonly idleTimeoutMs: number;
6
+ }
2
7
  export interface BufferedBinaryResult {
3
8
  readonly body: Uint8Array;
4
9
  readonly mediaType: string;
@@ -7,6 +12,9 @@ export interface BufferedBinaryResult {
7
12
  }
8
13
  export interface StreamingBinaryResult {
9
14
  readonly body: AsyncIterable<Uint8Array>;
15
+ /** Exact byte length; HTTP aborts delivery if the stream differs. */
16
+ readonly length?: number;
17
+ readonly delivery?: BinaryDeliveryBudget;
10
18
  readonly mediaType: string;
11
19
  readonly status?: number;
12
20
  readonly headers?: Readonly<Record<string, string>>;
@@ -1,2 +1,3 @@
1
- export type { BinaryOutput, BufferedBinaryResult, Callable, CallableSignature, CallOf, InputOf, OutputContractOf, OutputOf, SignatureOf, StreamingBinaryResult, TypedCallableOutput, } from './contract/index.js';
1
+ export { BinaryBodyLengthError } from './contract/index.js';
2
+ export type { BinaryOutput, BinaryDeliveryBudget, BinaryRequestBody, BufferedBinaryResult, Callable, CallableSignature, CallOf, InputOf, OutputContractOf, OutputOf, SignatureOf, StreamingBinaryResult, TypedCallableOutput, } from './contract/index.js';
2
3
  export { Target, targetPath, type Call, type CallableResult } from './invocation/index.js';
@@ -1 +1,2 @@
1
+ export { BinaryBodyLengthError } from './contract/index.js';
1
2
  export { Target, targetPath } from './invocation/index.js';