@astrale-os/kernel-client 1.0.0-beta.46 → 1.0.0-beta.47

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.
@@ -2,11 +2,16 @@ import type { NodePath, NodeTarget, PathLike } from '@astrale-os/kernel-core/pat
2
2
  import type { PolicyRef } from '@astrale-os/kernel-dsl/v1';
3
3
  import type { RequestOptions } from '../transport/index.js';
4
4
  import type { AuthCall } from './auth.js';
5
- export interface PolicyDecisionInput {
5
+ /** Each supplied Node is an ID, Path or DefinitionRef resolved by the Kernel. */
6
+ export type PolicyDecisionInput = {
6
7
  readonly policy: PathLike | PolicyRef;
7
- /** The observed Node: its ID, or a Path or DefinitionRef the Kernel resolves on its Registry. */
8
+ } & ({
8
9
  readonly object: NodeTarget;
9
- }
10
+ readonly input?: never;
11
+ } | {
12
+ readonly input: Readonly<Record<string, NodeTarget>>;
13
+ readonly object?: never;
14
+ });
10
15
  export declare const IDENTITY_CAN_PATH: NodePath;
11
16
  export declare function authorizationApi(call: AuthCall): Readonly<{
12
17
  can: {
@@ -28,7 +28,16 @@ function isBatch(input) {
28
28
  return Array.isArray(input);
29
29
  }
30
30
  function check(input) {
31
- return Object.freeze({ policy: policyPath(input.policy), object: objectTarget(input.object) });
31
+ if ('input' in input && 'object' in input) {
32
+ throw new TypeError('Identity.can accepts either object or named input.');
33
+ }
34
+ const policy = policyPath(input.policy);
35
+ return input.input !== undefined
36
+ ? {
37
+ policy,
38
+ input: Object.fromEntries(Object.entries(input.input).map(([name, target]) => [name, objectTarget(target)])),
39
+ }
40
+ : { policy, object: objectTarget(input.object) };
32
41
  }
33
42
  /** Text is already its wire form; a rich target serializes to its canonical Path. */
34
43
  function objectTarget(input) {
@@ -1,6 +1,7 @@
1
1
  import type { EdgeKey, EdgeSlug } from '@astrale-os/kernel-core/graph/edge';
2
2
  import type { FactId } from '@astrale-os/kernel-core/graph/formula';
3
3
  import type { Answer, QueryResult, Undecided, wire } from '@astrale-os/kernel-core/graph/query';
4
+ import type { RevisionToken } from '@astrale-os/kernel-core/graph/revision';
4
5
  import type { ClassKey } from '@astrale-os/kernel-dsl/v1/addressing';
5
6
  /** Caller-selected bounds and continuation for one graph query page. */
6
7
  export interface QueryPageRequest {
@@ -49,8 +50,11 @@ export interface QueryItem {
49
50
  }
50
51
  /**
51
52
  * What a Query answers, by its family: a list's Page, the table of the facts it renders as values
52
- * (an Edge's entry with the slug the Edge stores, when it has one), the revision it was read at and
53
- * whether its cursor came from another (W6); an `exists`; or a `count`.
53
+ * (an Edge's entry with the slug the Edge stores, when it has one, and each entry of a stored Node
54
+ * or Edge the caller reads with its `revision` and its write count, `writes`, unless the Host does
55
+ * not state them), the schema revision it was read under (`schema`) and whether its cursor came
56
+ * from another (W6); an `exists`; or a `count`. A Host below wire level 1 states neither on any
57
+ * entry: that case ends when the floor passes level 1.
54
58
  */
55
59
  export type QueryAnswer = {
56
60
  readonly list: QueryPage;
@@ -58,8 +62,10 @@ export type QueryAnswer = {
58
62
  readonly list: unknown;
59
63
  }>['facts'][number] & {
60
64
  readonly slug?: EdgeSlug;
65
+ readonly revision?: RevisionToken;
66
+ readonly writes?: number;
61
67
  })[];
62
- readonly revision: string;
68
+ readonly schema: string;
63
69
  readonly revised?: true;
64
70
  } | Exclude<Answer, {
65
71
  readonly list: unknown;
@@ -1,4 +1,5 @@
1
1
  import { QUERY, QueryAST, QueryASTDecodeError, QueryResult, } from '@astrale-os/kernel-core/graph/query';
2
+ import { isRevisionToken } from '@astrale-os/kernel-core/graph/revision';
2
3
  import { Path, PathError } from '@astrale-os/kernel-core/path';
3
4
  import { queryOutput } from '@astrale-os/kernel-core/schema/kernel/syscalls/contracts';
4
5
  import { query } from '@astrale-os/kernel-core/schema/kernel/syscalls/references';
@@ -126,7 +127,11 @@ function decodeAnswer(input, family) {
126
127
  return answer;
127
128
  // Only an Edge carries a slug.
128
129
  const slugs = answer.facts.every(({ fact, slug }) => slug === undefined || typeof fact !== 'string');
129
- return slugs && pagesClosed(answer.list) ? answer : refuse();
130
+ // A revision and a write count come together, or the Kernel states neither.
131
+ const revisions = answer.facts.every(({ revision, writes }) => revision === undefined
132
+ ? writes === undefined
133
+ : writes !== undefined && isRevisionToken(revision));
134
+ return slugs && revisions && pagesClosed(answer.list) ? answer : refuse();
130
135
  }
131
136
  /**
132
137
  * Every Page, its Branches' included, carries a cursor exactly when an item follows it (W3), and
@@ -47,8 +47,10 @@ declare function overloads(): Promise<readonly [QueryResponse<import("@astrale-o
47
47
  readonly list: unknown;
48
48
  }>['facts'][number] & {
49
49
  readonly slug?: import("@astrale-os/kernel-core/graph/edge").EdgeSlug;
50
+ readonly revision?: import("@astrale-os/kernel-core/graph/revision").RevisionToken;
51
+ readonly writes?: number;
50
52
  })[];
51
- readonly revision: string;
53
+ readonly schema: string;
52
54
  readonly revised?: true;
53
55
  }, {
54
56
  readonly exists: boolean;
@@ -24,7 +24,8 @@ export type CredentialsState = {
24
24
  };
25
25
  /**
26
26
  * Acquire one fresh credential: a compact JWT, whose `exp` claim is its expiry, or an explicit
27
- * credential and expiry. The supplied signal is owned by Credentials.
27
+ * credential and expiry. The supplied signal is owned by Credentials: the attempt fails once it
28
+ * aborts, at the mint budget at the latest, whether or not the mint observes it.
28
29
  */
29
30
  export type CredentialsMint = (signal: AbortSignal) => string | SessionCredential | PromiseLike<string | SessionCredential>;
30
31
  export interface CredentialsOptions {
@@ -131,18 +131,28 @@ export function credentials(source) {
131
131
  return { promise: Promise.reject(error), controller };
132
132
  }
133
133
  const renew = mint;
134
- const current = held();
135
- publish({ status: 'refreshing', ...(current === undefined ? {} : { credential: current }) });
136
134
  unsignalled = false;
137
- const signal = AbortSignal.any([controller.signal, AbortSignal.timeout(MINT_TIMEOUT_MS)]);
135
+ const signal = controller.signal;
136
+ // The budget is a timer of this owner's clock, cleared once the attempt settles.
137
+ const deadline = setTimeout(() => {
138
+ controller.abort(new DOMException('Session credential mint timed out.', 'TimeoutError'));
139
+ }, MINT_TIMEOUT_MS);
140
+ let abandon;
138
141
  const promise = (async () => {
139
142
  try {
140
143
  // A mint that throws instead of rejecting fails this attempt alike: the executor turns the
141
144
  // throw into a rejection, so the attempt settles only after it yields, once `minting`
142
- // holds it, and the cleanup below releases it for the next acquisition.
143
- const returned = new Promise((complete) => {
145
+ // holds it, and the cleanup below releases it for the next acquisition. The budget is
146
+ // this owner's, not the mint's: the attempt fails once its signal aborts, whether or not
147
+ // the mint observes it, so an answer that never comes cannot hold `minting` forever.
148
+ const answer = new Promise((complete) => {
144
149
  complete(renew(signal));
145
150
  });
151
+ const returned = new Promise((complete, fail) => {
152
+ abandon = () => fail(signal.reason);
153
+ signal.addEventListener('abort', abandon, { once: true });
154
+ answer.then(complete, fail);
155
+ });
146
156
  const minted = admitMinted(await returned);
147
157
  attempt = 0;
148
158
  publish({ status: 'valid', credential: minted });
@@ -155,10 +165,16 @@ export function credentials(source) {
155
165
  throw error;
156
166
  }
157
167
  finally {
168
+ clearTimeout(deadline);
169
+ if (abandon !== undefined)
170
+ signal.removeEventListener('abort', abandon);
158
171
  minting = undefined;
159
172
  }
160
173
  })();
161
174
  minting = { promise, controller };
175
+ // Published once the mint is held: an observer that acquires now joins it. It settles later.
176
+ const current = held();
177
+ publish({ status: 'refreshing', ...(current === undefined ? {} : { credential: current }) });
162
178
  // A rejection reaches every waiter; keep an unattached one from surfacing as unhandled.
163
179
  promise.catch(() => undefined);
164
180
  return minting;
@@ -213,7 +229,9 @@ export function credentials(source) {
213
229
  clearTimeout(expiryTimer);
214
230
  expiryTimer = setTimeout(() => {
215
231
  expiryTimer = undefined;
216
- if (!anticipating || held() !== credential)
232
+ // A mint in flight settles within its budget and reports the outcome itself: expiry is
233
+ // published only while no attempt is pending, so `expired` always means a retry can start.
234
+ if (!anticipating || held() !== credential || minting !== undefined)
217
235
  return;
218
236
  publish({ status: 'expired', error: new ClientError('Session credential expired.') });
219
237
  }, clamp(credential.expiresAt - Date.now()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/kernel-client",
3
- "version": "1.0.0-beta.46",
3
+ "version": "1.0.0-beta.47",
4
4
  "description": "Universal Client — protocol-first, transport-agnostic",
5
5
  "keywords": [
6
6
  "astrale",
@@ -65,13 +65,13 @@
65
65
  "access": "public"
66
66
  },
67
67
  "dependencies": {
68
- "@astrale-os/kernel-core": "1.0.0-beta.43",
69
- "@astrale-os/kernel-dsl": "1.0.0-beta.31",
70
- "@astrale-os/kernel-protocol": "1.0.0-beta.43",
68
+ "@astrale-os/kernel-core": "1.0.0-beta.44",
69
+ "@astrale-os/kernel-dsl": "1.0.0-beta.32",
70
+ "@astrale-os/kernel-protocol": "1.0.0-beta.44",
71
71
  "@tanstack/pacer": "0.20.1"
72
72
  },
73
73
  "devDependencies": {
74
- "@astrale-os/kernel-server": "1.0.0-beta.43",
74
+ "@astrale-os/kernel-server": "1.0.0-beta.44",
75
75
  "@astrale/typescript-config": "npm:@jsr/astrale__typescript-config@~1.1.0",
76
76
  "@types/node": "^24.10.0",
77
77
  "esbuild": "0.28.1",