@astrale-os/kernel-client 0.6.0-beta.57 → 0.6.0-beta.59
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/dist/auth/auth.d.ts +2 -1
- package/dist/auth/credential.d.ts +5 -0
- package/dist/auth/credential.js +4 -0
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/client/admission.d.ts +4 -1
- package/dist/graph/domain/project.js +2 -2
- package/dist/session/bound.d.ts +2 -2
- package/dist/session/reference.d.ts +9 -9
- package/dist/session/reference.js +1 -1
- package/dist/session/routing/dispatch.d.ts +3 -2
- package/dist/session/session.d.ts +1 -1
- package/dist/session/session.typecheck.js +55 -1
- package/package.json +5 -5
package/dist/auth/auth.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { PathLike } from '@astrale-os/kernel-core/path';
|
|
|
3
3
|
import type { Input } from '../client/index.js';
|
|
4
4
|
import type { RequestOptions } from '../transport/index.js';
|
|
5
5
|
import type { PolicyDecisionInput } from './authorization.js';
|
|
6
|
-
import type { DelegateOptions, MintOptions } from './credential.js';
|
|
6
|
+
import type { DelegateOptions, MintOptions, ImpersonateOptions } from './credential.js';
|
|
7
7
|
import type { WhoisInput } from './identity.js';
|
|
8
8
|
import type { RegisterRequest } from './register.js';
|
|
9
9
|
export type AuthCall = (target: PathLike, input: Input, options?: RequestOptions) => Promise<Input>;
|
|
@@ -12,6 +12,7 @@ export interface AuthApi {
|
|
|
12
12
|
whoami(options?: RequestOptions): Promise<Identity & Authentication>;
|
|
13
13
|
whois(input: WhoisInput, options?: RequestOptions): Promise<(Identity & Authentication) | null>;
|
|
14
14
|
can(input: PolicyDecisionInput, options?: RequestOptions): Promise<boolean>;
|
|
15
|
+
impersonate(input: ImpersonateOptions, options?: RequestOptions): Promise<MintedCredential>;
|
|
15
16
|
mint(input: MintOptions, options?: RequestOptions): Promise<MintedCredential>;
|
|
16
17
|
delegate(identity: IdentityId, input: DelegateOptions, options?: RequestOptions): Promise<MintedCredential>;
|
|
17
18
|
}
|
|
@@ -7,13 +7,18 @@ export interface MintOptions {
|
|
|
7
7
|
readonly ttlSeconds: number;
|
|
8
8
|
readonly grant?: UnresolvedGrant;
|
|
9
9
|
}
|
|
10
|
+
export interface ImpersonateOptions extends MintOptions {
|
|
11
|
+
readonly identity: IdentityId;
|
|
12
|
+
}
|
|
10
13
|
export interface DelegateOptions {
|
|
11
14
|
readonly audience: string;
|
|
12
15
|
readonly ttlSeconds: number;
|
|
13
16
|
readonly attenuation: UnresolvedIdentityExpr;
|
|
14
17
|
}
|
|
18
|
+
export declare const IDENTITY_IMPERSONATE_PATH: NodePath;
|
|
15
19
|
export declare const IDENTITY_MINT_PATH: NodePath;
|
|
16
20
|
export declare function credentialApi(call: AuthCall): Readonly<{
|
|
21
|
+
impersonate(input: ImpersonateOptions, options?: RequestOptions): Promise<MintedCredential>;
|
|
17
22
|
mint(input: MintOptions, options?: RequestOptions): Promise<MintedCredential>;
|
|
18
23
|
delegate(principal: IdentityId, input: DelegateOptions, options?: RequestOptions): Promise<MintedCredential>;
|
|
19
24
|
}>;
|
package/dist/auth/credential.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { Path } from '@astrale-os/kernel-core/path';
|
|
2
2
|
import { identity } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
|
|
3
3
|
const identityOwner = Path.project(identity.whoami.owner);
|
|
4
|
+
export const IDENTITY_IMPERSONATE_PATH = Path.staticMethod(identityOwner, identity.impersonate.name).raw;
|
|
4
5
|
export const IDENTITY_MINT_PATH = Path.staticMethod(identityOwner, identity.mint.name).raw;
|
|
5
6
|
export function credentialApi(call) {
|
|
6
7
|
return Object.freeze({
|
|
8
|
+
async impersonate(input, options) {
|
|
9
|
+
return credential(await call(IDENTITY_IMPERSONATE_PATH, input, options));
|
|
10
|
+
},
|
|
7
11
|
async mint(input, options) {
|
|
8
12
|
return credential(await call(IDENTITY_MINT_PATH, input, options));
|
|
9
13
|
},
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createAuth, type AuthApi, type AuthCall } from './auth.js';
|
|
2
2
|
export { IDENTITY_CAN_PATH, type PolicyDecisionInput } from './authorization.js';
|
|
3
|
-
export { IDENTITY_MINT_PATH, type DelegateOptions, type MintOptions } from './credential.js';
|
|
3
|
+
export { IDENTITY_MINT_PATH, IDENTITY_IMPERSONATE_PATH, type DelegateOptions, type MintOptions, type ImpersonateOptions, } from './credential.js';
|
|
4
4
|
export { IDENTITY_WHOAMI_PATH, IDENTITY_WHOIS_PATH, type WhoisInput } from './identity.js';
|
|
5
5
|
export { IDENTITY_REGISTER_PATH, type RegisterIdentity, type RegisterRequest } from './register.js';
|
|
6
6
|
export type { Identity, IdentityId, Subject, IssuerId, MintedCredential, RegisterResult, UnresolvedGrant, UnresolvedIdentityExpr, } from '@astrale-os/kernel-core/auth';
|
package/dist/auth/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createAuth } from './auth.js';
|
|
2
2
|
export { IDENTITY_CAN_PATH } from './authorization.js';
|
|
3
|
-
export { IDENTITY_MINT_PATH } from './credential.js';
|
|
3
|
+
export { IDENTITY_MINT_PATH, IDENTITY_IMPERSONATE_PATH, } from './credential.js';
|
|
4
4
|
export { IDENTITY_WHOAMI_PATH, IDENTITY_WHOIS_PATH } from './identity.js';
|
|
5
5
|
export { IDENTITY_REGISTER_PATH } from './register.js';
|
|
@@ -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:
|
|
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.
|
|
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.
|
|
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;
|
package/dist/session/bound.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
25
|
-
export type OutputOfReference<Reference extends CallableReference
|
|
26
|
-
type ReferenceInput<Callable> = unknown extends 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 =
|
|
29
|
-
type ExecutableInstanceMethod =
|
|
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.
|
|
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 {
|
|
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:
|
|
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
|
|
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 {
|
|
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.
|
|
3
|
+
"version": "0.6.0-beta.59",
|
|
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.
|
|
69
|
-
"@astrale-os/kernel-dsl": "0.2.0-beta.
|
|
70
|
-
"@astrale-os/kernel-protocol": "0.5.0-beta.
|
|
68
|
+
"@astrale-os/kernel-core": "0.9.0-beta.46",
|
|
69
|
+
"@astrale-os/kernel-dsl": "0.2.0-beta.33",
|
|
70
|
+
"@astrale-os/kernel-protocol": "0.5.0-beta.50",
|
|
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.
|
|
75
|
+
"@astrale-os/kernel-server": "0.5.0-beta.52",
|
|
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",
|