@astrale-os/sdk 0.6.0-beta.28 → 0.6.0-beta.29

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/README.md CHANGED
@@ -95,6 +95,66 @@ valid; the linter emits a non-failing `SCH-ICON-NEUTRAL` warning. Bare names suc
95
95
  non-canonical empty SVGs, external references, and executable SVG content are rejected during
96
96
  Schema authoring.
97
97
 
98
+ ## Read rules and caller rules
99
+
100
+ Every concrete Class authored through the SDK declares who may read it, and every executable
101
+ `authorized` callable declares who may call it. Omission is rejected by TypeScript and at the
102
+ runtime authoring boundary. A rule is a predicate on the caller: a Policy, or its constant value
103
+ `true` or `false`.
104
+
105
+ ```typescript
106
+ import { classIcon, func, nodeClass } from '@astrale-os/sdk/schema'
107
+ import { FileText, Lock } from '@astrale-os/sdk/schema/icons'
108
+ import { z } from 'zod'
109
+
110
+ export const Article = nodeClass({
111
+ icon: classIcon.lucide(FileText),
112
+ policies: { read: true },
113
+ })
114
+
115
+ export const Secret = nodeClass({
116
+ icon: classIcon.lucide(Lock),
117
+ policies: { read: false, traverse: false },
118
+ })
119
+
120
+ export const purge = func({
121
+ auth: 'authorized',
122
+ policy: false,
123
+ input: z.strictObject({}),
124
+ output: z.boolean(),
125
+ })
126
+ ```
127
+
128
+ A Class rule judges the caller, which passes by owning the Class's installation or by the rule,
129
+ never by a capability it holds. When a Domain acts for a caller, the Domain must also hold its own
130
+ right on the Class (the capability its requirements declare, or ownership), whatever the rule; an
131
+ Identity acting for itself delegates nothing and meets no such ceiling. A callable reads the same
132
+ way, except that its principal always holds its right (`can_use` or ownership). `true` admits
133
+ every Identity of the instance, never an anonymous request.
134
+
135
+ | Declared | Caller is admitted when |
136
+ | --- | --- |
137
+ | Class `read: true` | always |
138
+ | Class `read: false` | it is the owning installation |
139
+ | Class `read: aPolicy` | ownership or the Policy |
140
+ | Callable `policy: false` | it is Root or the owning installation |
141
+ | Callable `policy: true` | always |
142
+ | Callable `policy: checks` | Root, ownership, or the checks |
143
+
144
+ - `read: true` and `policy: false` are what an absent rule already meant. Writing them changes
145
+ neither the compiled Schema nor its revision.
146
+ - An excluded caller stays denied: `true` holds only for a caller whose live composition is not
147
+ denied.
148
+ - `read` governs values, `traverse` governs reachability: a Node is reachable, and its reference
149
+ selectable, when either rule admits the caller. A Class whose `read` is not `true` must
150
+ therefore declare `traverse` as well: `traverse: false` hides that its Nodes exist,
151
+ `traverse: true` keeps them reachable for every caller. Beside `read: true`, `traverse` stays
152
+ optional.
153
+ - An abstract Class declares no rule. An abstract Method declares its caller rule only where a
154
+ concrete Class executes it.
155
+ - `read: false`, `traverse: false` and `policy: true` need a Kernel that knows the two constants.
156
+ Earlier Kernels refuse such a Schema at installation.
157
+
98
158
  ## Business-error declarations
99
159
 
100
160
  Declare reusable business errors in `schema/modules/<module>/errors/` through the Schema facade:
@@ -0,0 +1,21 @@
1
+ import { func as kernelFunc, method as kernelMethod, type CallablePolicyBuilder, type FunctionInput, type Method, type MethodInput } from '@astrale-os/kernel-dsl/v1/builder';
2
+ /** Who may call an authorized callable: Policy checks, or the constant `true` or `false`. */
3
+ export type CallerRule = CallablePolicyBuilder | boolean;
4
+ /**
5
+ * An executable `authorized` callable declares its caller rule. An abstract Method is a contract
6
+ * on an abstract Class and executable on a concrete one, so its rule is settled by the Class that
7
+ * declares it.
8
+ */
9
+ export type DeclaredCallerRule<Config> = Config extends {
10
+ readonly auth: 'authorized';
11
+ } ? Config extends {
12
+ readonly abstract: true;
13
+ } ? unknown : {
14
+ readonly policy: CallerRule;
15
+ } : unknown;
16
+ /** Author a Function. An `authorized` Function declares its caller rule. */
17
+ export declare function func<const Config extends FunctionInput>(config: Config & DeclaredCallerRule<Config>): ReturnType<typeof kernelFunc<Config>>;
18
+ /** Author a Method. An executable `authorized` Method declares its caller rule. */
19
+ export declare function method<const Config extends MethodInput>(config: Config & DeclaredCallerRule<Config>): ReturnType<typeof kernelMethod<Config>>;
20
+ /** A concrete Class executes every Method it declares, abstract contracts included. */
21
+ export declare function assertNoUndeclaredCallerRule(methods: Readonly<Record<string, Method>> | undefined): void;
@@ -0,0 +1,27 @@
1
+ import { func as kernelFunc, method as kernelMethod, } from '@astrale-os/kernel-dsl/v1/builder';
2
+ /** Authorized abstract Methods authored without a caller rule, until a Class declares them. */
3
+ const undeclared = new WeakSet();
4
+ export function func(config) {
5
+ if (config.auth === 'authorized' && config.policy === undefined)
6
+ undeclaredCallerRule('Function');
7
+ return kernelFunc(config);
8
+ }
9
+ export function method(config) {
10
+ const value = kernelMethod(config);
11
+ if (config.auth === 'authorized' && config.policy === undefined) {
12
+ if (config.abstract !== true)
13
+ undeclaredCallerRule('Method');
14
+ undeclared.add(value);
15
+ }
16
+ return value;
17
+ }
18
+ /** A concrete Class executes every Method it declares, abstract contracts included. */
19
+ export function assertNoUndeclaredCallerRule(methods) {
20
+ for (const [name, value] of Object.entries(methods ?? {})) {
21
+ if (undeclared.has(value))
22
+ undeclaredCallerRule(`Method ${name}`);
23
+ }
24
+ }
25
+ function undeclaredCallerRule(subject) {
26
+ throw new TypeError(`${subject} is authorized and executable: declare its policy with Policy checks, true or false.`);
27
+ }
@@ -1,36 +1,86 @@
1
- import { nodeClass as kernelNodeClass, type DirectedEdgeClass, type DirectedEdgeInput, type NodeClass, type NodeClassInput as KernelNodeClassInput, type UndirectedEdgeClass, type UndirectedEdgeInput } from '@astrale-os/kernel-dsl/v1/builder';
1
+ import { edgeClass as kernelEdgeClass, nodeClass as kernelNodeClass, type DirectedEdgeClass, type DirectedEdgeInput, type Lazy, type NodeClass, type NodeClassInput as KernelNodeClassInput, type NodeClassPolicyInput, type Policy, type UndirectedEdgeClass, type UndirectedEdgeInput } from '@astrale-os/kernel-dsl/v1/builder';
2
2
  import { type ClassIcon } from './class-icon.js';
3
- /** SDK Node Class input: every author must make an explicit, admitted icon choice. */
3
+ /**
4
+ * SDK Node Class input: every author must make an explicit, admitted icon choice, and every
5
+ * concrete Class must declare its read rule.
6
+ */
4
7
  export type NodeClassInput = Omit<KernelNodeClassInput, 'icon'> & {
5
8
  readonly icon: ClassIcon;
6
9
  };
10
+ /** Who may read or traverse an Edge Class: a named Policy, or the constant `true` or `false`. */
11
+ export type ClassReadRule = Lazy<Policy> | boolean;
12
+ /**
13
+ * Who may read or traverse a Node Class: a named Policy, the constant `true` or `false`, or Policy
14
+ * checks over the observed Node (`self`) and fixed members (`ref(...)`), composed as the checks of
15
+ * an authorized callable.
16
+ */
17
+ export type NodeClassReadRule = NodeClassPolicyInput;
18
+ /**
19
+ * The observation rules of a concrete Class. A Node stays traversable through either rule, so a
20
+ * read rule other than `true` leaves every caller able to reach it, and to select its reference,
21
+ * until the traverse rule is declared too.
22
+ */
23
+ export type DeclaredObservation<Rule = ClassReadRule> = {
24
+ readonly read: true;
25
+ readonly traverse?: Rule;
26
+ } | {
27
+ readonly read: Exclude<Rule, true>;
28
+ readonly traverse: Rule;
29
+ };
30
+ /**
31
+ * A concrete Class declares its read rule, and its traverse rule whenever the read rule is not
32
+ * `true`. An abstract Class is never observed directly, so it declares neither.
33
+ */
34
+ export type DeclaredReadRule<Config, Rule = ClassReadRule> = Config extends {
35
+ readonly abstract: true;
36
+ } ? unknown : {
37
+ readonly policies: DeclaredObservation<Rule>;
38
+ };
7
39
  /** Preserve authored input instead of serializing expanded inheritance projections in consumers. */
8
40
  export interface AuthoredNodeClass<Config extends NodeClassInput> extends ReturnType<typeof kernelNodeClass<Config>> {
9
41
  }
42
+ type DirectedOptions = Omit<DirectedEdgeInput, 'orientation'>;
43
+ type UndirectedOptions = Omit<UndirectedEdgeInput, 'orientation'>;
44
+ /** The two states `defineClass` admits: abstract, or concrete with declared observation rules. */
45
+ type Declared<Input, Rule = ClassReadRule> = (Input & {
46
+ readonly abstract: true;
47
+ }) | (Input & {
48
+ readonly abstract: false;
49
+ } & {
50
+ readonly policies: DeclaredObservation<Rule>;
51
+ });
10
52
  type NodeInput = {
11
53
  readonly kind: 'node';
12
- readonly abstract: boolean;
13
- } & NodeClassInput;
54
+ } & Declared<NodeClassInput, NodeClassReadRule>;
14
55
  type DirectedInput = {
15
56
  readonly kind: 'edge';
16
57
  readonly orientation: 'directed';
17
- readonly abstract: boolean;
18
- } & Omit<DirectedEdgeInput, 'orientation'>;
58
+ } & Declared<DirectedOptions>;
19
59
  type UndirectedInput = {
20
60
  readonly kind: 'edge';
21
61
  readonly orientation: 'undirected';
22
- readonly abstract: boolean;
23
- } & Omit<UndirectedEdgeInput, 'orientation'>;
62
+ } & Declared<UndirectedOptions>;
24
63
  /**
25
64
  * Author a Node Class whose materialized configuration always carries an explicitly selected,
26
- * admitted SVG icon. The mapped input retains inference while expanding package-private
27
- * Config interface names into portable structure for downstream declaration emit.
65
+ * admitted SVG icon and, when concrete, a declared read rule. The mapped input retains inference
66
+ * while expanding package-private Config interface names into portable structure for downstream
67
+ * declaration emit.
28
68
  */
29
- export declare function nodeClass<const Config extends NodeClassInput>(config: Config & Record<Exclude<keyof Config, keyof NodeClassInput>, never>): AuthoredNodeClass<{
69
+ export declare function nodeClass<const Config extends NodeClassInput>(config: Config & Record<Exclude<keyof Config, keyof NodeClassInput>, never> & DeclaredReadRule<Config, NodeClassReadRule>): AuthoredNodeClass<{
30
70
  [Key in keyof Config]: Key extends 'properties' | 'methods' | 'policies' ? {
31
71
  [Member in keyof NonNullable<Config[Key]>]: NonNullable<Config[Key]>[Member];
32
72
  } | Extract<Config[Key], undefined> : Key extends 'extends' ? Config[Key] extends infer Parents extends NodeClassInput['extends'] ? Parents extends readonly unknown[] ? readonly [...Parents] : Parents : never : Config[Key];
33
73
  }>;
74
+ declare function directed<const Input extends DirectedOptions>(input: Input & Parameters<typeof kernelEdgeClass.directed<Input>>[0] & DeclaredReadRule<Input>): ReturnType<typeof kernelEdgeClass.directed<Input>>;
75
+ declare function undirected<const Input extends UndirectedOptions>(input: Input & Parameters<typeof kernelEdgeClass.undirected<Input>>[0] & DeclaredReadRule<Input>): ReturnType<typeof kernelEdgeClass.undirected<Input>>;
76
+ /**
77
+ * Author an Edge Class. A concrete Edge Class declares its read rule exactly as a Node Class
78
+ * does; the handle is the canonical DSL handle.
79
+ */
80
+ export declare const edgeClass: Readonly<{
81
+ directed: typeof directed;
82
+ undirected: typeof undirected;
83
+ }>;
34
84
  export declare function defineClass(config: NodeInput): NodeClass;
35
85
  export declare function defineClass(config: DirectedInput): DirectedEdgeClass;
36
86
  export declare function defineClass(config: UndirectedInput): UndirectedEdgeClass;
@@ -1,20 +1,53 @@
1
- import { defineClass as defineKernelClass, nodeClass as kernelNodeClass, } from '@astrale-os/kernel-dsl/v1/builder';
1
+ import { edgeClass as kernelEdgeClass, nodeClass as kernelNodeClass, } from '@astrale-os/kernel-dsl/v1/builder';
2
+ import { assertNoUndeclaredCallerRule } from './callable-authoring.js';
2
3
  import { classIcon } from './class-icon.js';
3
4
  export function nodeClass(config) {
4
5
  if (config === undefined || config.icon === undefined) {
5
6
  throw new TypeError('Node Class icon is required; use classIcon.neutral to make an explicit neutral choice.');
6
7
  }
8
+ assertDeclaredReadRule('Node', config);
9
+ if (config.abstract !== true)
10
+ assertNoUndeclaredCallerRule(config.methods);
7
11
  return kernelNodeClass({
8
12
  ...config,
9
13
  icon: classIcon.svg(config.icon),
10
14
  });
11
15
  }
16
+ function directed(input) {
17
+ assertDeclaredReadRule('Edge', input);
18
+ return kernelEdgeClass.directed(input);
19
+ }
20
+ function undirected(input) {
21
+ assertDeclaredReadRule('Edge', input);
22
+ return kernelEdgeClass.undirected(input);
23
+ }
24
+ /**
25
+ * Author an Edge Class. A concrete Edge Class declares its read rule exactly as a Node Class
26
+ * does; the handle is the canonical DSL handle.
27
+ */
28
+ export const edgeClass = Object.freeze({ directed, undirected });
12
29
  export function defineClass(config) {
13
30
  if (config.kind === 'node') {
14
31
  const { kind: _, ...input } = config;
15
32
  return nodeClass(input);
16
33
  }
17
- if (config.orientation === 'directed')
18
- return defineKernelClass(config);
19
- return defineKernelClass(config);
34
+ if (config.orientation === 'directed') {
35
+ const { kind: _, orientation: __, ...input } = config;
36
+ return edgeClass.directed(input);
37
+ }
38
+ const { kind: _, orientation: __, ...input } = config;
39
+ return edgeClass.undirected(input);
40
+ }
41
+ /** The authoring boundary restates the type contract for untyped and widened configurations. */
42
+ function assertDeclaredReadRule(kind, config) {
43
+ if (config.abstract === true)
44
+ return;
45
+ const rule = kind === 'Node' ? 'a Policy, Policy checks, true or false' : 'a Policy, true or false';
46
+ const read = config.policies?.read;
47
+ if (read === undefined) {
48
+ throw new TypeError(`${kind} Class read rule is required; declare policies.read with ${rule}.`);
49
+ }
50
+ if (read !== true && config.policies?.traverse === undefined) {
51
+ throw new TypeError(`${kind} Class traverse rule is required when its read rule is not true; declare policies.traverse with ${rule}.`);
52
+ }
20
53
  }
@@ -7,14 +7,16 @@ export type { StateProperty } from './state-property.js';
7
7
  export { property } from './property.js';
8
8
  export type { AuthoredProperty, PropertyOptions } from './property.js';
9
9
  export { patterns } from '@astrale-os/kernel-dsl/v1/addressing';
10
- export { defineClass, nodeClass } from './class-authoring.js';
11
- export type { AuthoredNodeClass, NodeClassInput } from './class-authoring.js';
10
+ export { defineClass, edgeClass, nodeClass } from './class-authoring.js';
11
+ export type { AuthoredNodeClass, ClassReadRule, DeclaredObservation, DeclaredReadRule, NodeClassReadRule, NodeClassInput, } from './class-authoring.js';
12
+ export { func, method } from './callable-authoring.js';
13
+ export type { CallerRule, DeclaredCallerRule } from './callable-authoring.js';
12
14
  export { error } from './error.js';
13
15
  export type { DeclaredErrorDefinition, DeclaredErrorFamily } from './error.js';
14
16
  export { classIcon } from './class-icon.js';
15
17
  export type { ClassIcon } from './class-icon.js';
16
18
  export type { StoredPropertyInputOf } from './property-input.js';
17
- export type { CallablePolicyBuilder, CallablePolicyContext, CallableProjection, AuthoredMethodProjection, AuthoredPropertyProjection, ClassIdentityProjection, ClassOwnerProjection, CoreEdge, CoreEndpoint, CoreNode, DefinedSchema, DirectedEdgeClass, ClassReferenceProjection, ClassProjection, FunctionProjection, EdgeClass, Function, Method, MethodProjection, Lazy, NodeClass, Policy, PolicyExistsContext, PolicyNodeBinder, PolicyPatternContext, Property, PropertyProjection, ResolvedDomainOfInput, View, } from '@astrale-os/kernel-dsl/v1/builder';
19
+ export type { CallablePolicyBuilder, CallablePolicyContext, ClassRuleBuilder, ClassRuleContext, PolicyCheckContext, CallableProjection, AuthoredMethodProjection, AuthoredPropertyProjection, ClassIdentityProjection, ClassOwnerProjection, CoreEdge, CoreEndpoint, CoreNode, DefinedSchema, DirectedEdgeClass, ClassReferenceProjection, ClassProjection, FunctionProjection, EdgeClass, Function, Method, MethodProjection, Lazy, NodeClass, Policy, PolicyExistsContext, PolicyNodeBinder, PolicyPatternContext, Property, PropertyProjection, ResolvedDomainOfInput, View, } from '@astrale-os/kernel-dsl/v1/builder';
18
20
  export type { Array, Object, Value } from '@astrale-os/kernel-dsl/value';
19
21
  export type { CallableExecution, ClassKind, DirectedEdgeContract, EdgeClassPolicies, NodeClassDefinition, PolicyCheckObject, PolicyObjectRef, PropertyFacet, PropertyImmutability, StateTopology, UndirectedEdgeContract, } from '@astrale-os/kernel-dsl/v1/language';
20
22
  export type { DomainSchema } from '@astrale-os/kernel-dsl/v1/schema';
@@ -4,7 +4,8 @@ export { defineSchema } from './schema-authoring.js';
4
4
  export { stateProperty } from './state-property.js';
5
5
  export { property } from './property.js';
6
6
  export { patterns } from '@astrale-os/kernel-dsl/v1/addressing';
7
- export { defineClass, nodeClass } from './class-authoring.js';
7
+ export { defineClass, edgeClass, nodeClass } from './class-authoring.js';
8
+ export { func, method } from './callable-authoring.js';
8
9
  export { error } from './error.js';
9
10
  export { classIcon } from './class-icon.js';
10
11
  /** Kernel-owned Schema values used by authored product Schemas and graph operations. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/sdk",
3
- "version": "0.6.0-beta.28",
3
+ "version": "0.6.0-beta.29",
4
4
  "description": "Schema-first SDK for defining, composing, and deploying Astrale domains",
5
5
  "keywords": [
6
6
  "astrale",
@@ -257,11 +257,11 @@
257
257
  "registry": "https://registry.npmjs.org/"
258
258
  },
259
259
  "dependencies": {
260
- "@astrale-os/kernel-client": "1.0.0-beta.1",
261
- "@astrale-os/kernel-core": "1.0.0-beta.1",
262
- "@astrale-os/kernel-dsl": "1.0.0-beta.1",
263
- "@astrale-os/kernel-protocol": "1.0.0-beta.1",
264
- "@astrale-os/kernel-server": "1.0.0-beta.1",
260
+ "@astrale-os/kernel-client": "1.0.0-beta.2",
261
+ "@astrale-os/kernel-core": "1.0.0-beta.2",
262
+ "@astrale-os/kernel-dsl": "1.0.0-beta.2",
263
+ "@astrale-os/kernel-protocol": "1.0.0-beta.2",
264
+ "@astrale-os/kernel-server": "1.0.0-beta.2",
265
265
  "@lucide/icons": "1.34.0",
266
266
  "@typescript/native-preview": "7.0.0-dev.20260707.2",
267
267
  "cross-spawn": "7.0.6",