@astrale-os/sdk 0.6.0-beta.35 → 0.6.0-beta.37

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 (104) hide show
  1. package/README.md +10 -0
  2. package/dist/application/action/context.d.ts +14 -11
  3. package/dist/application/action/index.d.ts +1 -1
  4. package/dist/application/dependency/invoker.d.ts +10 -4
  5. package/dist/application/integration/define.d.ts +8 -1
  6. package/dist/application/integration/index.d.ts +2 -2
  7. package/dist/application/integration/integration.d.ts +13 -1
  8. package/dist/application/integration/operation.d.ts +14 -1
  9. package/dist/application/mutation/execution/execute.js +1 -1
  10. package/dist/application/mutation/failure.d.ts +6 -0
  11. package/dist/application/mutation/failure.js +24 -18
  12. package/dist/application/query/collection/union.js +11 -4
  13. package/dist/application/query/conformance.d.ts +15 -0
  14. package/dist/application/query/conformance.js +46 -0
  15. package/dist/application/query/define.js +4 -3
  16. package/dist/application/query/execution/execute.d.ts +0 -1
  17. package/dist/application/query/execution/execute.js +7 -1
  18. package/dist/application/query/failure.d.ts +8 -0
  19. package/dist/application/query/failure.js +8 -0
  20. package/dist/application/query/index.d.ts +1 -1
  21. package/dist/application/query/index.js +1 -1
  22. package/dist/application/workflow/authoring.d.ts +1 -1
  23. package/dist/application/workflow/context.d.ts +1 -1
  24. package/dist/application/workflow/durable.d.ts +55 -20
  25. package/dist/application/workflow/index.d.ts +1 -1
  26. package/dist/execution/cache/cache.d.ts +17 -0
  27. package/dist/execution/cache/cache.js +11 -0
  28. package/dist/execution/cache/index.d.ts +2 -0
  29. package/dist/execution/cache/index.js +2 -0
  30. package/dist/execution/cache/memory.d.ts +13 -0
  31. package/dist/execution/cache/memory.js +48 -0
  32. package/dist/execution/identity/authentication.js +12 -6
  33. package/dist/execution/identity/callback.d.ts +7 -8
  34. package/dist/execution/identity/callback.js +17 -14
  35. package/dist/execution/index.d.ts +1 -0
  36. package/dist/execution/index.js +1 -0
  37. package/dist/execution/invocation/admission/age.d.ts +57 -0
  38. package/dist/execution/invocation/admission/age.js +208 -0
  39. package/dist/execution/invocation/admission/authentication.d.ts +2 -0
  40. package/dist/execution/invocation/admission/authentication.js +6 -2
  41. package/dist/execution/invocation/admission/index.d.ts +3 -2
  42. package/dist/execution/invocation/admission/index.js +3 -2
  43. package/dist/execution/invocation/admission/target.d.ts +11 -0
  44. package/dist/execution/invocation/admission/target.js +22 -3
  45. package/dist/execution/invocation/capabilities/bind.d.ts +11 -0
  46. package/dist/execution/invocation/capabilities/bind.js +25 -0
  47. package/dist/execution/invocation/capabilities/index.d.ts +1 -0
  48. package/dist/execution/invocation/capabilities/index.js +1 -0
  49. package/dist/execution/invocation/dispatch/context.js +2 -21
  50. package/dist/execution/invocation/handler.js +8 -2
  51. package/dist/execution/invocation/integration/authentication.d.ts +3 -3
  52. package/dist/execution/invocation/integration/authentication.js +7 -7
  53. package/dist/execution/invocation/integration/call.js +2 -2
  54. package/dist/execution/invocation/integration/index.d.ts +1 -0
  55. package/dist/execution/invocation/integration/index.js +1 -0
  56. package/dist/execution/invocation/invocation.d.ts +6 -0
  57. package/dist/execution/invocation/invocation.js +94 -19
  58. package/dist/execution/invocation/lifecycle/active.d.ts +8 -2
  59. package/dist/execution/invocation/lifecycle/active.js +3 -3
  60. package/dist/execution/invocation/lifecycle/index.d.ts +1 -1
  61. package/dist/execution/serve.d.ts +8 -0
  62. package/dist/execution/serve.js +7 -0
  63. package/dist/execution/service/create.js +2 -0
  64. package/dist/execution/service/service.d.ts +6 -0
  65. package/dist/execution/workflows/engine.d.ts +12 -2
  66. package/dist/execution/workflows/index.d.ts +1 -1
  67. package/dist/execution/workflows/integrations.d.ts +13 -0
  68. package/dist/execution/workflows/integrations.js +25 -0
  69. package/dist/execution/workflows/options.js +3 -1
  70. package/dist/execution/workflows/receiver.d.ts +3 -0
  71. package/dist/execution/workflows/receiver.js +7 -2
  72. package/dist/execution/workflows/run.d.ts +3 -4
  73. package/dist/execution/workflows/run.js +32 -60
  74. package/dist/execution/workflows/steps.d.ts +42 -0
  75. package/dist/execution/workflows/steps.js +67 -0
  76. package/dist/platform/schema/index.d.ts +1 -1
  77. package/dist/testing/durable/engine.d.ts +111 -0
  78. package/dist/testing/durable/engine.js +540 -0
  79. package/dist/testing/durable/index.d.ts +3 -0
  80. package/dist/testing/durable/index.js +1 -0
  81. package/dist/testing/durable/steps.d.ts +30 -0
  82. package/dist/testing/durable/steps.js +40 -0
  83. package/dist/testing/index.d.ts +6 -1
  84. package/dist/testing/index.js +5 -1
  85. package/dist/tooling/cli/dotenv.d.ts +3 -3
  86. package/dist/tooling/cli/dotenv.js +3 -3
  87. package/dist/tooling/cli/log.d.ts +0 -2
  88. package/dist/tooling/cli/log.js +0 -2
  89. package/dist/tooling/linter/adapters/typescript/imports.d.ts +0 -1
  90. package/dist/tooling/linter/adapters/typescript/imports.js +1 -5
  91. package/dist/tooling/linter/adapters/typescript/index.d.ts +1 -1
  92. package/dist/tooling/linter/adapters/typescript/index.js +1 -1
  93. package/dist/tooling/linter/adapters/typescript/syntax.d.ts +3 -3
  94. package/dist/tooling/linter/adapters/typescript/syntax.js +13 -25
  95. package/dist/tooling/linter/implementations/source/callable-requirements.d.ts +0 -1
  96. package/dist/tooling/linter/implementations/source/callable-requirements.js +1 -6
  97. package/dist/tooling/linter/implementations/source/dependencies.js +12 -1
  98. package/dist/tooling/linter/implementations/source/mutations.js +1 -12
  99. package/dist/tooling/linter/implementations/source/queries.js +1 -17
  100. package/dist/tooling/linter/implementations/source/shared.d.ts +0 -4
  101. package/dist/tooling/linter/implementations/source/shared.js +1 -33
  102. package/dist/tooling/linter/implementations/source/workflows.js +5 -15
  103. package/dist/tooling/linter/policy/generated.js +2 -2
  104. package/package.json +6 -6
@@ -0,0 +1,67 @@
1
+ import { bindSession } from '../../platform/client/session/index.js';
2
+ import { bindCapabilities } from '../invocation/capabilities/index.js';
3
+ import { bindIntegrationAuthentication } from '../invocation/integration/index.js';
4
+ import { stepCalls } from './integrations.js';
5
+ /**
6
+ * Steps acting as the Domain through a Session of the Execution they belong to: the capabilities of
7
+ * an Action over the keyed Session, and the Runtime's Integration clients over the same keys.
8
+ */
9
+ export function sessionSteps(input) {
10
+ const { executor, domain, integrations } = input;
11
+ return ({ execution, next, lifetime }) => {
12
+ const session = executor(execution.kernel, execution.id, lifetime);
13
+ try {
14
+ const bound = bindSession(session, lifetime);
15
+ const self = keyed(bound, domain, next);
16
+ const auth = bindIntegrationAuthentication(lifetime, bound);
17
+ const authority = Object.freeze({
18
+ ...bindCapabilities(domain, { self }),
19
+ integrations: integrations(stepCalls({ next, lifetime, auth })),
20
+ });
21
+ return Object.freeze({ authority, close: () => session.close() });
22
+ }
23
+ catch (cause) {
24
+ session.close();
25
+ throw cause;
26
+ }
27
+ };
28
+ }
29
+ /**
30
+ * Every Mutation and every `invoke` of a durable callable of one Step without its own key carries
31
+ * the next key of the Step's sequence. The sequence restarts with every attempt, so a retried Step
32
+ * replays the same keys: the Kernel answers a Mutation with its receipt and a durable call with the
33
+ * Execution it started, or refuses a request that changed under its key. Any other `invoke` carries
34
+ * no key, because the Kernel accepts one only for a durable Function, and runs again with the Step.
35
+ */
36
+ export function keyed(session, domain, next) {
37
+ const invokeSource = session.invoke;
38
+ const mutateSource = session.mutate;
39
+ const invoke = ((reference, value, options) => invokeSource(reference, value, declaredDurable(domain, reference) ? withKey(options, next) : options));
40
+ const mutate = ((author, options) => mutateSource(author, withKey(options, next)));
41
+ return Object.freeze({ ...session, invoke, mutate });
42
+ }
43
+ /**
44
+ * Whether the Domain's Schema closure declares the referenced callable durable. An untyped Path
45
+ * names no declaration and a callable outside the closure has none here: both need their own key.
46
+ */
47
+ function declaredDurable(domain, reference) {
48
+ if (reference === null || typeof reference !== 'object')
49
+ return false;
50
+ const key = reference.callable;
51
+ return (typeof key === 'string' && domain.callable(key)?.execution?.durable === true);
52
+ }
53
+ function withKey(options, next) {
54
+ if (options?.idempotencyKey !== undefined || options?.body !== undefined)
55
+ return options;
56
+ return { ...options, idempotencyKey: next() };
57
+ }
58
+ /** The key sequence of one Step of one Execution: `<execution>.<digest of the name>.<position>`. */
59
+ export async function keySequence(execution, name) {
60
+ const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(name)));
61
+ const prefix = `${execution}.${Array.from(digest.subarray(0, 12), hex).join('')}`;
62
+ let position = 0;
63
+ return () => `${prefix}.${++position}`;
64
+ }
65
+ function hex(byte) {
66
+ return byte.toString(16).padStart(2, '0');
67
+ }
@@ -18,7 +18,7 @@ export type { ClassIcon } from './class-icon.js';
18
18
  export type { StoredPropertyInputOf } from './property-input.js';
19
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';
20
20
  export type { Array, Object, Value } from '@astrale-os/kernel-dsl/value';
21
- export type { CallableExecution, ClassKind, DirectedEdgeContract, EdgeClassPolicies, NodeClassDefinition, PolicyCheckObject, PolicyObjectRef, PropertyFacet, PropertyImmutability, StateTopology, UndirectedEdgeContract, } from '@astrale-os/kernel-dsl/v1/language';
21
+ export type { CallableAdmission, CallableExecution, ClassKind, DirectedEdgeContract, EdgeClassPolicies, NodeClassDefinition, PolicyCheckObject, PolicyObjectRef, PropertyFacet, PropertyImmutability, StateTopology, UndirectedEdgeContract, } from '@astrale-os/kernel-dsl/v1/language';
22
22
  export type { DomainSchema } from '@astrale-os/kernel-dsl/v1/schema';
23
23
  /** Kernel-owned Schema values used by authored product Schemas and graph operations. */
24
24
  export { AuthorityOperationOrder, AuthorityOperations, AuthorityRelations, KernelRootFunctions, OperationCore, operationOf, } from '@astrale-os/kernel-core/schema';
@@ -0,0 +1,111 @@
1
+ import type { ActionOutputOf, ResolvedDomainOf } from '../../application/action/index.js';
2
+ import type { DeclaredErrors } from '../../application/error/index.js';
3
+ import type { Integrations, Providers } from '../../application/integration/index.js';
4
+ import type { CallableAtWorkflowAddress, WorkflowAddress, WorkflowDefinition } from '../../application/workflow/index.js';
5
+ import type { ExecutionOutcome, ExecutionState } from '../../platform/client/session/index.js';
6
+ import type { NodeId } from '../../platform/graph/node/index.js';
7
+ import type { CallableInputOf, ResolvedMethod, schema } from '../../platform/schema/index.js';
8
+ import type { Value } from '../../platform/value/index.js';
9
+ import type { TestStepCapabilities } from './steps.js';
10
+ export interface TestEngineOptions {
11
+ /** Start of the virtual clock, in Unix milliseconds; the current time by default. */
12
+ readonly now?: number;
13
+ /** Attempts of a run before it pauses; 20 by default, as on a Host. */
14
+ readonly maxAttempts?: number;
15
+ }
16
+ /**
17
+ * An in-memory workflow engine that runs durable Workflows with the receiver a Host serves: it
18
+ * journals each Step, replays the journal on every attempt, retries failed attempts, keeps timers
19
+ * on a virtual clock, buffers signals, pauses after the last attempt and cancels cooperatively.
20
+ */
21
+ export interface TestEngine {
22
+ /** The virtual clock, in Unix milliseconds. */
23
+ readonly now: number;
24
+ /** Start one durable Execution and settle it: it ends, waits, or pauses. */
25
+ start<Schema extends schema.DomainSchema, Address extends WorkflowAddress<Schema>, Definitions extends Integrations, Errors extends DeclaredErrors>(workflow: WorkflowDefinition<Schema, Address, Definitions, Errors>, options: TestStartOptions<CallableAtWorkflowAddress<Schema, Address>, ResolvedDomainOf<Schema>, Definitions>): Promise<TestExecution<ActionOutputOf<CallableAtWorkflowAddress<Schema, Address>>>>;
26
+ /** Move the virtual clock forward and settle every waiting Execution. */
27
+ advance(durationMs: number): Promise<void>;
28
+ }
29
+ export type TestStartOptions<Callable, DomainValue, Definitions extends Integrations> = {
30
+ /** The resolved Schema the Workflow belongs to. */
31
+ readonly schema: DomainValue;
32
+ readonly input: CallableInputOf<Callable>;
33
+ /** The `K.Execution` id; a fresh one by default. */
34
+ readonly id?: NodeId;
35
+ /** Who started the Execution; test Identities by default. */
36
+ readonly initiator?: {
37
+ readonly principal: NodeId;
38
+ readonly caller: NodeId;
39
+ };
40
+ readonly capabilities?: TestStepCapabilities;
41
+ /** Steps whose first completion is lost before the journal records it; see `interruptAfter`. */
42
+ readonly interruptAfter?: readonly string[];
43
+ } & ReceiverOf<Callable> & ProvidersOf<Definitions>;
44
+ type ReceiverOf<Callable> = Callable extends ResolvedMethod<unknown, unknown, false> ? {
45
+ readonly self: NodeId;
46
+ } : {
47
+ readonly self?: never;
48
+ };
49
+ type ProvidersOf<Definitions extends Integrations> = keyof Definitions extends never ? {
50
+ readonly providers?: never;
51
+ } : {
52
+ readonly providers: Providers<Definitions>;
53
+ };
54
+ /** One durable Execution on a test engine. */
55
+ export interface TestExecution<Output> {
56
+ readonly id: NodeId;
57
+ readonly state: Extract<ExecutionState, 'running' | 'waiting' | 'paused' | 'completed' | 'failed' | 'cancelled'>;
58
+ /** Present once the Execution ended, as `Execution.result` answers it. */
59
+ readonly outcome: ExecutionOutcome<Output> | undefined;
60
+ /** What the last failed attempt threw; it is why a paused Execution paused. */
61
+ readonly failure: unknown;
62
+ /** Attempts made so far, replays included. */
63
+ readonly attempts: number;
64
+ /** The run's journal, in order. */
65
+ readonly journal: readonly TestJournalEntry[];
66
+ /**
67
+ * Deliver `Execution.signal({ name, value })`, then settle. False when a signal already resolved
68
+ * that name.
69
+ */
70
+ signal(name: string, value?: Value): Promise<boolean>;
71
+ /** Request cooperative cancellation, as `Execution.cancel()`, then settle. */
72
+ cancel(): Promise<void>;
73
+ /** Attempt a paused Execution again, as `Execution.resume()`, then settle. */
74
+ resume(): Promise<void>;
75
+ /**
76
+ * Run the Workflow once more from its journal alone, as a restart does, and fail if it runs a Step
77
+ * again, diverges from the journal, or reaches another outcome.
78
+ */
79
+ replay(): Promise<void>;
80
+ /**
81
+ * The next time Step `id` completes, lose its result before the journal records it, as a crash
82
+ * between its effect and the journal does. The engine then retries the Step.
83
+ */
84
+ interruptAfter(id: string): void;
85
+ }
86
+ /** One entry of a run's journal. */
87
+ export type TestJournalEntry = {
88
+ readonly kind: 'run';
89
+ readonly name: string;
90
+ readonly settled: boolean;
91
+ readonly value?: unknown;
92
+ readonly error?: unknown;
93
+ } | {
94
+ readonly kind: 'sleep';
95
+ readonly until: number;
96
+ readonly settled: boolean;
97
+ } | {
98
+ readonly kind: 'signal';
99
+ readonly name: string;
100
+ readonly settled: boolean;
101
+ readonly value?: unknown;
102
+ } | {
103
+ readonly kind: 'race';
104
+ readonly name: string;
105
+ readonly until: number;
106
+ readonly settled: boolean;
107
+ readonly outcome?: 'signal' | 'timeout' | 'cancelled';
108
+ };
109
+ /** Create an in-memory workflow engine for tests. */
110
+ export declare function createTestEngine(options?: TestEngineOptions): TestEngine;
111
+ export {};