@astrale-os/sdk 0.6.0-beta.55 → 0.6.0-beta.57

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 (74) hide show
  1. package/README.md +11 -10
  2. package/dist/application/index.d.ts +2 -1
  3. package/dist/application/query/execution/crossings.d.ts +6 -1
  4. package/dist/application/query/execution/crossings.js +15 -1
  5. package/dist/application/query/execution/legacy/declared-classes.d.ts +10 -0
  6. package/dist/application/query/execution/legacy/declared-classes.js +9 -0
  7. package/dist/application/requirements/canonical.d.ts +7 -0
  8. package/dist/application/requirements/canonical.js +16 -0
  9. package/dist/application/requirements/classes.d.ts +9 -7
  10. package/dist/application/requirements/classes.js +35 -42
  11. package/dist/application/requirements/functions.d.ts +3 -1
  12. package/dist/application/requirements/functions.js +12 -27
  13. package/dist/application/requirements/index.d.ts +34 -16
  14. package/dist/application/requirements/index.js +17 -20
  15. package/dist/application/requirements/legacy/authority.d.ts +21 -0
  16. package/dist/application/requirements/{authority.js → legacy/authority.js} +5 -2
  17. package/dist/application/requirements/legacy/classes.d.ts +22 -0
  18. package/dist/application/requirements/legacy/classes.js +24 -0
  19. package/dist/application/requirements/legacy/core.d.ts +30 -0
  20. package/dist/application/requirements/{core.js → legacy/core.js} +15 -13
  21. package/dist/application/requirements/legacy/functions.d.ts +7 -0
  22. package/dist/application/requirements/legacy/functions.js +15 -0
  23. package/dist/application/requirements/legacy/index.d.ts +43 -0
  24. package/dist/application/requirements/legacy/index.js +1 -0
  25. package/dist/application/requirements/legacy/requirements.d.ts +31 -0
  26. package/dist/application/requirements/legacy/requirements.js +31 -0
  27. package/dist/application/requirements/requirement.d.ts +30 -19
  28. package/dist/application/requirements/roles.d.ts +17 -0
  29. package/dist/application/requirements/roles.js +62 -0
  30. package/dist/application/requirements/scopes.d.ts +16 -0
  31. package/dist/application/requirements/scopes.js +34 -0
  32. package/dist/deployment/build/build.d.ts +3 -5
  33. package/dist/deployment/build/compile.js +12 -64
  34. package/dist/deployment/build/legacy/requirements.d.ts +11 -0
  35. package/dist/deployment/build/legacy/requirements.js +79 -0
  36. package/dist/deployment/build/material.js +0 -3
  37. package/dist/execution/invocation/dispatch/context.js +2 -1
  38. package/dist/platform/schema/class-authoring.d.ts +9 -7
  39. package/dist/platform/schema/class-authoring.js +3 -2
  40. package/dist/platform/schema/index.d.ts +1 -1
  41. package/dist/testing/query.js +2 -1
  42. package/dist/tooling/linter/adapters/typescript/discover.js +8 -2
  43. package/dist/tooling/linter/adapters/typescript/index.d.ts +6 -0
  44. package/dist/tooling/linter/adapters/typescript/index.js +1 -0
  45. package/dist/tooling/linter/adapters/typescript/legacy.d.ts +20 -0
  46. package/dist/tooling/linter/adapters/typescript/legacy.js +28 -0
  47. package/dist/tooling/linter/implementations/source/callable-requirements.d.ts +1 -2
  48. package/dist/tooling/linter/implementations/source/callable-requirements.js +7 -44
  49. package/dist/tooling/linter/implementations/source/const-initializer.d.ts +3 -0
  50. package/dist/tooling/linter/implementations/source/const-initializer.js +31 -0
  51. package/dist/tooling/linter/implementations/source/domain-requirements.d.ts +8 -0
  52. package/dist/tooling/linter/implementations/source/domain-requirements.js +35 -0
  53. package/dist/tooling/linter/implementations/source/global.js +21 -8
  54. package/dist/tooling/linter/implementations/source/legacy/requirements.d.ts +10 -0
  55. package/dist/tooling/linter/implementations/source/legacy/requirements.js +40 -0
  56. package/dist/tooling/linter/implementations/source/legacy-folders.d.ts +3 -0
  57. package/dist/tooling/linter/implementations/source/legacy-folders.js +126 -0
  58. package/dist/tooling/linter/implementations/source/mutations.js +7 -22
  59. package/dist/tooling/linter/implementations/source/requirement-entries.d.ts +24 -0
  60. package/dist/tooling/linter/implementations/source/requirement-entries.js +52 -0
  61. package/dist/tooling/linter/implementations/source/schema.d.ts +3 -0
  62. package/dist/tooling/linter/implementations/source/schema.js +9 -5
  63. package/dist/tooling/linter/implementations/source/tests.js +1 -1
  64. package/dist/tooling/linter/implementations/source/verifiers.js +2 -0
  65. package/dist/tooling/linter/policy/generated.js +2 -2
  66. package/dist/tooling/linter/requirements/registry.js +2 -0
  67. package/docs/accounts/scenarios.tsv +12 -0
  68. package/docs/handler-dependencies.md +5 -3
  69. package/docs/legacy.md +113 -0
  70. package/docs/queries.md +3 -2
  71. package/docs/requirements.md +134 -0
  72. package/package.json +4 -4
  73. package/dist/application/requirements/authority.d.ts +0 -7
  74. package/dist/application/requirements/core.d.ts +0 -14
package/README.md CHANGED
@@ -151,9 +151,9 @@ export const purge = func({
151
151
 
152
152
  A Class rule judges the caller, which passes by owning the Class's installation or by the rule,
153
153
  never by a capability it holds. When a Domain acts for a caller, the Domain must also hold its own
154
- right on the Class (the capability its requirements declare, or ownership), whatever the rule; an
154
+ right on the Class (the scope its requirements declare, or ownership), whatever the rule; an
155
155
  Identity acting for itself delegates nothing and meets no such ceiling. A callable reads the same
156
- way, with `can_use` (or ownership) as the right of its ceiling. `true` admits every Identity of the
156
+ way, with its `call` scope (or ownership) as the right of its ceiling. `true` admits every Identity of the
157
157
  instance, never an anonymous request.
158
158
 
159
159
  | Declared | Caller is admitted when |
@@ -204,15 +204,16 @@ Error declarations are not yet published in the installed Kernel Schema.
204
204
 
205
205
  ## Development
206
206
 
207
- ### Core Identity requirements
207
+ ### Requirements: Kernel Roles and scopes
208
208
 
209
- Use `requirements({ core: [{ subject, functions, classes, authority }] })` to declare capabilities
210
- for an Identity in the Domain's local Core. `subject` is the resolved Core Node; each entry
211
- must request at least one capability. The top-level `functions`, `classes`, and `authority` members
212
- describe capabilities for the Domain principal.
213
-
214
- Builds emit `requirements.capabilities.core`; the release declares those requirements for the
215
- Domain principal and local Core identities. Installation verifies the Release and its exact Bundle.
209
+ `requirements({ roles, scopes })` declares what a Domain's release needs from an instance: each
210
+ Role binding names a Role (a Core Node of the Domain or of a dependency) and the holders that are
211
+ its `members` or its `granters` (one of the Domain's Core Identities, or `requirements.domain` for
212
+ the installed Domain itself); each scope names a Class with Class operations, or a Function or
213
+ Method with `call`. Builds emit them as the release's `requirements.capabilities.roles` and
214
+ `.scopes`, which the Kernel validates against the exact dependency closure. See
215
+ [Requirements](docs/requirements.md). The previous shape (`functions`, `classes`, `authority`,
216
+ `core`) still builds unchanged and is deprecated; see [the legacy method](docs/legacy.md).
216
217
 
217
218
  ### Durable schema installations
218
219
 
@@ -1,7 +1,8 @@
1
1
  export { defineDomain, isDomainDefinition } from './define.js';
2
2
  export type { DomainDefinitionInput } from './define.js';
3
3
  export { requirements } from './requirements/index.js';
4
- export type { AuthorityRequirements, AuthorityRequirementsInput, ClassOperation, ClassRequirement, ClassRequirementInput, CoreRequirement, CoreRequirementInput, FunctionRequirementTarget, Requirements, RequirementsInput, } from './requirements/index.js';
4
+ export type { CallableScopeRequirement, CallableScopeRequirementInput, ClassOperation, ClassScopeRequirement, ClassScopeRequirementInput, ClassTarget, CoreNodeInput, DomainHolder, FunctionRequirementTarget, HolderInput, RequirementHolder, Requirements, RequirementsFunction, RequirementsInput, RoleRequirement, RoleRequirementInput, RoleRequirements, RoleRequirementsInput, ScopeRequirement, ScopeRequirementInput, } from './requirements/index.js';
5
+ export type { AuthorityRequirements, AuthorityRequirementsInput, ClassRequirement, ClassRequirementInput, CoreRequirement, CoreRequirementInput, LegacyAuthorityRequirements, LegacyAuthorityRequirementsInput, LegacyClassRequirement, LegacyClassRequirementInput, LegacyCoreRequirement, LegacyCoreRequirementInput, LegacyRequirements, LegacyRequirementsInput, } from './requirements/index.js';
5
6
  export { route, routes } from './routes/index.js';
6
7
  export type { Route, RouteInput, RouteTarget, Routes } from './routes/index.js';
7
8
  export { defineFrontend, external, vite } from './view/index.js';
@@ -1,11 +1,16 @@
1
1
  import type { ClassRef, Domain } from '../../../platform/schema/index.js';
2
2
  import type { Model } from '../handles/model.js';
3
3
  import type { ReadPlan } from '../handles/plan.js';
4
- /** A Class requirement as a build compiles it: an entry of `requirements.capabilities.classes`. */
4
+ /** A Class the Domain holds scopes on, and those scopes. */
5
5
  export interface DeclaredClass {
6
6
  readonly class: ClassRef;
7
7
  readonly operations: readonly string[];
8
8
  }
9
+ /**
10
+ * The Classes a Domain's requirements scope, authored or as a build compiled them: each Class
11
+ * scope, which bounds what the Domain reads for a caller. A scope on a callable names no Class.
12
+ */
13
+ export declare function declaredClasses(capabilities: object): readonly DeclaredClass[];
9
14
  /**
10
15
  * The S12 refusal: a `TypeError`, the same for every input and every attempt, so a durable Step
11
16
  * fails at once on it.
@@ -17,6 +17,20 @@
17
17
  * written, so an empty list the input gives refuses what any other list does.
18
18
  */
19
19
  import { Key } from '@astrale-os/kernel-dsl/v1/addressing';
20
+ import { isLegacyCapabilities } from '@astrale-os/kernel-protocol/release';
21
+ import { legacyDeclaredClasses } from './legacy/declared-classes.js';
22
+ /**
23
+ * The Classes a Domain's requirements scope, authored or as a build compiled them: each Class
24
+ * scope, which bounds what the Domain reads for a caller. A scope on a callable names no Class.
25
+ */
26
+ export function declaredClasses(capabilities) {
27
+ // The one seam to the legacy shape: a key only that shape declares selects it.
28
+ if (isLegacyCapabilities(capabilities)) {
29
+ return legacyDeclaredClasses(capabilities);
30
+ }
31
+ const { scopes = [] } = capabilities;
32
+ return Object.freeze(scopes.flatMap(({ on, operations }) => typeof on === 'string' ? [] : [Object.freeze({ class: on, operations })]));
33
+ }
20
34
  /**
21
35
  * The Kernel's origin. Its Classes need nothing, even when the Domain declares it a dependency, but
22
36
  * the dependency Classes under an abstract one (`Identity`, `Node`) each do.
@@ -165,7 +179,7 @@ export class Crossings {
165
179
  'read',
166
180
  ];
167
181
  throw new UndeclaredCrossing(query, `Query ${query}: ${relation} ${what}, a Class of the dependency ${alias} whose ${why}. ` +
168
- `Its requirements need { class: ${c.key}, operations: ['${operation}'] } in classes.`);
182
+ `Its requirements need the scope { on: ${c.key}, operations: ['${operation}'] }.`);
169
183
  }
170
184
  /**
171
185
  * Whether a read for the caller may `operation` a Class as the Domain's own read may: its rule
@@ -0,0 +1,10 @@
1
+ import type { DeclaredClass } from '../crossings.js';
2
+ /**
3
+ * @deprecated The legacy `classes` requirements as the Classes a Query may cross (L-SDK-3).
4
+ * Replaced by the Class scopes `declaredClasses` reads. Removal: in the SDK major that adopts a
5
+ * Kernel cohort no longer admitting the legacy capability shape (Kernel
6
+ * `LegacyCapabilityRequirements`, A1e).
7
+ */
8
+ export declare function legacyDeclaredClasses(capabilities: {
9
+ readonly classes?: readonly DeclaredClass[];
10
+ }): readonly DeclaredClass[];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @deprecated The legacy `classes` requirements as the Classes a Query may cross (L-SDK-3).
3
+ * Replaced by the Class scopes `declaredClasses` reads. Removal: in the SDK major that adopts a
4
+ * Kernel cohort no longer admitting the legacy capability shape (Kernel
5
+ * `LegacyCapabilityRequirements`, A1e).
6
+ */
7
+ export function legacyDeclaredClasses(capabilities) {
8
+ return capabilities.classes ?? [];
9
+ }
@@ -0,0 +1,7 @@
1
+ /** Throw unless every value is distinct: requirements are canonical sets. */
2
+ export declare function unique(values: readonly string[], label: string): void;
3
+ /** Compare two strings in code-unit order, the order the Kernel admits requirements in. */
4
+ export declare function compare(left: string, right: string): number;
5
+ /** A frozen copy of the values, sorted by their key in code-unit order. */
6
+ export declare function sortedBy<Value>(values: readonly Value[], key: (value: Value) => string): readonly Value[];
7
+ export declare function isRecord(input: unknown): input is Readonly<Record<PropertyKey, unknown>>;
@@ -0,0 +1,16 @@
1
+ /** Throw unless every value is distinct: requirements are canonical sets. */
2
+ export function unique(values, label) {
3
+ if (new Set(values).size !== values.length)
4
+ throw new TypeError(`${label}s must be unique.`);
5
+ }
6
+ /** Compare two strings in code-unit order, the order the Kernel admits requirements in. */
7
+ export function compare(left, right) {
8
+ return left < right ? -1 : left > right ? 1 : 0;
9
+ }
10
+ /** A frozen copy of the values, sorted by their key in code-unit order. */
11
+ export function sortedBy(values, key) {
12
+ return Object.freeze([...values].sort((left, right) => compare(key(left), key(right))));
13
+ }
14
+ export function isRecord(input) {
15
+ return input !== null && typeof input === 'object' && !Array.isArray(input);
16
+ }
@@ -1,9 +1,11 @@
1
- import type { AnyResolvedClass } from '../../platform/schema/index.js';
2
- import type { ClassRequirement } from './requirement.js';
1
+ import type { AnyResolvedClass, ClassRef } from '../../platform/schema/index.js';
3
2
  export declare const ClassOperationOrder: readonly ["create", "read", "traverse", "update", "delete"];
4
3
  export type ClassOperation = (typeof ClassOperationOrder)[number];
5
- export interface ClassRequirementInput {
6
- readonly class: Pick<AnyResolvedClass, 'ref'>;
7
- readonly operations: readonly [ClassOperation, ...ClassOperation[]];
8
- }
9
- export declare function captureClasses(input: readonly ClassRequirementInput[] | undefined): readonly ClassRequirement[];
4
+ /** A Class a requirement names: a resolved Class, or its reference. */
5
+ export type ClassTarget = Pick<AnyResolvedClass, 'ref'> | ClassRef;
6
+ /** Accept the reference of a resolved Class (`{ ref }`) or a Class reference itself. */
7
+ export declare function captureClassRef(input: unknown, message: string): ClassRef;
8
+ /** Whether the input names a Class, resolved or by reference. */
9
+ export declare function namesClass(input: unknown): boolean;
10
+ /** Capture a non-empty set of Class operations in their canonical order. */
11
+ export declare function captureClassOperations(input: unknown, label: string): readonly [ClassOperation, ...ClassOperation[]];
@@ -1,4 +1,5 @@
1
- import { acceptDefinitionRef, Key } from '../../platform/schema/index.js';
1
+ import { acceptDefinitionRef } from '../../platform/schema/index.js';
2
+ import { isRecord, unique } from './canonical.js';
2
3
  export const ClassOperationOrder = Object.freeze([
3
4
  'create',
4
5
  'read',
@@ -6,47 +7,39 @@ export const ClassOperationOrder = Object.freeze([
6
7
  'update',
7
8
  'delete',
8
9
  ]);
9
- export function captureClasses(input) {
10
- if (input === undefined)
11
- return Object.freeze([]);
12
- if (!Array.isArray(input))
13
- throw new TypeError('Requirement classes must be an array.');
14
- const classes = input.map((entry) => {
15
- if (entry === null || typeof entry !== 'object' || !Array.isArray(entry.operations)) {
16
- throw new TypeError('Class requirement is invalid.');
17
- }
18
- let ref;
19
- try {
20
- const admitted = acceptDefinitionRef(entry.class?.ref);
21
- if (admitted.kind !== 'class')
22
- throw new TypeError('Expected Class reference.');
23
- ref = admitted;
24
- }
25
- catch (cause) {
26
- throw new TypeError('Class requirement target is invalid.', { cause });
27
- }
28
- if (entry.operations.length === 0) {
29
- throw new TypeError('Class requirement operations cannot be empty.');
30
- }
31
- const operations = entry.operations.map((operation) => {
32
- if (!ClassOperationOrder.includes(operation)) {
33
- throw new TypeError(`Unknown Class requirement operation ${String(operation)}.`);
34
- }
35
- return operation;
36
- });
37
- unique(operations, 'Class requirement operation');
38
- return Object.freeze({
39
- class: ref,
40
- operations: Object.freeze([...operations].sort((left, right) => ClassOperationOrder.indexOf(left) - ClassOperationOrder.indexOf(right))),
41
- });
42
- });
43
- unique(classes.map((entry) => Key.of(entry.class)), 'Class requirement');
44
- return Object.freeze([...classes].sort((left, right) => compare(Key.of(left.class), Key.of(right.class))));
10
+ /** Accept the reference of a resolved Class (`{ ref }`) or a Class reference itself. */
11
+ export function captureClassRef(input, message) {
12
+ try {
13
+ const admitted = acceptDefinitionRef(isRecord(input) && 'ref' in input ? input.ref : input);
14
+ if (admitted.kind !== 'class')
15
+ throw new TypeError('Expected Class reference.');
16
+ return admitted;
17
+ }
18
+ catch (cause) {
19
+ throw new TypeError(message, { cause });
20
+ }
45
21
  }
46
- function unique(values, label) {
47
- if (new Set(values).size !== values.length)
48
- throw new TypeError(`${label}s must be unique.`);
22
+ /** Whether the input names a Class, resolved or by reference. */
23
+ export function namesClass(input) {
24
+ try {
25
+ return (acceptDefinitionRef(isRecord(input) && 'ref' in input ? input.ref : input).kind === 'class');
26
+ }
27
+ catch {
28
+ return false;
29
+ }
49
30
  }
50
- function compare(left, right) {
51
- return left < right ? -1 : left > right ? 1 : 0;
31
+ /** Capture a non-empty set of Class operations in their canonical order. */
32
+ export function captureClassOperations(input, label) {
33
+ if (!Array.isArray(input))
34
+ throw new TypeError(`${label}s must be an array.`);
35
+ if (input.length === 0)
36
+ throw new TypeError(`${label}s cannot be empty.`);
37
+ for (const operation of input) {
38
+ if (!ClassOperationOrder.includes(operation)) {
39
+ throw new TypeError(`Unknown ${label} ${String(operation)}.`);
40
+ }
41
+ }
42
+ const operations = input;
43
+ unique(operations, label);
44
+ return Object.freeze([...operations].sort((left, right) => ClassOperationOrder.indexOf(left) - ClassOperationOrder.indexOf(right)));
52
45
  }
@@ -1,4 +1,6 @@
1
1
  import type { ResolvedFunction, ResolvedMethod } from '../../platform/schema/index.js';
2
2
  import type { Key as SemanticKey } from '../../platform/schema/index.js';
3
+ /** A Function or Method a requirement names, by its resolved definition. */
3
4
  export type FunctionRequirementTarget = Pick<ResolvedFunction, 'key'> | Pick<ResolvedMethod, 'key'>;
4
- export declare function captureFunctions(input: readonly FunctionRequirementTarget[] | undefined): readonly SemanticKey.Callable[];
5
+ /** Accept the exact Key of one Function or Method. */
6
+ export declare function captureCallable(input: unknown, message: string): SemanticKey.Callable;
@@ -1,30 +1,15 @@
1
1
  import { callableAddress, Key } from '../../platform/schema/index.js';
2
- export function captureFunctions(input) {
3
- if (input === undefined)
4
- return Object.freeze([]);
5
- if (!Array.isArray(input))
6
- throw new TypeError('Requirement functions must be an array.');
7
- const keys = input.map((target) => {
8
- if (target === null || typeof target !== 'object' || typeof target.key !== 'string') {
9
- throw new TypeError('Function requirement target is invalid.');
10
- }
11
- let key;
12
- try {
13
- key = Key(target.key);
14
- callableAddress(key);
15
- }
16
- catch (cause) {
17
- throw new TypeError('Function requirement target is invalid.', { cause });
18
- }
2
+ import { isRecord } from './canonical.js';
3
+ /** Accept the exact Key of one Function or Method. */
4
+ export function captureCallable(input, message) {
5
+ if (!isRecord(input) || typeof input.key !== 'string')
6
+ throw new TypeError(message);
7
+ try {
8
+ const key = Key(input.key);
9
+ callableAddress(key);
19
10
  return key;
20
- });
21
- unique(keys, 'Function requirement');
22
- return Object.freeze([...keys].sort(compare));
23
- }
24
- function unique(values, label) {
25
- if (new Set(values).size !== values.length)
26
- throw new TypeError(`${label}s must be unique.`);
27
- }
28
- function compare(left, right) {
29
- return left < right ? -1 : left > right ? 1 : 0;
11
+ }
12
+ catch (cause) {
13
+ throw new TypeError(message, { cause });
14
+ }
30
15
  }
@@ -1,19 +1,37 @@
1
- import type { AuthorityRequirementsInput } from './authority.js';
2
- import type { ClassRequirementInput } from './classes.js';
3
- import type { CoreRequirementInput } from './core.js';
4
- import type { FunctionRequirementTarget } from './functions.js';
5
- import type { Requirements } from './requirement.js';
6
- export type { AuthorityRequirements, CoreRequirement, ClassRequirement, Requirements, } from './requirement.js';
7
- export { ClassOperationOrder, type ClassOperation, type ClassRequirementInput } from './classes.js';
1
+ import type { LegacyRequirements, LegacyRequirementsInput } from './legacy/index.js';
2
+ import type { DomainHolder, RoleRequirements } from './requirement.js';
3
+ import type { RoleRequirementInput } from './roles.js';
4
+ import type { ScopeRequirementInput } from './scopes.js';
5
+ export type { CallableScopeRequirement, ClassScopeRequirement, DomainHolder, RequirementHolder, RoleRequirement, RoleRequirements, ScopeRequirement, } from './requirement.js';
6
+ export { ClassOperationOrder, type ClassOperation, type ClassTarget } from './classes.js';
8
7
  export type { FunctionRequirementTarget } from './functions.js';
9
- export type { AuthorityRequirementsInput } from './authority.js';
10
- export type { CoreRequirementInput } from './core.js';
11
- export interface RequirementsInput {
12
- readonly functions?: readonly FunctionRequirementTarget[];
13
- readonly classes?: readonly ClassRequirementInput[];
14
- readonly authority?: AuthorityRequirementsInput;
15
- readonly core?: readonly CoreRequirementInput[];
8
+ export type { CoreNodeInput, HolderInput, RoleRequirementInput } from './roles.js';
9
+ export type { CallableScopeRequirementInput, ClassScopeRequirementInput, ScopeRequirementInput, } from './scopes.js';
10
+ export type { AuthorityRequirements, AuthorityRequirementsInput, ClassRequirement, ClassRequirementInput, CoreRequirement, CoreRequirementInput, LegacyAuthorityRequirements, LegacyAuthorityRequirementsInput, LegacyClassRequirement, LegacyClassRequirementInput, LegacyCoreRequirement, LegacyCoreRequirementInput, LegacyRequirements, LegacyRequirementsInput, } from './legacy/index.js';
11
+ /** The Kernel Roles a release binds and the scopes its installed Domain holds. */
12
+ export interface RoleRequirementsInput {
13
+ readonly roles?: readonly RoleRequirementInput[];
14
+ readonly scopes?: readonly ScopeRequirementInput[];
16
15
  }
17
- /** Capture canonical dependency requirements; Build proves the pinned dependency closure. */
18
- export declare function requirements(input?: RequirementsInput): Requirements;
16
+ /** Everything `requirements` accepts: Roles and scopes, or the legacy shape (L-SDK-1). */
17
+ export type RequirementsInput = RoleRequirementsInput | LegacyRequirementsInput;
18
+ /** A captured requirement set: Roles and scopes, or the legacy shape (L-SDK-1). */
19
+ export type Requirements = RoleRequirements | LegacyRequirements;
20
+ export interface RequirementsFunction {
21
+ /**
22
+ * Capture the Kernel Roles and scopes a Domain release requires, canonical and frozen. Build
23
+ * proves them against the exact dependency closure.
24
+ */
25
+ (input?: RoleRequirementsInput): RoleRequirements;
26
+ /**
27
+ * @deprecated The capability shape of a release before Kernel Roles (L-SDK-1). Replaced by
28
+ * `requirements({ roles, scopes })`. Removal: in the SDK major that adopts a Kernel cohort no
29
+ * longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
30
+ */
31
+ (input: LegacyRequirementsInput): LegacyRequirements;
32
+ /** The installed Domain as a Role member or granter: `{ kind: 'domain' }`. */
33
+ readonly domain: DomainHolder;
34
+ }
35
+ /** Capture canonical Role and scope requirements; Build proves the pinned dependency closure. */
36
+ export declare const requirements: RequirementsFunction;
19
37
  export declare function isRequirements(input: unknown): input is Requirements;
@@ -1,32 +1,29 @@
1
- import { captureAuthority } from './authority.js';
2
- import { captureClasses } from './classes.js';
3
- import { captureCore } from './core.js';
4
- import { captureFunctions } from './functions.js';
1
+ import { isLegacyCapabilities } from '@astrale-os/kernel-protocol/release';
2
+ import { legacyRequirements } from './legacy/index.js';
3
+ import { captureRoles, DOMAIN_HOLDER } from './roles.js';
4
+ import { captureScopes } from './scopes.js';
5
5
  export { ClassOperationOrder } from './classes.js';
6
6
  const admittedRequirements = new WeakSet();
7
- /** Capture canonical dependency requirements; Build proves the pinned dependency closure. */
8
- export function requirements(input = {}) {
7
+ function capture(input = {}) {
9
8
  if (input === null || typeof input !== 'object' || Array.isArray(input))
10
9
  invalid();
11
- if (Reflect.ownKeys(input).some((key) => key !== 'functions' && key !== 'classes' && key !== 'authority' && key !== 'core')) {
12
- invalid();
13
- }
14
- const functions = captureFunctions(input.functions);
15
- const classes = captureClasses(input.classes);
16
- const authority = captureAuthority(input.authority);
17
- const core = captureCore(input.core);
18
- const value = Object.freeze({
19
- functions,
20
- classes,
21
- core,
22
- ...(authority === undefined ? {} : { authority }),
23
- });
10
+ // The one seam to the legacy shape: a key only that shape declares selects it.
11
+ const value = isLegacyCapabilities(input)
12
+ ? legacyRequirements(input)
13
+ : captureRoleRequirements(input);
24
14
  admittedRequirements.add(value);
25
15
  return value;
26
16
  }
17
+ /** Capture canonical Role and scope requirements; Build proves the pinned dependency closure. */
18
+ export const requirements = Object.freeze(Object.assign(capture, { domain: DOMAIN_HOLDER }));
27
19
  export function isRequirements(input) {
28
20
  return input !== null && typeof input === 'object' && admittedRequirements.has(input);
29
21
  }
22
+ function captureRoleRequirements(input) {
23
+ if (Reflect.ownKeys(input).some((key) => key !== 'roles' && key !== 'scopes'))
24
+ invalid();
25
+ return Object.freeze({ roles: captureRoles(input.roles), scopes: captureScopes(input.scopes) });
26
+ }
30
27
  function invalid() {
31
- throw new TypeError('Requirements definition may contain only functions, classes, authority, and core.');
28
+ throw new TypeError('Requirements definition may contain only roles and scopes.');
32
29
  }
@@ -0,0 +1,21 @@
1
+ import type { AuthorityOperation } from '../../../platform/schema/index.js';
2
+ /**
3
+ * @deprecated Authority operations the installed Domain may grant or revoke, by Operation
4
+ * (L-SDK-1). Replaced by `granters` of a `RoleRequirementInput`. Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
5
+ */
6
+ export interface LegacyAuthorityRequirementsInput {
7
+ readonly grant?: readonly [AuthorityOperation, ...AuthorityOperation[]];
8
+ readonly revoke?: readonly [AuthorityOperation, ...AuthorityOperation[]];
9
+ }
10
+ /**
11
+ * @deprecated The captured grant and revoke operations (L-SDK-1). Replaced by `RoleRequirement`
12
+ * granters. Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
13
+ */
14
+ export interface LegacyAuthorityRequirements {
15
+ readonly grant?: readonly [AuthorityOperation, ...AuthorityOperation[]];
16
+ readonly revoke?: readonly [AuthorityOperation, ...AuthorityOperation[]];
17
+ }
18
+ /**
19
+ * @deprecated Capture legacy authority operations (L-SDK-1). Replaced by `captureRoles`. Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
20
+ */
21
+ export declare function legacyAuthority(input: LegacyAuthorityRequirementsInput | undefined): LegacyAuthorityRequirements | undefined;
@@ -1,5 +1,8 @@
1
- import { AuthorityOperationOrder } from '../../platform/schema/index.js';
2
- export function captureAuthority(input) {
1
+ import { AuthorityOperationOrder } from '../../../platform/schema/index.js';
2
+ /**
3
+ * @deprecated Capture legacy authority operations (L-SDK-1). Replaced by `captureRoles`. Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
4
+ */
5
+ export function legacyAuthority(input) {
3
6
  if (input === undefined)
4
7
  return undefined;
5
8
  if (input === null || typeof input !== 'object' || Array.isArray(input))
@@ -0,0 +1,22 @@
1
+ import type { AnyResolvedClass, ClassRef } from '../../../platform/schema/index.js';
2
+ import type { ClassOperation } from '../classes.js';
3
+ /**
4
+ * @deprecated Class operations the installed Domain holds on a Class, by `class` (L-SDK-1).
5
+ * Replaced by `ClassScopeRequirementInput` (`{ on, operations }` in `scopes`). Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
6
+ */
7
+ export interface LegacyClassRequirementInput {
8
+ readonly class: Pick<AnyResolvedClass, 'ref'>;
9
+ readonly operations: readonly [ClassOperation, ...ClassOperation[]];
10
+ }
11
+ /**
12
+ * @deprecated A captured legacy Class requirement (L-SDK-1). Replaced by
13
+ * `ClassScopeRequirement`. Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
14
+ */
15
+ export interface LegacyClassRequirement {
16
+ readonly class: ClassRef;
17
+ readonly operations: readonly [ClassOperation, ...ClassOperation[]];
18
+ }
19
+ /**
20
+ * @deprecated Capture legacy Class requirements (L-SDK-1). Replaced by `captureScopes`. Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
21
+ */
22
+ export declare function legacyClasses(input: readonly LegacyClassRequirementInput[] | undefined): readonly LegacyClassRequirement[];
@@ -0,0 +1,24 @@
1
+ import { Key } from '../../../platform/schema/index.js';
2
+ import { sortedBy, unique } from '../canonical.js';
3
+ import { captureClassOperations, captureClassRef } from '../classes.js';
4
+ /**
5
+ * @deprecated Capture legacy Class requirements (L-SDK-1). Replaced by `captureScopes`. Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
6
+ */
7
+ export function legacyClasses(input) {
8
+ if (input === undefined)
9
+ return Object.freeze([]);
10
+ if (!Array.isArray(input))
11
+ throw new TypeError('Requirement classes must be an array.');
12
+ const classes = input.map((entry) => {
13
+ if (entry === null || typeof entry !== 'object' || !Array.isArray(entry.operations)) {
14
+ throw new TypeError('Class requirement is invalid.');
15
+ }
16
+ const ref = captureClassRef(entry.class?.ref, 'Class requirement target is invalid.');
17
+ return Object.freeze({
18
+ class: ref,
19
+ operations: captureClassOperations(entry.operations, 'Class requirement operation'),
20
+ });
21
+ });
22
+ unique(classes.map((entry) => Key.of(entry.class)), 'Class requirement');
23
+ return sortedBy(classes, (entry) => Key.of(entry.class));
24
+ }
@@ -0,0 +1,30 @@
1
+ import type { CoreRef, Key, ResolvedCoreDefinition } from '../../../platform/schema/index.js';
2
+ import type { FunctionRequirementTarget } from '../functions.js';
3
+ import type { LegacyAuthorityRequirements, LegacyAuthorityRequirementsInput } from './authority.js';
4
+ import type { LegacyClassRequirement, LegacyClassRequirementInput } from './classes.js';
5
+ /**
6
+ * @deprecated Capabilities assigned to one installation-owned local Core Identity (L-SDK-1).
7
+ * Replaced by a `RoleRequirementInput` whose `members` name that Core Identity. Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
8
+ */
9
+ export interface LegacyCoreRequirementInput {
10
+ readonly subject: Pick<ResolvedCoreDefinition, 'ref'>;
11
+ /** Exact executable local callables or direct dependency callables; does not bypass Policies. */
12
+ readonly functions?: readonly FunctionRequirementTarget[];
13
+ readonly classes?: readonly LegacyClassRequirementInput[];
14
+ readonly authority?: LegacyAuthorityRequirementsInput;
15
+ }
16
+ /**
17
+ * @deprecated Capabilities assigned at installation to one Identity declared in the local Core
18
+ * (L-SDK-1). Replaced by `RoleRequirement`. Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
19
+ */
20
+ export interface LegacyCoreRequirement {
21
+ readonly subject: CoreRef;
22
+ readonly functions: readonly Key.Callable[];
23
+ readonly classes: readonly LegacyClassRequirement[];
24
+ readonly authority?: LegacyAuthorityRequirements;
25
+ }
26
+ /**
27
+ * @deprecated Capture legacy Core Identity requirements (L-SDK-1). Replaced by `captureRoles`.
28
+ * Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
29
+ */
30
+ export declare function legacyCore(input: readonly LegacyCoreRequirementInput[] | undefined): readonly LegacyCoreRequirement[];
@@ -1,8 +1,13 @@
1
- import { acceptDefinitionRef, Key } from '../../platform/schema/index.js';
2
- import { captureAuthority } from './authority.js';
3
- import { captureClasses } from './classes.js';
4
- import { captureFunctions } from './functions.js';
5
- export function captureCore(input) {
1
+ import { acceptDefinitionRef, Key as SemanticKey } from '../../../platform/schema/index.js';
2
+ import { sortedBy } from '../canonical.js';
3
+ import { legacyAuthority } from './authority.js';
4
+ import { legacyClasses } from './classes.js';
5
+ import { legacyFunctions } from './functions.js';
6
+ /**
7
+ * @deprecated Capture legacy Core Identity requirements (L-SDK-1). Replaced by `captureRoles`.
8
+ * Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
9
+ */
10
+ export function legacyCore(input) {
6
11
  if (input === undefined)
7
12
  return Object.freeze([]);
8
13
  if (!Array.isArray(input))
@@ -17,9 +22,9 @@ export function captureCore(input) {
17
22
  if (admitted.kind !== 'core')
18
23
  invalid();
19
24
  const subject = admitted;
20
- const functions = captureFunctions(entry.functions);
21
- const classes = captureClasses(entry.classes);
22
- const authority = captureAuthority(entry.authority);
25
+ const functions = legacyFunctions(entry.functions);
26
+ const classes = legacyClasses(entry.classes);
27
+ const authority = legacyAuthority(entry.authority);
23
28
  if (functions.length === 0 && classes.length === 0 && authority === undefined)
24
29
  invalid();
25
30
  return Object.freeze({
@@ -29,13 +34,10 @@ export function captureCore(input) {
29
34
  ...(authority === undefined ? {} : { authority }),
30
35
  });
31
36
  });
32
- if (new Set(core.map(({ subject }) => Key.of(subject))).size !== core.length)
37
+ if (new Set(core.map(({ subject }) => SemanticKey.of(subject))).size !== core.length)
33
38
  invalid();
34
- return Object.freeze([...core].sort((left, right) => compare(Key.of(left.subject), Key.of(right.subject))));
39
+ return sortedBy(core, ({ subject }) => SemanticKey.of(subject));
35
40
  }
36
41
  function invalid() {
37
42
  throw new TypeError('Core capability requirement is invalid.');
38
43
  }
39
- function compare(left, right) {
40
- return left < right ? -1 : left > right ? 1 : 0;
41
- }
@@ -0,0 +1,7 @@
1
+ import type { Key as SemanticKey } from '../../../platform/schema/index.js';
2
+ import type { FunctionRequirementTarget } from '../functions.js';
3
+ /**
4
+ * @deprecated Capture the legacy `functions` list the installed Domain may call (L-SDK-1).
5
+ * Replaced by `captureScopes` over `CallableScopeRequirementInput`. Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
6
+ */
7
+ export declare function legacyFunctions(input: readonly FunctionRequirementTarget[] | undefined): readonly SemanticKey.Callable[];
@@ -0,0 +1,15 @@
1
+ import { compare, unique } from '../canonical.js';
2
+ import { captureCallable } from '../functions.js';
3
+ /**
4
+ * @deprecated Capture the legacy `functions` list the installed Domain may call (L-SDK-1).
5
+ * Replaced by `captureScopes` over `CallableScopeRequirementInput`. Removal: in the SDK major that adopts a Kernel cohort no longer admitting the legacy capability shape (Kernel `LegacyCapabilityRequirements`, A1e).
6
+ */
7
+ export function legacyFunctions(input) {
8
+ if (input === undefined)
9
+ return Object.freeze([]);
10
+ if (!Array.isArray(input))
11
+ throw new TypeError('Requirement functions must be an array.');
12
+ const keys = input.map((target) => captureCallable(target, 'Function requirement target is invalid.'));
13
+ unique(keys, 'Function requirement');
14
+ return Object.freeze([...keys].sort(compare));
15
+ }