@astrale-os/kernel-client 0.6.0-beta.57 → 0.6.0-beta.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,7 @@
1
1
  import type { invocation as protocol } from '@astrale-os/kernel-protocol';
2
2
  import type { Call } from './request.js';
3
3
  /** Parent-private Call acceptance shared by Client and Client Session. */
4
- export declare function acceptCall(input: Call): protocol.Call;
4
+ export declare function acceptCall(input: {
5
+ readonly target: Call['target'];
6
+ readonly input: unknown;
7
+ }): protocol.Call;
@@ -47,7 +47,7 @@ function propertyAccessor(selected, props) {
47
47
  function methodAccessor(selected, node, call) {
48
48
  return (input) => {
49
49
  const method = resolveMethod(selected, input);
50
- if (method.abstract === true) {
50
+ if (!method.executable) {
51
51
  throw new TypeError(`Abstract Method ${method.key} cannot be invoked.`);
52
52
  }
53
53
  return (value) => call(node, method, value);
@@ -104,7 +104,7 @@ function installPropertyShortcuts(target, selected, props, reserved) {
104
104
  }
105
105
  function installMethodShortcuts(target, selected, node, call, reserved) {
106
106
  for (const member of selected.methods) {
107
- if (member.abstract === true || reserved.has(member.name) || hasOwn(target, member.name))
107
+ if (!member.executable || reserved.has(member.name) || hasOwn(target, member.name))
108
108
  continue;
109
109
  if (named(selected.methods, member.name) !== member)
110
110
  continue;
@@ -14,7 +14,7 @@ export interface BoundSessionSource {
14
14
  readonly schema: SchemaApi;
15
15
  dispatch(call: Call, options?: SessionRequestOptions): Promise<Result>;
16
16
  call(call: Call, options?: SessionRequestOptions): Promise<Input>;
17
- invoke<const Reference extends CallableReference>(reference: Reference, input: InputOfReference<Reference>, options?: SessionRequestOptions): Promise<OutputOfReference<Reference>>;
17
+ invoke<const Reference extends CallableReference<unknown>>(reference: Reference, input: InputOfReference<Reference>, options?: SessionRequestOptions): Promise<OutputOfReference<Reference>>;
18
18
  stream(call: Call, options?: SessionRequestOptions): Promise<Stream>;
19
19
  binary(call: Call, options?: SessionRequestOptions): Promise<Binary>;
20
20
  viewsFor(target: Parameters<ClientSession['viewsFor']>[0], options?: SessionControlOptions): Promise<ViewCatalog>;
@@ -36,7 +36,7 @@ export interface BoundClientSession extends GraphApi {
36
36
  readonly schema: SchemaApi;
37
37
  dispatch(call: Call, options?: SessionRequestOptions): Promise<Result>;
38
38
  call(call: Call, options?: SessionRequestOptions): Promise<Input>;
39
- invoke<const Reference extends CallableReference>(reference: Reference, input: InputOfReference<Reference>, options?: SessionRequestOptions): Promise<OutputOfReference<Reference>>;
39
+ invoke<const Reference extends CallableReference<unknown>>(reference: Reference, input: InputOfReference<Reference>, options?: SessionRequestOptions): Promise<OutputOfReference<Reference>>;
40
40
  stream(call: Call, options?: SessionRequestOptions): Promise<Stream>;
41
41
  binary(call: Call, options?: SessionRequestOptions): Promise<Binary>;
42
42
  viewsFor: BoundSessionSource['viewsFor'];
@@ -1,11 +1,11 @@
1
1
  import type { Path as PathValue, PathLike } from '@astrale-os/kernel-core/path';
2
- import type { CallableInputOf, CallableOutputOf, CallableResultOf, Domain, ResolvedFunction, ResolvedMethod } from '@astrale-os/kernel-dsl/v1';
2
+ import type { CallableInputOf, CallableOutputOf, CallableResultOf, Domain, ResolvedFunction, ExecutableMethod } from '@astrale-os/kernel-dsl/v1';
3
3
  import type { Revision } from '@astrale-os/kernel-dsl/v1/addressing';
4
4
  import { type Key as KeyType } from '@astrale-os/kernel-dsl/v1/addressing';
5
5
  import type { Binary, Input } from '../client/index.js';
6
6
  declare const REFERENCE_INPUT: unique symbol;
7
7
  declare const REFERENCE_OUTPUT: unique symbol;
8
- export interface CallableReference<InputValue extends Input = Input, Output = unknown> {
8
+ export interface CallableReference<InputValue = Input, Output = unknown> {
9
9
  readonly origin: KeyType.Origin;
10
10
  readonly revision: Revision;
11
11
  readonly callable: KeyType.Callable;
@@ -14,22 +14,22 @@ export interface CallableReference<InputValue extends Input = Input, Output = un
14
14
  readonly [REFERENCE_INPUT]?: InputValue;
15
15
  readonly [REFERENCE_OUTPUT]?: Output;
16
16
  }
17
- export interface InstanceCallableReference<InputValue extends Input = Input, Output = unknown> {
17
+ export interface InstanceCallableReference<InputValue = Input, Output = unknown> {
18
18
  (receiver: PathLike): CallableReference<InputValue, Output>;
19
19
  readonly origin: KeyType.Origin;
20
20
  readonly revision: Revision;
21
21
  readonly callable: KeyType.Callable;
22
22
  readonly outputMode: 'value' | 'stream' | 'binary';
23
23
  }
24
- export type InputOfReference<Reference extends CallableReference> = Reference extends CallableReference<infer InputValue, unknown> ? InputValue : never;
25
- export type OutputOfReference<Reference extends CallableReference> = Reference extends CallableReference<infer _Input, infer Output> ? Output : never;
26
- type ReferenceInput<Callable> = unknown extends CallableInputOf<Callable> ? Input : Extract<CallableInputOf<Callable>, Input>;
24
+ export type InputOfReference<Reference extends CallableReference<unknown>> = Reference extends CallableReference<infer InputValue, unknown> ? InputValue : never;
25
+ export type OutputOfReference<Reference extends CallableReference<unknown>> = Reference extends CallableReference<infer _Input, infer Output> ? Output : never;
26
+ type ReferenceInput<Callable> = unknown extends CallableInputOf<Callable> ? Input : CallableInputOf<Callable>;
27
27
  type ReferenceOutput<Callable> = unknown extends CallableOutputOf<Callable> ? unknown : CallableResultOf<Callable, Binary>;
28
- type ExecutableStaticMethod = ResolvedMethod<unknown, unknown, true, false>;
29
- type ExecutableInstanceMethod = ResolvedMethod<unknown, unknown, false, false>;
28
+ type ExecutableStaticMethod = ExecutableMethod<unknown, unknown, true>;
29
+ type ExecutableInstanceMethod = ExecutableMethod<unknown, unknown, false>;
30
30
  /** Project one exact resolved Function or static Method into a typed Client reference. */
31
31
  export declare function reference<const Callable extends ResolvedFunction | ExecutableStaticMethod>(domain: Pick<Domain, 'origin' | 'revision'>, callable: Callable): CallableReference<ReferenceInput<Callable>, ReferenceOutput<Callable>>;
32
32
  /** Project one exact resolved instance Method into a receiver-bound typed Client reference. */
33
33
  export declare function reference<const Callable extends ExecutableInstanceMethod>(domain: Pick<Domain, 'origin' | 'revision'>, callable: Callable): InstanceCallableReference<ReferenceInput<Callable>, ReferenceOutput<Callable>>;
34
- export declare function admitReference(input: CallableReference): CallableReference;
34
+ export declare function admitReference(input: CallableReference<unknown>): CallableReference<unknown>;
35
35
  export {};
@@ -3,7 +3,7 @@ import { callableAddress, Key, patterns, } from '@astrale-os/kernel-dsl/v1/addre
3
3
  export function reference(domain, callable) {
4
4
  if (Key.origin(callable.key) !== domain.origin)
5
5
  invalid();
6
- if ('owner' in callable && callable.abstract === true)
6
+ if ('owner' in callable && !callable.executable)
7
7
  invalid();
8
8
  const common = Object.freeze({
9
9
  origin: domain.origin,
@@ -1,10 +1,11 @@
1
1
  import type { IssuerId } from '@astrale-os/kernel-core/auth/issuer';
2
- import type { Call, Result } from '../../client/index.js';
2
+ import type { Result } from '../../client/index.js';
3
3
  import type { SessionOperation, SessionPolicy } from '../context/index.js';
4
4
  import type { SessionAuth } from './auth.js';
5
5
  import type { RouteCache } from './cache.js';
6
6
  import type { ClientPoolCapability } from './envelope.js';
7
7
  import type { SessionEnvelopeTransport, SessionRequestOptions } from './request.js';
8
+ import { acceptCall } from '../../client/index.js';
8
9
  export interface SessionDispatcherOptions {
9
10
  readonly kernel: IssuerId;
10
11
  readonly sourceEndpoint: string;
@@ -19,7 +20,7 @@ export interface SessionDispatcherOptions {
19
20
  export declare class SessionDispatcher {
20
21
  private readonly state;
21
22
  constructor(state: SessionDispatcherOptions);
22
- dispatch(input: Call, options: SessionRequestOptions, operation: SessionOperation): Promise<Result>;
23
+ dispatch(input: Parameters<typeof acceptCall>[0], options: SessionRequestOptions, operation: SessionOperation): Promise<Result>;
23
24
  private dispatchSource;
24
25
  private followSource;
25
26
  private dispatchDestinationWithRecovery;
@@ -56,7 +56,7 @@ export declare class ClientSession {
56
56
  viewsFor(target: PathLike, options?: SessionControlOptions): Promise<ViewCatalog>;
57
57
  dispatch(call: Call, options?: SessionRequestOptions): Promise<Result>;
58
58
  call(call: Call, options?: SessionRequestOptions): Promise<Input>;
59
- invoke<const Reference extends CallableReference>(reference: Reference, input: InputOfReference<Reference>, options?: SessionRequestOptions): Promise<OutputOfReference<Reference>>;
59
+ invoke<const Reference extends CallableReference<unknown>>(reference: Reference, input: InputOfReference<Reference>, options?: SessionRequestOptions): Promise<OutputOfReference<Reference>>;
60
60
  stream(call: Call, options?: SessionRequestOptions): Promise<import("../client/result.js").Stream>;
61
61
  binary(call: Call, options?: SessionRequestOptions): Promise<import("@astrale-os/kernel-core/callable").BinaryOutput>;
62
62
  close(): void;
@@ -1,6 +1,7 @@
1
1
  import { NodeId } from '@astrale-os/kernel-core/graph/node';
2
2
  import { Path } from '@astrale-os/kernel-core/path';
3
- import { defineSchema, method, nodeClass, schema } from '@astrale-os/kernel-dsl/v1';
3
+ import { K, KernelSchema } from '@astrale-os/kernel-core/schema';
4
+ import { defineSchema, func, method, nodeClass, schema, valueSchema, } from '@astrale-os/kernel-dsl/v1';
4
5
  import { ClientSession, reference } from './index.js';
5
6
  void new ClientSession(options);
6
7
  void auth;
@@ -15,6 +16,59 @@ const dynamicInputIsClientInput = true;
15
16
  const dynamicOutputIsUnknown = true;
16
17
  void dynamicInputIsClientInput;
17
18
  void dynamicOutputIsUnknown;
19
+ const renameInput = valueSchema()({
20
+ type: 'object',
21
+ properties: { name: { type: 'string' } },
22
+ required: ['name'],
23
+ additionalProperties: false,
24
+ });
25
+ const registrationInput = valueSchema()(K.functions.register.input);
26
+ const booleanOutput = valueSchema()({ type: 'boolean' });
27
+ const typedDomain = schema.resolve(defineSchema('client.input-witness.typecheck', {
28
+ dependencies: { kernel: KernelSchema },
29
+ functions: {
30
+ registerIdentity: func({
31
+ auth: 'authenticated',
32
+ input: registrationInput,
33
+ output: booleanOutput,
34
+ }),
35
+ },
36
+ classes: {
37
+ Person: nodeClass({
38
+ methods: {
39
+ rename: method({ auth: 'authenticated', input: renameInput, output: booleanOutput }),
40
+ registerIdentity: method({
41
+ static: true,
42
+ auth: 'authenticated',
43
+ input: registrationInput,
44
+ output: booleanOutput,
45
+ }),
46
+ },
47
+ }),
48
+ },
49
+ }));
50
+ const registerReference = reference(typedDomain, typedDomain.functions.registerIdentity);
51
+ const staticRegisterReference = reference(typedDomain, typedDomain.classes.Person.static.methods.registerIdentity);
52
+ const renameReference = reference(typedDomain, typedDomain.classes.Person.methods.rename)(Path.id(NodeId('person')));
53
+ void session.invoke(registerReference, registration);
54
+ void boundSession.invoke(staticRegisterReference, registration);
55
+ void session.invoke(renameReference, renameRequest);
56
+ const registerInputIsRequest = true;
57
+ const renameInputIsInterface = true;
58
+ const renameOutputIsBoolean = true;
59
+ void registerInputIsRequest;
60
+ void renameInputIsInterface;
61
+ void renameOutputIsBoolean;
62
+ // @ts-expect-error The exact Schema's required input fields are retained.
63
+ void session.invoke(renameReference, {});
64
+ // @ts-expect-error A Date is not the Schema's declared string input.
65
+ void session.invoke(renameReference, { name: new Date() });
66
+ // @ts-expect-error A function is not the Schema's declared string input.
67
+ void session.invoke(renameReference, { name: () => 'Ada' });
68
+ // @ts-expect-error RegisterRequest retains its nonempty identities tuple.
69
+ void session.invoke(registerReference, { idempotencyKey: 'key', identities: [] });
70
+ // @ts-expect-error An unknown-schema reference still accepts only portable Client Input.
71
+ void session.invoke(dynamicReference, new Date());
18
72
  const abstractMethod = method({
19
73
  auth: 'authenticated',
20
74
  input: { type: 'null' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/kernel-client",
3
- "version": "0.6.0-beta.57",
3
+ "version": "0.6.0-beta.58",
4
4
  "description": "Universal Client — protocol-first, transport-agnostic",
5
5
  "keywords": [
6
6
  "astrale",
@@ -65,14 +65,14 @@
65
65
  "access": "public"
66
66
  },
67
67
  "dependencies": {
68
- "@astrale-os/kernel-core": "0.9.0-beta.44",
69
- "@astrale-os/kernel-dsl": "0.2.0-beta.32",
70
- "@astrale-os/kernel-protocol": "0.5.0-beta.48",
68
+ "@astrale-os/kernel-core": "0.9.0-beta.45",
69
+ "@astrale-os/kernel-dsl": "0.2.0-beta.33",
70
+ "@astrale-os/kernel-protocol": "0.5.0-beta.49",
71
71
  "@tanstack/pacer": "0.20.1",
72
72
  "msgpackr": "^2.0.5"
73
73
  },
74
74
  "devDependencies": {
75
- "@astrale-os/kernel-server": "0.5.0-beta.50",
75
+ "@astrale-os/kernel-server": "0.5.0-beta.51",
76
76
  "@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
77
77
  "@types/node": "^22.0.0",
78
78
  "typescript": "7.0.2",