@astrale-os/kernel-core 0.9.0-beta.63 → 0.9.0-beta.65

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 (110) hide show
  1. package/dist/auth/authority/admission/admission.d.ts +2 -2
  2. package/dist/auth/authority/admission/admission.js +10 -8
  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 +7 -3
  6. package/dist/auth/authority/index.js +4 -2
  7. package/dist/auth/authority/language/index.d.ts +2 -0
  8. package/dist/auth/authority/language/index.js +1 -0
  9. package/dist/auth/authority/language/predicate.d.ts +10 -5
  10. package/dist/auth/authority/language/predicate.js +1 -1
  11. package/dist/auth/authority/language/program.d.ts +21 -0
  12. package/dist/auth/authority/language/program.js +2 -0
  13. package/dist/auth/authority/normalization/index.d.ts +1 -1
  14. package/dist/auth/authority/normalization/index.js +1 -1
  15. package/dist/auth/authority/normalization/normalize.d.ts +1 -1
  16. package/dist/auth/authority/normalization/normalize.js +4 -5
  17. package/dist/auth/authority/ownership.optimization.js +2 -2
  18. package/dist/auth/authority/prepare-binder-body.d.ts +4 -0
  19. package/dist/auth/authority/prepare-binder-body.js +31 -0
  20. package/dist/auth/authority/program.d.ts +28 -0
  21. package/dist/auth/authority/program.js +191 -0
  22. package/dist/auth/authority/semantics/class-authority.d.ts +8 -0
  23. package/dist/auth/authority/semantics/class-authority.js +26 -0
  24. package/dist/auth/authority/semantics/composition.d.ts +39 -0
  25. package/dist/auth/authority/semantics/composition.js +112 -0
  26. package/dist/auth/authority/semantics/failure.d.ts +21 -0
  27. package/dist/auth/authority/semantics/failure.js +10 -0
  28. package/dist/auth/authority/semantics/index.d.ts +11 -0
  29. package/dist/auth/authority/semantics/index.js +5 -0
  30. package/dist/auth/authority/semantics/interpret.d.ts +35 -0
  31. package/dist/auth/authority/semantics/interpret.js +215 -0
  32. package/dist/auth/authority/semantics/snapshot.d.ts +34 -0
  33. package/dist/auth/authority/semantics/terms.d.ts +20 -0
  34. package/dist/auth/authority/semantics/terms.js +96 -0
  35. package/dist/auth/authority/semantics/vocabulary.d.ts +19 -0
  36. package/dist/auth/authority/semantics/vocabulary.js +1 -0
  37. package/dist/auth/context/context.d.ts +4 -3
  38. package/dist/auth/expression/authoring/builder.d.ts +2 -11
  39. package/dist/auth/expression/authoring/builder.js +1 -45
  40. package/dist/auth/expression/authoring/index.d.ts +1 -1
  41. package/dist/auth/expression/authoring/index.js +1 -1
  42. package/dist/auth/expression/index.d.ts +1 -2
  43. package/dist/auth/expression/index.js +1 -2
  44. package/dist/auth/expression/language/identity-expression.d.ts +2 -22
  45. package/dist/auth/grant/index.d.ts +1 -1
  46. package/dist/auth/grant/index.js +1 -1
  47. package/dist/auth/grant/resolved/admission.d.ts +4 -3
  48. package/dist/auth/grant/resolved/admission.js +23 -13
  49. package/dist/auth/grant/resolved/grant.d.ts +1 -1
  50. package/dist/auth/grant/resolved/index.d.ts +1 -1
  51. package/dist/auth/grant/resolved/index.js +1 -1
  52. package/dist/auth/grant/unresolved/admission.d.ts +4 -1
  53. package/dist/auth/grant/unresolved/admission.js +27 -67
  54. package/dist/auth/grant/unresolved/limits.d.ts +2 -4
  55. package/dist/auth/grant/unresolved/limits.js +1 -5
  56. package/dist/auth/index.d.ts +1 -1
  57. package/dist/graph/graph/graph.d.ts +1 -5
  58. package/dist/graph/graph/graph.js +3 -27
  59. package/dist/graph/graph/index.d.ts +1 -3
  60. package/dist/graph/graph/index.js +1 -2
  61. package/dist/graph/query/index.d.ts +2 -0
  62. package/dist/graph/query/index.js +1 -0
  63. package/dist/graph/query/order/index.d.ts +46 -0
  64. package/dist/graph/query/order/index.js +59 -0
  65. package/dist/graph/query/reference/evaluate.js +24 -50
  66. package/dist/graph/reconcile/planning/canonical.d.ts +6 -0
  67. package/dist/graph/reconcile/planning/canonical.js +28 -0
  68. package/dist/graph/reconcile/planning/model.d.ts +4 -0
  69. package/dist/graph/reconcile/planning/plan.js +2 -1
  70. package/dist/schema/authority/vocabulary.d.ts +3 -0
  71. package/dist/schema/authority/vocabulary.js +25 -0
  72. package/dist/schema/callables/function.d.ts +120 -90
  73. package/dist/schema/domain/domain.d.ts +120 -90
  74. package/dist/schema/identity/composition.d.ts +5 -0
  75. package/dist/schema/identity/composition.js +5 -0
  76. package/dist/schema/identity/identity.d.ts +8 -6
  77. package/dist/schema/index.d.ts +1 -0
  78. package/dist/schema/index.js +1 -0
  79. package/dist/schema/kernel/schema.d.ts +337 -276
  80. package/dist/schema/kernel/syscalls/contracts/delegate.d.ts +4 -1
  81. package/dist/schema/kernel/syscalls/contracts/delegate.js +4 -3
  82. package/dist/schema/kernel/syscalls/contracts/impersonate.d.ts +0 -1
  83. package/dist/schema/kernel/syscalls/contracts/legacy/delegate.d.ts +5 -0
  84. package/dist/schema/kernel/syscalls/contracts/legacy/delegate.js +25 -0
  85. package/dist/schema/kernel/syscalls/contracts/mint.d.ts +0 -1
  86. package/dist/schema/kernel/syscalls/contracts/mint.js +1 -2
  87. package/dist/schema/kernel/syscalls/declarations/delegate.d.ts +4 -1
  88. package/dist/schema/kernel/syscalls/declarations/impersonate.d.ts +0 -1
  89. package/dist/schema/kernel/syscalls/declarations/index.d.ts +35 -34
  90. package/dist/schema/kernel/syscalls/declarations/install.d.ts +8 -8
  91. package/dist/schema/kernel/syscalls/declarations/mint.d.ts +0 -1
  92. package/dist/schema/kernel/syscalls/declarations/mutate.d.ts +23 -23
  93. package/dist/schema/kernel/syscalls/descriptors/identity.d.ts +4 -3
  94. package/package.json +2 -2
  95. package/dist/auth/authority/prepare-grant-body.d.ts +0 -4
  96. package/dist/auth/authority/prepare-grant-body.js +0 -27
  97. package/dist/auth/expression/normalization/canonicalize.d.ts +0 -7
  98. package/dist/auth/expression/normalization/canonicalize.js +0 -102
  99. package/dist/auth/expression/normalization/index.d.ts +0 -2
  100. package/dist/auth/expression/normalization/index.js +0 -2
  101. package/dist/auth/expression/normalization/raise-denials.d.ts +0 -3
  102. package/dist/auth/expression/normalization/raise-denials.js +0 -59
  103. package/dist/graph/graph/navigation/error.d.ts +0 -12
  104. package/dist/graph/graph/navigation/error.js +0 -20
  105. package/dist/graph/graph/navigation/index.d.ts +0 -2
  106. package/dist/graph/graph/navigation/index.js +0 -1
  107. package/dist/graph/graph/navigation/model.d.ts +0 -15
  108. package/dist/schema/kernel/projection/path.d.ts +0 -2
  109. package/dist/schema/kernel/projection/path.js +0 -113
  110. /package/dist/{graph/graph/navigation/model.js → auth/authority/semantics/snapshot.js} +0 -0
@@ -6,6 +6,7 @@ import { GraphData } from '../../graph/index.js';
6
6
  import { NodeId as admitNodeId } from '../../node/index.js';
7
7
  import { compareNodeIds } from '../../node/index.js';
8
8
  import { encodeQueryAST, QueryASTDecodeError } from '../language/index.js';
9
+ import { compareQueryRank } from '../order/index.js';
9
10
  import { decodeQueryResult } from '../result/index.js';
10
11
  import { QueryReferenceError } from './error.js';
11
12
  /** Independent backend-neutral executable Query V6 row algebra. */
@@ -273,9 +274,13 @@ function decodeWitness(input, path, context) {
273
274
  }
274
275
  function selectNodes(rows, select, size, after, admission, properties) {
275
276
  const selected = new Map();
277
+ const ordered = orderedClasses(select.order, 'node', properties);
276
278
  rows.forEach((row) => {
277
279
  const node = boundNode(row, select.binding, '/select/binding');
278
- const needsRead = select.kind === 'graph' || (select.kind === 'nodes' && select.projection.kind === 'value');
280
+ // A value is read; an ordered reference reads a fact its order applies to before ranking it.
281
+ const needsRead = select.kind === 'graph' ||
282
+ (select.kind === 'nodes' && select.projection.kind === 'value') ||
283
+ ordered.has(node.class);
279
284
  if (needsRead && !admission.readNode(node, '/select/binding'))
280
285
  return;
281
286
  selected.set(node.id, node);
@@ -305,6 +310,7 @@ function selectNodes(rows, select, size, after, admission, properties) {
305
310
  }
306
311
  function selectEdges(rows, select, size, after, context, admission, properties) {
307
312
  const selected = new Map();
313
+ const ordered = orderedClasses(select.order, 'edge', properties);
308
314
  rows.forEach((row) => {
309
315
  const edge = boundEdge(row, select.binding, '/select/binding');
310
316
  const source = requireNode(context, edge.source, '/select/binding');
@@ -319,7 +325,7 @@ function selectEdges(rows, select, size, after, context, admission, properties)
319
325
  admission.readNode(source, '/select/binding') &&
320
326
  admission.readNode(target, '/select/binding')
321
327
  : select.kind === 'edges'
322
- ? (select.projection.edge === 'reference' ||
328
+ ? ((select.projection.edge === 'reference' && !ordered.has(edge.class)) ||
323
329
  admission.readEdge(edge, '/select/binding')) &&
324
330
  (select.projection.source === 'reference' ||
325
331
  admission.readNode(source, '/select/binding')) &&
@@ -362,12 +368,24 @@ function selectEdges(rows, select, size, after, context, admission, properties)
362
368
  const next = last === undefined ? undefined : frontierOf(last, order, 'edge', properties);
363
369
  return Object.freeze({ result, ...(next === undefined ? {} : { next }) });
364
370
  }
371
+ /** The Classes a Property order applies to, whose facts are read before they are ranked. */
372
+ function orderedClasses(order, kind, properties) {
373
+ return order === undefined
374
+ ? new Set()
375
+ : properties.close(order.property, kind, '/select/order/property');
376
+ }
365
377
  function orderingComparator(order, kind, properties) {
366
- return (left, right) => compareReferenceRank(rankOf(left, order, kind, properties), rankOf(right, order, kind, properties), order);
378
+ const ordering = orderingOf(order, kind, properties);
379
+ return (left, right) => compareReferenceRank(rankOf(left, order, kind, properties), rankOf(right, order, kind, properties), order, ordering);
380
+ }
381
+ function orderingOf(order, kind, properties) {
382
+ return order === undefined
383
+ ? undefined
384
+ : properties.ordering(order.property, kind, '/select/order/property');
367
385
  }
368
386
  function compareFrontier(frontier, fact, order, kind, properties) {
369
387
  const admitted = decodeReferenceFrontier(frontier, order, kind, properties);
370
- return compareReferenceRank(admitted, rankOf(fact, order, kind, properties), order);
388
+ return compareReferenceRank(admitted, rankOf(fact, order, kind, properties), order, orderingOf(order, kind, properties));
371
389
  }
372
390
  function frontierOf(fact, order, kind, properties) {
373
391
  const rank = rankOf(fact, order, kind, properties);
@@ -413,36 +431,8 @@ function decodeReferenceFrontier(frontier, order, kind, properties) {
413
431
  }
414
432
  return Object.freeze({ bucket: 'ranked', value: frontier.value, identity });
415
433
  }
416
- function compareReferenceRank(left, right, order) {
417
- if (order === undefined)
418
- return compareIdentity(left.identity, right.identity);
419
- if (left.bucket !== right.bucket) {
420
- return left.bucket === 'unranked'
421
- ? order.unranked === 'first'
422
- ? -1
423
- : 1
424
- : order.unranked === 'first'
425
- ? 1
426
- : -1;
427
- }
428
- if (left.bucket === 'ranked' && right.bucket === 'ranked') {
429
- const kind = typeof left.value === 'boolean'
430
- ? 'boolean'
431
- : typeof left.value === 'number'
432
- ? 'number'
433
- : 'string';
434
- const compared = compareOrderingValue(left.value, right.value, kind);
435
- if (compared !== 0)
436
- return order.direction === 'asc' ? compared : -compared;
437
- }
438
- return compareIdentity(left.identity, right.identity);
439
- }
440
- function compareIdentity(left, right) {
441
- if (typeof left === 'string' && typeof right === 'string')
442
- return compareNodeIds(left, right);
443
- if (typeof left !== 'string' && typeof right !== 'string')
444
- return compareEdgeKeys(left, right);
445
- invalid('/after/identity', 'Frontier identity kind disagrees with selection');
434
+ function compareReferenceRank(left, right, order, ordering) {
435
+ return compareQueryRank(left, right, order === undefined || ordering === undefined ? undefined : { ...order, kind: ordering });
446
436
  }
447
437
  function orderingValue(input, kind) {
448
438
  if (kind === 'boolean')
@@ -451,22 +441,6 @@ function orderingValue(input, kind) {
451
441
  return typeof input === 'number' && Number.isFinite(input);
452
442
  return typeof input === 'string';
453
443
  }
454
- function compareOrderingValue(left, right, kind) {
455
- if (kind === 'boolean')
456
- return Number(left) - Number(right);
457
- if (kind === 'number')
458
- return left - right;
459
- return compareUnicodeScalars(left, right);
460
- }
461
- function compareUnicodeScalars(left, right) {
462
- const a = Array.from(left, (value) => value.codePointAt(0));
463
- const b = Array.from(right, (value) => value.codePointAt(0));
464
- for (let index = 0; index < Math.min(a.length, b.length); index += 1) {
465
- if (a[index] !== b[index])
466
- return a[index] - b[index];
467
- }
468
- return a.length - b.length;
469
- }
470
444
  function projectNode(node, shape) {
471
445
  return shape === 'value'
472
446
  ? Object.freeze({ kind: 'value', value: node })
@@ -2,6 +2,12 @@ import { type ObservationRequirement } from '#graph/reconcile/evidence';
2
2
  import type { Effect, PlanningBlocker, PlanningConflict, Premise, ReconciliationPlan } from './model.js';
3
3
  export declare function canonicalRequirements(values: readonly ObservationRequirement[]): ObservationRequirement[];
4
4
  export declare function canonicalPremises(values: readonly Premise[]): Premise[];
5
+ /**
6
+ * Distinct desired refs can name one target: an explicit NodeId and a binding whose
7
+ * correspondence observes that Node. Effects with one key and equal content collapse; effects with
8
+ * one key and different content contradict the desired state, which no transition can establish.
9
+ */
10
+ export declare function contradictoryEffects(values: readonly Effect[]): PlanningConflict[];
5
11
  export declare function canonicalEffects(values: readonly Effect[]): Effect[];
6
12
  export declare function canonicalConflicts(values: readonly PlanningConflict[]): PlanningConflict[];
7
13
  export declare function canonicalBlockers(values: readonly PlanningBlocker[]): PlanningBlocker[];
@@ -1,3 +1,4 @@
1
+ import * as portable from '@astrale-os/kernel-dsl/value';
1
2
  import { freezeRequirement, requirementKey, } from '#graph/reconcile/evidence';
2
3
  import { encodeEdgeKey } from '../../edge/index.js';
3
4
  export function canonicalRequirements(values) {
@@ -8,6 +9,30 @@ export function canonicalRequirements(values) {
8
9
  export function canonicalPremises(values) {
9
10
  return [...new Map(values.map((value) => [premiseKey(value), value])).values()].sort(comparePremises);
10
11
  }
12
+ /**
13
+ * Distinct desired refs can name one target: an explicit NodeId and a binding whose
14
+ * correspondence observes that Node. Effects with one key and equal content collapse; effects with
15
+ * one key and different content contradict the desired state, which no transition can establish.
16
+ */
17
+ export function contradictoryEffects(values) {
18
+ const groups = new Map();
19
+ for (const value of values) {
20
+ const key = effectKey(value);
21
+ const group = groups.get(key) ?? new Map();
22
+ group.set(portable.json.serialize(value), value);
23
+ groups.set(key, group);
24
+ }
25
+ const conflicts = [];
26
+ for (const group of groups.values()) {
27
+ if (group.size < 2)
28
+ continue;
29
+ conflicts.push({
30
+ kind: 'desired-target-contradictory',
31
+ effects: [...group].sort(([left], [right]) => compare(left, right)).map(([, value]) => value),
32
+ });
33
+ }
34
+ return conflicts;
35
+ }
11
36
  export function canonicalEffects(values) {
12
37
  return [...new Map(values.map((value) => [effectKey(value), value])).values()].sort(compareEffects);
13
38
  }
@@ -66,6 +91,9 @@ function freezeConflict(value) {
66
91
  if (value.kind === 'correspondence-noninjective') {
67
92
  return Object.freeze({ ...value, desired: Object.freeze([...value.desired]) });
68
93
  }
94
+ if (value.kind === 'desired-target-contradictory') {
95
+ return Object.freeze({ ...value, effects: Object.freeze([...value.effects]) });
96
+ }
69
97
  return Object.freeze({ ...value });
70
98
  }
71
99
  function compare(left, right) {
@@ -72,6 +72,10 @@ export type PlanningConflict = ReconcileConflict | CorrespondenceConflict | Obse
72
72
  } | {
73
73
  readonly kind: 'node-identity-absent';
74
74
  readonly node: NodeId;
75
+ } | {
76
+ /** One effect target reached through aliasing refs with different desired content. */
77
+ readonly kind: 'desired-target-contradictory';
78
+ readonly effects: readonly Effect[];
75
79
  };
76
80
  export type PlanningBlocker = {
77
81
  readonly kind: 'selection-unsatisfied';
@@ -1,5 +1,5 @@
1
1
  import { fingerprint } from '../condition/index.js';
2
- import { canonicalBlockers, canonicalConflicts, canonicalEffects, canonicalPremises, canonicalRequirements, createPlan, } from './canonical.js';
2
+ import { canonicalBlockers, canonicalConflicts, canonicalEffects, canonicalPremises, canonicalRequirements, contradictoryEffects, createPlan, } from './canonical.js';
3
3
  import { createPlanningContext } from './context.js';
4
4
  import { planEdge } from './edge.js';
5
5
  import { planNode } from './node.js';
@@ -13,6 +13,7 @@ export function plan(input) {
13
13
  planEdge(edge, context);
14
14
  for (const selection of input.desired.selections)
15
15
  planSelection(selection, context);
16
+ context.conflicts.push(...contradictoryEffects(context.effects));
16
17
  if (context.conflicts.length > 0) {
17
18
  return Object.freeze({
18
19
  kind: 'conflict',
@@ -0,0 +1,3 @@
1
+ import type { authority } from '../../auth/index.js';
2
+ /** The Kernel instance of the authority vocabulary; Core Auth interprets authority through it. */
3
+ export declare const authorityVocabulary: authority.AuthorityVocabulary;
@@ -0,0 +1,25 @@
1
+ import { K } from '../kernel/schema.js';
2
+ /** The Kernel instance of the authority vocabulary; Core Auth interprets authority through it. */
3
+ export const authorityVocabulary = Object.freeze({
4
+ identity: ref(K.classes.Identity.ref),
5
+ composition: Object.freeze({
6
+ extension: ref(K.classes.extends_with.ref),
7
+ constraint: ref(K.classes.constrained_by.ref),
8
+ exclusion: ref(K.classes.excluded_from.ref),
9
+ }),
10
+ capabilities: Object.freeze({
11
+ create: ref(K.classes.can_create.ref),
12
+ read: ref(K.classes.can_read.ref),
13
+ traverse: ref(K.classes.can_traverse.ref),
14
+ update: ref(K.classes.can_update.ref),
15
+ delete: ref(K.classes.can_delete.ref),
16
+ }),
17
+ instanceOf: ref(K.classes.instance_of.ref),
18
+ });
19
+ function ref(value) {
20
+ return Object.freeze({
21
+ origin: value.origin,
22
+ kind: 'class',
23
+ name: value.name,
24
+ });
25
+ }