@astrale-os/kernel-dsl 1.0.0-beta.20 → 1.0.0-beta.21

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.
@@ -20,7 +20,8 @@ export type { ClassRuleChecks, CreateRuleChecks, EdgeRuleChecks, } from '../lang
20
20
  export type { AuthoredPropertyProjection, AuthoredMethodProjection, ClassIdentityProjection, ClassOwnerProjection, ClassReferenceProjection, } from './class/projection.js';
21
21
  export type { PathAuthoring } from './value/path.js';
22
22
  export type { Lazy } from './schema/lazy.js';
23
- export type { EdgeRolesOf, MatchPolicyInput, Policy, PolicyBuilder as PolicyFactory, PolicyEdgeClassInput, PolicyEdgeEnds, PolicyEdgeInput, PolicyEdgeOptions, PolicyEdgeRepeat, PolicyExistsContext, PolicyInput, PolicyNodeBinder, PolicyPatternContext, } from './policy/authoring.js';
23
+ export type { EdgeRolesOf, MatchPolicyInput, Policy, PolicyBuilder as PolicyFactory, PolicyEdgeClassInput, PolicyEdgeEnds, PolicyEdgeOptions, PolicyEdgeRepeat, PolicyExistsContext, PolicyInput, PolicyNodeBinder, PolicyPatternContext, } from './policy/authoring.js';
24
+ export type { PolicyEdgeInput } from './policy/legacy/edge.js';
24
25
  export type { AutoOptions, AutoProperty, Property, PropertyFieldInput as PropertyField, PropertyOptions, ValueSchemaInput, } from './class/property.js';
25
26
  export type { CorePropertyInput } from './schema/projection.js';
26
27
  export type { ClassProjection, FunctionProjection, MethodProjection, PropertyProjection, } from './schema/projection.js';
@@ -7,16 +7,7 @@ import type { EdgeClassReferenceInput, NodeClassReferenceInput } from '../class/
7
7
  import type { AuthoringValue } from '../schema/handle.js';
8
8
  import type { Lazy } from '../schema/lazy.js';
9
9
  import type { ResolveLazy } from '../schema/projection/identity.js';
10
- /**
11
- * @deprecated Name the ends by their roles: `edge(classValue, { [role]: term }, { repeat })`
12
- * lowers to this same pattern.
13
- */
14
- export interface PolicyEdgeInput {
15
- readonly source: CanonicalPolicyPatternTerm;
16
- readonly class: EdgeClassReferenceInput;
17
- readonly target: CanonicalPolicyPatternTerm;
18
- readonly repeat?: PolicyEdgeRepeat;
19
- }
10
+ import type { PolicyEdgeInput } from './legacy/edge.js';
20
11
  /** How many Edges of the Class a path between the two terms crosses, both bounds included. */
21
12
  export interface PolicyEdgeRepeat {
22
13
  readonly min: number;
@@ -1,5 +1,6 @@
1
1
  import { assertKnownKeys, escapeToken, fail } from '../schema/diagnostic.js';
2
2
  import { authoringValue } from '../schema/handle.js';
3
+ import { acceptLegacyEdge } from './legacy/edge.js';
3
4
  const declarations = new WeakMap();
4
5
  const compositions = new WeakSet();
5
6
  export function policyDeclaration(value) {
@@ -57,8 +58,11 @@ function variableIds() {
57
58
  }
58
59
  function edge(options, args) {
59
60
  const pointer = `${options.pointer}/match/edge`;
60
- if (args[1] === undefined)
61
- return legacyEdge(options, args[0], pointer);
61
+ if (args[1] === undefined) {
62
+ const input = acceptLegacyEdge(args[0], pointer);
63
+ const ref = options.resolveEdgeClass(input.class, `${options.pointer}/match/class`);
64
+ return edgePattern(input.source, ref, input.target, input.repeat);
65
+ }
62
66
  const [classValue, ends, edgeOptions] = args;
63
67
  const ref = options.resolveEdgeClass(classValue, `${options.pointer}/match/class`);
64
68
  const [sourceRole, targetRole] = options.edgeRoles(ref);
@@ -76,18 +80,6 @@ function edge(options, args) {
76
80
  }
77
81
  return edgePattern(sourceTerm, ref, targetTerm, edgeOptions?.repeat);
78
82
  }
79
- function legacyEdge(options, input, pointer) {
80
- // Typed callers cannot pass an Edge Class without ends; untyped ones can, and `kind` is read
81
- // without `in` so a primitive still reaches `assertKnownKeys`.
82
- if (typeof input === 'function' || input.kind === 'edge') {
83
- fail('BUILDER_POLICY', pointer, 'edge(classValue, ends) names both ends by their roles.');
84
- }
85
- assertKnownKeys(input, ['source', 'class', 'target', 'repeat']);
86
- if (input.repeat !== undefined)
87
- assertKnownKeys(input.repeat, ['min', 'max']);
88
- const ref = options.resolveEdgeClass(input.class, `${options.pointer}/match/class`);
89
- return edgePattern(input.source, ref, input.target, input.repeat);
90
- }
91
83
  /** The term of one role. An own key holding `undefined` passes through, as it always has. */
92
84
  function endTerm(ends, role, pointer, missing) {
93
85
  if (!Object.hasOwn(ends, role))
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The Edge pattern a Policy named by side, `edge({ source, class, target, repeat })`, before its
3
+ * ends were keyed by the roles of the Edge Class. The canonical `edge(...)` lowers what this accepts
4
+ * as it lowers the role form.
5
+ *
6
+ * Retirement: once no supported SDK, CLI, Shell or Admin builds a Policy with
7
+ * `edge({ source, class, target })`, delete this folder, its re-export in `../../index.ts`, the
8
+ * `edge(input)` overload of `PolicyPatternContext` and the branch of `edge` in `../authoring.ts`
9
+ * that calls `acceptLegacyEdge`.
10
+ */
11
+ import type { PolicyPatternTerm } from '../../../language/policy/model/policy.js';
12
+ import type { EdgeClassReferenceInput } from '../../class/input.js';
13
+ import type { PolicyEdgeRepeat } from '../authoring.js';
14
+ /**
15
+ * @deprecated Name the ends by their roles: `edge(classValue, { [role]: term }, { repeat })`
16
+ * lowers to this same pattern.
17
+ */
18
+ export interface PolicyEdgeInput {
19
+ readonly source: PolicyPatternTerm;
20
+ readonly class: EdgeClassReferenceInput;
21
+ readonly target: PolicyPatternTerm;
22
+ readonly repeat?: PolicyEdgeRepeat;
23
+ }
24
+ /**
25
+ * @deprecated Use `edge(classValue, { [role]: term }, { repeat })`. Refuses an Edge Class passed
26
+ * without ends and a field the side form does not have.
27
+ */
28
+ export declare function acceptLegacyEdge(input: PolicyEdgeInput, pointer: string): PolicyEdgeInput;
@@ -0,0 +1,16 @@
1
+ import { assertKnownKeys, fail } from '../../schema/diagnostic.js';
2
+ /**
3
+ * @deprecated Use `edge(classValue, { [role]: term }, { repeat })`. Refuses an Edge Class passed
4
+ * without ends and a field the side form does not have.
5
+ */
6
+ export function acceptLegacyEdge(input, pointer) {
7
+ // Typed callers cannot pass an Edge Class without ends; untyped ones can, and `kind` is read
8
+ // without `in` so a primitive still reaches `assertKnownKeys`.
9
+ if (typeof input === 'function' || input.kind === 'edge') {
10
+ fail('BUILDER_POLICY', pointer, 'edge(classValue, ends) names both ends by their roles.');
11
+ }
12
+ assertKnownKeys(input, ['source', 'class', 'target', 'repeat']);
13
+ if (input.repeat !== undefined)
14
+ assertKnownKeys(input.repeat, ['min', 'max']);
15
+ return input;
16
+ }
@@ -123,7 +123,7 @@ function createDefinitions(declarations, classesByKey, input) {
123
123
  continue;
124
124
  if (isFunctionDefinition(definition)) {
125
125
  const key = Key.of(definition.ref);
126
- const inputFields = input.validation.callableFields(key);
126
+ const { fields, validateInput, validateInputField, validateOutput } = input.validation.callable(key);
127
127
  const resolved = Object.freeze({
128
128
  ref: definition.ref,
129
129
  key,
@@ -134,11 +134,11 @@ function createDefinitions(declarations, classesByKey, input) {
134
134
  ...(definition.admission === undefined ? {} : { admission: definition.admission }),
135
135
  auth: definition.auth,
136
136
  policy: definition.policy,
137
- ...(inputFields === undefined ? {} : { inputFields }),
137
+ ...(fields === undefined ? {} : { inputFields: fields }),
138
138
  definition,
139
- validateInput: (value, options) => input.validation.callableInput(key, value, options),
140
- validateInputField: (field, value) => input.validation.callableInputField(key, field, value),
141
- validateOutput: (value) => input.validation.callableOutput(key, value),
139
+ validateInput,
140
+ validateInputField,
141
+ validateOutput,
142
142
  });
143
143
  definitionsByKey.set(key, resolved);
144
144
  continue;
@@ -22,14 +22,18 @@ export interface DomainInput {
22
22
  }
23
23
  /** Already-bound validation semantics supplied by source compilation or compiled loading. */
24
24
  export interface DomainValidation {
25
- propertyExists(key: PropertyKey): boolean;
26
- property(key: PropertyKey, input: unknown): readonly Diagnostic[];
27
- /** The admitted program `property` evaluates. */
28
- propertyProgram(key: PropertyKey): ValueProgram;
29
- propertyOrdering(key: PropertyKey): OrderingKind | undefined;
30
- callableExists(key: AddressKey.Callable): boolean;
31
- callableInput(key: AddressKey.Callable, input: unknown, options?: Options): readonly Diagnostic[];
32
- callableFields(key: AddressKey.Callable): readonly string[] | undefined;
33
- callableInputField(key: AddressKey.Callable, field: string, input: unknown): readonly Diagnostic[];
34
- callableOutput(key: AddressKey.Callable, output: unknown): readonly Diagnostic[];
25
+ property(key: PropertyKey): PropertyValidation;
26
+ callable(key: AddressKey.Callable): CallableValidation;
27
+ }
28
+ export interface PropertyValidation {
29
+ readonly ordering?: OrderingKind;
30
+ validate(input: unknown): readonly Diagnostic[];
31
+ /** The admitted program `validate` evaluates. */
32
+ program(): ValueProgram;
33
+ }
34
+ export interface CallableValidation {
35
+ readonly fields?: readonly string[];
36
+ validateInput(input: unknown, options?: Options): readonly Diagnostic[];
37
+ validateInputField(field: string, input: unknown): readonly Diagnostic[];
38
+ validateOutput(output: unknown): readonly Diagnostic[];
35
39
  }
@@ -38,15 +38,15 @@ export function createClasses(definitions, validation) {
38
38
  const ownProperties = [];
39
39
  for (const [name, propertyDefinition] of Object.entries(definition.properties)) {
40
40
  const propertyKey = PropertyKeyValue.of(ref, name);
41
- const ordering = validation.propertyOrdering(propertyKey);
41
+ const { ordering, validate, program } = validation.property(propertyKey);
42
42
  const property = Object.freeze({
43
43
  owner: shell,
44
44
  name,
45
45
  key: propertyKey,
46
46
  definition: propertyDefinition,
47
47
  ...(ordering === undefined ? {} : { ordering }),
48
- validate: (input) => validation.property(propertyKey, input),
49
- program: () => validation.propertyProgram(propertyKey),
48
+ validate,
49
+ program,
50
50
  });
51
51
  ownProperties.push(property);
52
52
  effectiveProperties.set(property.key, property);
@@ -59,7 +59,7 @@ export function createClasses(definitions, validation) {
59
59
  if (definition.kind === 'node') {
60
60
  for (const [name, methodDefinition] of Object.entries(definition.methods)) {
61
61
  const methodKey = MethodKeyValue.of(ref, name);
62
- const inputFields = validation.callableFields(methodKey);
62
+ const { fields, validateInput, validateInputField, validateOutput } = validation.callable(methodKey);
63
63
  const method = Object.freeze({
64
64
  owner: shell,
65
65
  name,
@@ -78,11 +78,11 @@ export function createClasses(definitions, validation) {
78
78
  static: methodDefinition.static,
79
79
  abstract: methodDefinition.abstract,
80
80
  executable: isMethodExecutable(definition, methodDefinition),
81
- ...(inputFields === undefined ? {} : { inputFields }),
81
+ ...(fields === undefined ? {} : { inputFields: fields }),
82
82
  definition: methodDefinition,
83
- validateInput: (input, options) => validation.callableInput(methodKey, input, options),
84
- validateInputField: (field, input) => validation.callableInputField(methodKey, field, input),
85
- validateOutput: (output) => validation.callableOutput(methodKey, output),
83
+ validateInput,
84
+ validateInputField,
85
+ validateOutput,
86
86
  });
87
87
  (methodDefinition.static ? ownStaticMethods : ownInstanceMethods).push(method);
88
88
  }
@@ -1,20 +1,6 @@
1
- import type { Options } from '@astrale-os/kernel-dsl/value';
2
1
  import type { Key, PropertyKey } from '../../addressing/index.js';
3
2
  import type { Diagnostic } from '../../language/validation/diagnostic.js';
4
- import type { ValueProgram } from '../../language/value/compile/model.js';
5
- import type { OrderingKind } from '../../language/value/ordering.js';
6
- import type { DomainValidation } from '../model/input.js';
7
- export interface PropertyValidation {
8
- readonly ordering?: OrderingKind;
9
- validate(input: unknown): readonly Diagnostic[];
10
- program(): ValueProgram;
11
- }
12
- export interface CallableValidation {
13
- readonly fields?: readonly string[];
14
- validateInput(input: unknown, options?: Options): readonly Diagnostic[];
15
- validateInputField(field: string, input: unknown): readonly Diagnostic[];
16
- validateOutput(output: unknown): readonly Diagnostic[];
17
- }
3
+ import type { CallableValidation, DomainValidation, PropertyValidation } from '../model/input.js';
18
4
  /**
19
5
  * Build the one Domain-level router shared by source resolution and compiled loading. The Domain
20
6
  * built from the same entries asks only for the Properties and Callables they declare.
@@ -3,30 +3,27 @@
3
3
  * built from the same entries asks only for the Properties and Callables they declare.
4
4
  */
5
5
  export function createDomainValidation(properties, callables) {
6
- const propertyOf = (key) => {
7
- const target = properties.get(key);
8
- if (target === undefined)
9
- throw new TypeError(`Property ${key} is absent.`);
10
- return target;
11
- };
12
- const callableOf = (key) => {
13
- const target = callables.get(key);
14
- if (target === undefined)
15
- throw new TypeError(`Callable ${key} is absent.`);
16
- return target;
6
+ return Object.freeze({
7
+ property: (key) => properties.get(key) ?? absentProperty(key),
8
+ callable: (key) => callables.get(key) ?? absentCallable(key),
9
+ });
10
+ }
11
+ // An absent entry fails only when it is asked to validate, never when it is looked up.
12
+ function absentProperty(key) {
13
+ const absent = () => {
14
+ throw new TypeError(`Property ${key} is absent.`);
17
15
  };
18
- const validation = {
19
- propertyExists: (key) => properties.has(key),
20
- property: (key, input) => propertyOf(key).validate(input),
21
- propertyProgram: (key) => propertyOf(key).program(),
22
- propertyOrdering: (key) => properties.get(key)?.ordering,
23
- callableExists: (key) => callables.has(key),
24
- callableInput: (key, input, options) => callableOf(key).validateInput(input, options),
25
- callableFields: (key) => callables.get(key)?.fields,
26
- callableInputField: (key, field, input) => callableOf(key).validateInputField(field, input),
27
- callableOutput: (key, output) => callableOf(key).validateOutput(output),
16
+ return Object.freeze({ validate: absent, program: absent });
17
+ }
18
+ function absentCallable(key) {
19
+ const absent = () => {
20
+ throw new TypeError(`Callable ${key} is absent.`);
28
21
  };
29
- return Object.freeze(validation);
22
+ return Object.freeze({
23
+ validateInput: absent,
24
+ validateInputField: absent,
25
+ validateOutput: absent,
26
+ });
30
27
  }
31
28
  export function unknownInputField(field) {
32
29
  return [
@@ -1,5 +1,5 @@
1
1
  import type { ClassRef } from '../../addressing/index.js';
2
- import type { CallableValidation } from '../../domain/validation/create.js';
2
+ import type { CallableValidation } from '../../domain/model/input.js';
3
3
  import type { CallableDefinition } from '../../language/callable/model/callable.js';
4
4
  import type { DomainSchema } from '../model/schema.js';
5
5
  /** One admitted callable contract and the validators of its exact owner environment. */
@@ -1,5 +1,5 @@
1
1
  import type { SourceDomain } from '../../domain/model/domain.js';
2
- import type { CallableValidation } from '../../domain/validation/create.js';
2
+ import type { CallableValidation } from '../../domain/model/input.js';
3
3
  import type { JsonSchema } from '../../language/value/model/schema.js';
4
4
  import type { ValueSchemaRegistry } from '../../language/value/reference/registry.js';
5
5
  import type { DomainSchema } from '../model/schema.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/kernel-dsl",
3
- "version": "1.0.0-beta.20",
3
+ "version": "1.0.0-beta.21",
4
4
  "description": "Astrale Kernel DSL - Schema authoring, inference, and IR serialization",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {