@astrale-os/kernel-client 1.0.0-beta.11 → 1.0.0-beta.13

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.
@@ -1,31 +1,29 @@
1
- import { ClassKey } from '@astrale-os/kernel-dsl/v1/addressing';
2
1
  import { isDomain } from '@astrale-os/kernel-dsl/v1/domain';
3
2
  import { provenanceOfGraphValue, provenanceOfResponse } from '../provenance.js';
3
+ import { definedClass, validateDefinedProperties } from './conformance.js';
4
4
  import { selectedEdges, selectedNodes } from './page.js';
5
5
  import { projectEdge, projectNode } from './project.js';
6
- import { provenanceOfProjectedValue, sameClosure } from './provenance.js';
6
+ import { provenanceOfProjectedValue } from './provenance.js';
7
7
  export function createDomainBinding(domain, graph, call) {
8
8
  if (!isDomain(domain))
9
9
  throw new TypeError('Domain binding requires an admitted DSL Domain.');
10
10
  const wrapNode = (selected, node) => {
11
11
  requireOwnedClass(domain, selected);
12
- const provenance = requireProvenance(domain, node);
12
+ const provenance = requireProvenance(node);
13
13
  const exact = requireExactClass(domain, node.class, 'node');
14
14
  if (!exact.satisfies(selected))
15
15
  throw new TypeError(`${exact.key} does not satisfy ${selected.key}.`);
16
- const diagnostics = exact.validateProperties(node.props);
17
- if (diagnostics.length > 0)
16
+ if (validateDefinedProperties(exact, node.props).length > 0)
18
17
  throw new TypeError(`Node ${node.id} has invalid exact Properties.`);
19
18
  return projectNode(selected, node, provenance, call);
20
19
  };
21
20
  const wrapEdge = (selected, edge) => {
22
21
  requireOwnedClass(domain, selected);
23
- const provenance = requireProvenance(domain, edge);
22
+ const provenance = requireProvenance(edge);
24
23
  const exact = requireExactClass(domain, edge.class, 'edge');
25
24
  if (!exact.satisfies(selected))
26
25
  throw new TypeError(`${exact.key} does not satisfy ${selected.key}.`);
27
- const diagnostics = exact.validateProperties(edge.props);
28
- if (diagnostics.length > 0)
26
+ if (validateDefinedProperties(exact, edge.props).length > 0)
29
27
  throw new TypeError('Edge has invalid exact Properties.');
30
28
  return projectEdge(selected, edge, provenance);
31
29
  };
@@ -34,13 +32,14 @@ export function createDomainBinding(domain, graph, call) {
34
32
  graph,
35
33
  async query(query, options) {
36
34
  const selected = selectedSourceClass(domain, query);
37
- const response = await graph.query(query, { ...options, expected: domain.closure });
35
+ // The Kernel answers in its active Schema; projection checks each value against `domain`.
36
+ const response = await graph.query(query, options);
38
37
  // A repair-session read may hold facts the bound Domain refutes: it is never typed by it.
39
38
  if (response.certification === 'uncertified') {
40
39
  throw new TypeError('An uncertified Query response cannot be bound to its Domain.');
41
40
  }
42
41
  const provenance = provenanceOfResponse(response);
43
- if (provenance === undefined || !sameClosure(provenance.closure, domain.closure)) {
42
+ if (provenance === undefined) {
44
43
  throw new TypeError('Authenticated query provenance was not retained.');
45
44
  }
46
45
  const next = response.page.next === undefined
@@ -50,7 +49,9 @@ export function createDomainBinding(domain, graph, call) {
50
49
  page: { ...options.page, after: response.page.next },
51
50
  });
52
51
  if (selected.kind === 'node') {
53
- const nodes = selectedNodes(response).map((node) => wrapNode(selected, node));
52
+ const nodes = selectedNodes(response)
53
+ .filter((node) => definedClass(domain, node.class) !== undefined)
54
+ .map((node) => wrapNode(selected, node));
54
55
  return Object.freeze({
55
56
  nodes: Object.freeze(nodes),
56
57
  raw: response,
@@ -58,7 +59,9 @@ export function createDomainBinding(domain, graph, call) {
58
59
  refine: (value, target) => refineNode(domain, call, value, target, provenance),
59
60
  });
60
61
  }
61
- const edges = selectedEdges(response).map((edge) => wrapEdge(selected, edge));
62
+ const edges = selectedEdges(response)
63
+ .filter((edge) => definedClass(domain, edge.class) !== undefined)
64
+ .map((edge) => wrapEdge(selected, edge));
62
65
  return Object.freeze({
63
66
  edges: Object.freeze(edges),
64
67
  raw: response,
@@ -111,16 +114,16 @@ function requireOwnedClass(domain, selected) {
111
114
  throw new TypeError('Selected Class does not belong to the bound Domain closure.');
112
115
  }
113
116
  }
114
- function requireProvenance(domain, value) {
117
+ function requireProvenance(value) {
115
118
  const provenance = provenanceOfGraphValue(value);
116
- if (provenance === undefined || !sameClosure(provenance.closure, domain.closure)) {
117
- throw new TypeError('Graph value lacks matching authenticated query provenance.');
119
+ if (provenance === undefined) {
120
+ throw new TypeError('Graph value lacks authenticated query provenance.');
118
121
  }
119
122
  return provenance;
120
123
  }
121
124
  function requireExactClass(domain, key, kind) {
122
- const exact = domain.definition(ClassKey.ref(ClassKey(key)));
123
- if (exact?.ref.kind !== 'class' || exact.kind !== kind || exact.abstract) {
125
+ const exact = definedClass(domain, key);
126
+ if (exact?.kind !== kind || exact.abstract) {
124
127
  throw new TypeError(`Exact ${kind} Class ${key} is not active and concrete.`);
125
128
  }
126
129
  return exact;
@@ -0,0 +1,12 @@
1
+ import type { Domain } from '@astrale-os/kernel-dsl/v1/domain';
2
+ import type { AnyResolvedClass, Diagnostic } from '@astrale-os/kernel-dsl/v1/language';
3
+ /**
4
+ * The Class `domain` defines under `key`, or `undefined` when that Class was added after `domain`
5
+ * was built. The Kernel answers in its active Schema, so a result may hold values of such a Class.
6
+ */
7
+ export declare function definedClass(domain: Domain, key: string): AnyResolvedClass | undefined;
8
+ /**
9
+ * What in `props` breaks `exact`: a Property it defines holding an invalid value, or a required one
10
+ * absent. A Property `exact` does not define passes: the active Schema may add it.
11
+ */
12
+ export declare function validateDefinedProperties(exact: AnyResolvedClass, props: unknown): readonly Diagnostic[];
@@ -0,0 +1,18 @@
1
+ import { ClassKey } from '@astrale-os/kernel-dsl/v1/addressing';
2
+ /**
3
+ * The Class `domain` defines under `key`, or `undefined` when that Class was added after `domain`
4
+ * was built. The Kernel answers in its active Schema, so a result may hold values of such a Class.
5
+ */
6
+ export function definedClass(domain, key) {
7
+ const definition = domain.definition(ClassKey.ref(ClassKey(key)));
8
+ return definition?.ref.kind === 'class' ? definition : undefined;
9
+ }
10
+ /**
11
+ * What in `props` breaks `exact`: a Property it defines holding an invalid value, or a required one
12
+ * absent. A Property `exact` does not define passes: the active Schema may add it.
13
+ */
14
+ export function validateDefinedProperties(exact, props) {
15
+ return exact
16
+ .validateProperties(props)
17
+ .filter((diagnostic) => diagnostic.code !== 'DOMAIN_PROPERTY_UNKNOWN');
18
+ }
@@ -1,3 +1,4 @@
1
1
  export type { DomainBinding, DomainQueryOptions } from './binding.js';
2
+ export { definedClass, validateDefinedProperties } from './conformance.js';
2
3
  export type { BoundEdge, BoundGraphValue, BoundNode, BoundNodeFor } from './model.js';
3
4
  export type { BoundEdgePage, BoundNodePage, BoundQueryPage } from './page.js';
@@ -1 +1 @@
1
- export {};
1
+ export { definedClass, validateDefinedProperties } from './conformance.js';
@@ -1,6 +1,4 @@
1
- import type { Domain } from '@astrale-os/kernel-dsl/v1/domain';
2
1
  import type { QueryProvenance } from '../provenance.js';
3
2
  export declare function retainProjectedProvenance(value: object, provenance: QueryProvenance): void;
4
3
  export declare function provenanceOfProjectedValue(value: object): QueryProvenance | undefined;
5
- export declare function sameClosure(left: Domain['closure'], right: Domain['closure']): boolean;
6
4
  export type { QueryProvenance };
@@ -5,7 +5,3 @@ export function retainProjectedProvenance(value, provenance) {
5
5
  export function provenanceOfProjectedValue(value) {
6
6
  return projectedValues.get(value);
7
7
  }
8
- export function sameClosure(left, right) {
9
- return (left.length === right.length &&
10
- left.every((identity, index) => identity.origin === right[index]?.origin && identity.revision === right[index]?.revision));
11
- }
@@ -1,6 +1,6 @@
1
1
  export { createGraph, type GraphApi, type GraphCall, type GraphMutationOptions, type GraphQueryOptions, type MutationAuthor, } from './graph.js';
2
2
  export type { QueryPageRequest, QueryResponse } from './page-contract.js';
3
- export { type BoundEdge, type BoundEdgePage, type BoundGraphValue, type BoundNode, type BoundNodeFor, type BoundNodePage, type BoundQueryPage, type DomainBinding, type DomainQueryOptions, } from './domain/index.js';
3
+ export { type BoundEdge, type BoundEdgePage, type BoundGraphValue, type BoundNode, type BoundNodeFor, type BoundNodePage, type BoundQueryPage, type DomainBinding, type DomainQueryOptions, definedClass, validateDefinedProperties, } from './domain/index.js';
4
4
  export { NodeUnavailableError } from './errors.js';
5
5
  export type { NeighborsOptions, NodePage } from './page/index.js';
6
6
  export { LocalAlias, type GraphSpec } from '@astrale-os/kernel-core/graph/graph';
@@ -1,5 +1,5 @@
1
1
  export { createGraph, } from './graph.js';
2
- export {} from './domain/index.js';
2
+ export { definedClass, validateDefinedProperties, } from './domain/index.js';
3
3
  export { NodeUnavailableError } from './errors.js';
4
4
  export { LocalAlias } from '@astrale-os/kernel-core/graph/graph';
5
5
  export { MutationAST, MutationResult, } from '@astrale-os/kernel-core/graph/mutate';
@@ -1,14 +1,13 @@
1
1
  import type { Edge } from '@astrale-os/kernel-core/graph/edge';
2
2
  import type { Node } from '@astrale-os/kernel-core/graph/node';
3
- import type { DomainDependency } from '@astrale-os/kernel-dsl/v1/schema';
4
3
  import type { QueryResponse } from './page-contract.js';
4
+ /** A certified Query response this client received from the Kernel; `page` identifies it. */
5
5
  export interface QueryProvenance {
6
- readonly closure: readonly DomainDependency[];
7
6
  readonly page: object;
8
7
  }
9
- /** Retain authenticated query provenance without adding serialized response metadata. */
10
- export declare function retainQueryProvenance(response: QueryResponse, closure: readonly DomainDependency[]): QueryResponse;
11
- /** Reattach the exact authenticated closure when Store materialization replaces response objects. */
8
+ /** Retain the provenance of a certified Query response without adding serialized metadata. */
9
+ export declare function retainQueryProvenance(response: QueryResponse): QueryResponse;
10
+ /** Reattach provenance when Store materialization replaces response objects. */
12
11
  export declare function retainDerivedQueryProvenance(source: QueryResponse, derived: QueryResponse): QueryResponse;
13
12
  export declare function provenanceOfGraphValue(value: Node | Edge): QueryProvenance | undefined;
14
13
  export declare function provenanceOfResponse(value: QueryResponse): QueryProvenance | undefined;
@@ -1,8 +1,8 @@
1
1
  const graphValues = new WeakMap();
2
2
  const responses = new WeakMap();
3
- /** Retain authenticated query provenance without adding serialized response metadata. */
4
- export function retainQueryProvenance(response, closure) {
5
- const provenance = Object.freeze({ closure, page: Object.freeze({}) });
3
+ /** Retain the provenance of a certified Query response without adding serialized metadata. */
4
+ export function retainQueryProvenance(response) {
5
+ const provenance = Object.freeze({ page: Object.freeze({}) });
6
6
  responses.set(response, provenance);
7
7
  const { result } = response;
8
8
  if (result.kind === 'graph') {
@@ -29,10 +29,9 @@ export function retainQueryProvenance(response, closure) {
29
29
  }
30
30
  return response;
31
31
  }
32
- /** Reattach the exact authenticated closure when Store materialization replaces response objects. */
32
+ /** Reattach provenance when Store materialization replaces response objects. */
33
33
  export function retainDerivedQueryProvenance(source, derived) {
34
- const provenance = responses.get(source);
35
- return provenance === undefined ? derived : retainQueryProvenance(derived, provenance.closure);
34
+ return responses.has(source) ? retainQueryProvenance(derived) : derived;
36
35
  }
37
36
  export function provenanceOfGraphValue(value) {
38
37
  return graphValues.get(value);
@@ -28,9 +28,10 @@ export async function queryGraph(call, input, options) {
28
28
  page: admittedPage,
29
29
  })), request);
30
30
  const response = decodeResponse(output);
31
- return capturedExpected === undefined
32
- ? response
33
- : retainQueryProvenance(response, capturedExpected);
31
+ // A repair-session read may hold facts the Domain refutes: it carries no provenance.
32
+ return response.certification === undefined
33
+ ? retainQueryProvenance(response)
34
+ : response;
34
35
  }
35
36
  function admitPage(input) {
36
37
  if (input === null || typeof input !== 'object' || Array.isArray(input)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/kernel-client",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.13",
4
4
  "description": "Universal Client — protocol-first, transport-agnostic",
5
5
  "keywords": [
6
6
  "astrale",
@@ -65,13 +65,13 @@
65
65
  "access": "public"
66
66
  },
67
67
  "dependencies": {
68
- "@astrale-os/kernel-core": "1.0.0-beta.9",
69
- "@astrale-os/kernel-dsl": "1.0.0-beta.4",
70
- "@astrale-os/kernel-protocol": "1.0.0-beta.9",
68
+ "@astrale-os/kernel-core": "1.0.0-beta.11",
69
+ "@astrale-os/kernel-dsl": "1.0.0-beta.5",
70
+ "@astrale-os/kernel-protocol": "1.0.0-beta.11",
71
71
  "@tanstack/pacer": "0.20.1"
72
72
  },
73
73
  "devDependencies": {
74
- "@astrale-os/kernel-server": "1.0.0-beta.9",
74
+ "@astrale-os/kernel-server": "1.0.0-beta.11",
75
75
  "@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
76
76
  "@types/node": "^22.0.0",
77
77
  "typescript": "7.0.2",