@truenas/api-client 9.0.0 → 9.0.1

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.
@@ -13543,17 +13543,35 @@ type JobResult<D extends ApiDirectoryShape, M extends JobMethod<D>> = D['job'][M
13543
13543
  response: infer R;
13544
13544
  } ? R : never;
13545
13545
  /**
13546
- * The events a surface can be subscribed to by name alone.
13547
- *
13548
- * Excludes *event sources* (entries with a `subscriptionParams` model, e.g.
13549
- * `app.stats`, `reporting.realtime`). They take subscribe-time arguments whose
13550
- * encoding the dump does not record (`core.subscribe` takes one string), so
13551
- * subscribing by name alone would give a silent stream. Widen this once the
13552
- * encoding is confirmed against a live appliance (`yarn live-check`).
13546
+ * The collections a surface can be subscribed to: by name alone, with no
13547
+ * arguments. Event sources are {@link EventSourceName}.
13553
13548
  */
13554
13549
  type EventName<D extends ApiDirectoryShape> = {
13555
13550
  [E in keyof D['event']]: 'subscriptionParams' extends keyof D['event'][E] ? never : E;
13556
13551
  }[keyof D['event']] & string;
13552
+ /**
13553
+ * The *event sources* of a surface: entries with a `subscriptionParams` model,
13554
+ * such as `filesystem.file_tail_follow` or `reporting.realtime`, which take
13555
+ * arguments when subscribed to. See {@link SubscriptionParams}.
13556
+ */
13557
+ type EventSourceName<D extends ApiDirectoryShape> = {
13558
+ [E in keyof D['event']]: 'subscriptionParams' extends keyof D['event'][E] ? E : never;
13559
+ }[keyof D['event']] & string;
13560
+ /** Everything a surface can be subscribed to: collections and event sources. */
13561
+ type SubscribableEvent<D extends ApiDirectoryShape> = EventName<D> | EventSourceName<D>;
13562
+ /** The arguments an event source takes, e.g. `{ path, tail_lines? }`. */
13563
+ type SubscriptionParams<D extends ApiDirectoryShape, E extends EventSourceName<D>> = D['event'][E] extends {
13564
+ subscriptionParams: infer P;
13565
+ } ? P : never;
13566
+ /**
13567
+ * What `events()` takes after an event source's name: its arguments, which may
13568
+ * be left out when none of them is required.
13569
+ *
13570
+ * Not {@link ArgsOf}: that asks whether an empty *tuple* fits, and the
13571
+ * arguments here are an object. `Record<string, never>` — a source taking no
13572
+ * arguments, such as `zfs.tier.rewrite_job_query` — would then be required.
13573
+ */
13574
+ type SubscriptionArgs<D extends ApiDirectoryShape, E extends EventSourceName<D>> = Record<never, never> extends SubscriptionParams<D, E> ? [params?: SubscriptionParams<D, E>] : [params: SubscriptionParams<D, E>];
13557
13575
  /** The kinds of change a collection event reports. */
13558
13576
  type EventKind = 'added' | 'changed' | 'removed';
13559
13577
  /**
@@ -13564,11 +13582,11 @@ type EventKind = 'added' | 'changed' | 'removed';
13564
13582
  * plenty of collections declare only `added`, and an arm for a kind that never
13565
13583
  * arrives would invite callers to handle it.
13566
13584
  */
13567
- type EventArm<D extends ApiDirectoryShape, E extends EventName<D>, K extends EventKind> = K extends keyof D['event'][E] ? {
13585
+ type EventArm<D extends ApiDirectoryShape, E extends SubscribableEvent<D>, K extends EventKind> = K extends keyof D['event'][E] ? {
13568
13586
  msg: K;
13569
13587
  } & D['event'][E][K] : never;
13570
13588
  /** The kinds the directory says this event reports. */
13571
- type DeclaredKinds<D extends ApiDirectoryShape, E extends EventName<D>> = Extract<keyof D['event'][E], EventKind>;
13589
+ type DeclaredKinds<D extends ApiDirectoryShape, E extends SubscribableEvent<D>> = Extract<keyof D['event'][E], EventKind>;
13572
13590
  /**
13573
13591
  * An arm for the kinds the directory does NOT declare, carrying no payload.
13574
13592
  *
@@ -13580,7 +13598,7 @@ type DeclaredKinds<D extends ApiDirectoryShape, E extends EventName<D>> = Extrac
13580
13598
  * this arm a `removed` frame on a collection that lists only `added` and
13581
13599
  * `changed` would reach the caller typed as carrying `fields`.
13582
13600
  */
13583
- type UndeclaredArm<D extends ApiDirectoryShape, E extends EventName<D>> = [Exclude<EventKind, DeclaredKinds<D, E>>] extends [never] ? never : {
13601
+ type UndeclaredArm<D extends ApiDirectoryShape, E extends SubscribableEvent<D>> = [Exclude<EventKind, DeclaredKinds<D, E>>] extends [never] ? never : {
13584
13602
  msg: Exclude<EventKind, DeclaredKinds<D, E>>;
13585
13603
  id?: unknown;
13586
13604
  };
@@ -13591,7 +13609,7 @@ type UndeclaredArm<D extends ApiDirectoryShape, E extends EventName<D>> = [Exclu
13591
13609
  * no `fields` in 55 of the 56 collections that declare one — so narrowing on
13592
13610
  * `msg` is what makes the payload safe to reach.
13593
13611
  */
13594
- type EventUnion<D extends ApiDirectoryShape, E extends EventName<D>> = EventArm<D, E, 'added'> | EventArm<D, E, 'changed'> | EventArm<D, E, 'removed'> | UndeclaredArm<D, E>;
13612
+ type EventUnion<D extends ApiDirectoryShape, E extends SubscribableEvent<D>> = EventArm<D, E, 'added'> | EventArm<D, E, 'changed'> | EventArm<D, E, 'removed'> | UndeclaredArm<D, E>;
13595
13613
 
13596
13614
  /**
13597
13615
  * Types for the query verbs — `api.query` / `queryOne` / `queryCount`.
@@ -30802,14 +30820,29 @@ declare class TrueNasApi<D extends ApiDirectoryShape = BaseApiDirectory> {
30802
30820
  /**
30803
30821
  * Stream of job events from websocket.
30804
30822
  * JSON-RPC 2.0 events have structure: { method: 'collection_update', params: { collection, fields, ... } }
30823
+ *
30824
+ * Reads `messages()` when first subscribed, not when this is built, as every
30825
+ * other verb does. A consumer that wraps the connection's `messages()` after
30826
+ * the client is created — a debug panel mixing in mocked answers — is
30827
+ * otherwise heard by `call` and `events` but not by job tracking.
30805
30828
  */
30806
30829
  private jobEvents;
30807
30830
  /**
30808
- * One shared stream per subscribed event name — see {@link events}.
30809
- * Keyed by name rather than by caller, because the subscription it stands
30810
- * for lives on the server and is per socket, not per caller.
30831
+ * One shared stream per subscription — see {@link events}. Keyed by the
30832
+ * name *with* its arguments: a tail of one file is not a tail of another.
30811
30833
  */
30812
30834
  private readonly eventStreams;
30835
+ /**
30836
+ * Releases awaiting their `core.unsubscribe` reply, per name. Middleware
30837
+ * sends a source's release notice (`terminate`) before that reply, and a
30838
+ * notice names only the collection; so an error-free one arriving inside
30839
+ * that window belongs to the release, not to a later subscription. One per
30840
+ * window, which closes on the reply whether or not a notice came.
30841
+ */
30842
+ private readonly releasing;
30843
+ /** The live subscription per name, told when the server ends it. */
30844
+ private readonly serverEnds;
30845
+ private endNotices?;
30813
30846
  constructor(authenticated: BehaviorSubject<boolean>, connection: TrueNasConnection);
30814
30847
  /**
30815
30848
  * Call a method of the typed surface and emit its result.
@@ -30877,7 +30910,7 @@ declare class TrueNasApi<D extends ApiDirectoryShape = BaseApiDirectory> {
30877
30910
  * differs by version (v25.10 answers with the id, v27 with `null`), while
30878
30911
  * the event correlation holds for both.
30879
30912
  *
30880
- * @returns Observable that emits the job ID when received from websocket events
30913
+ * @returns the job's id; errors with a {@link TrueNasApiError} if the method is refused before a job starts
30881
30914
  */
30882
30915
  callAndGetJobId<M extends JobMethod<D>>(method: M, ...params: ArgsOf<JobParams<D, M>>): Observable<number>;
30883
30916
  /**
@@ -30893,19 +30926,33 @@ declare class TrueNasApi<D extends ApiDirectoryShape = BaseApiDirectory> {
30893
30926
  */
30894
30927
  job<M extends JobMethod<D>>(method: M, ...params: ArgsOf<JobParams<D, M>>): Observable<Job<JobResult<D, M>>>;
30895
30928
  /**
30896
- * Subscribe to a collection and emit its changes, discriminated on `msg`.
30929
+ * Subscribe to a collection or an event source and emit its changes,
30930
+ * discriminated on `msg`.
30897
30931
  *
30898
30932
  * ```typescript
30899
30933
  * api.events('app.query').subscribe(event => {
30900
30934
  * if (event.msg === 'removed') return drop(event.id);
30901
30935
  * render(event.fields); // only reachable once narrowed
30902
30936
  * });
30937
+ * api.events('filesystem.file_tail_follow', { path: '/var/log/messages' });
30903
30938
  * ```
30904
30939
  *
30905
30940
  * Narrow before reading `fields`: `removed` events almost never carry it.
30906
- * Sources taking subscribe-time arguments are excluded; see {@link EventName}.
30907
30941
  */
30908
30942
  events<E extends EventName<D>>(event: E): Observable<EventUnion<D, E>>;
30943
+ events<E extends EventSourceName<D>>(event: E, ...params: SubscriptionArgs<D, E>): Observable<EventUnion<D, E>>;
30944
+ /**
30945
+ * Release a subscription by the id `core.subscribe` answered with, holding
30946
+ * its notice window (see {@link releasing}) open until the reply.
30947
+ */
30948
+ private unsubscribe;
30949
+ /**
30950
+ * Route each `notify_unsubscribed` once: an error-free one inside an open
30951
+ * release window is that release's, anything else ends the name's live
30952
+ * subscription. Installed on the first `events()` call, before any stream
30953
+ * listens.
30954
+ */
30955
+ private listenForEndNotices;
30909
30956
  /**
30910
30957
  * Convenience wrapper for auth.generate_token API call.
30911
30958
  *
@@ -31625,4 +31672,4 @@ declare enum TrueNasAuthMechanism {
31625
31672
  Token = "TOKEN_PLAIN"
31626
31673
  }
31627
31674
 
31628
- export { type CreateClientOptions as $, type ApiDirectory$7 as A, type ApiEventDirectory$1 as B, type ApiEventDirectory as C, type ApiJobDirectory$7 as D, type ApiJobDirectory$6 as E, type ApiJobDirectory$5 as F, type ApiJobDirectory$4 as G, type ApiJobDirectory$3 as H, type ApiJobDirectory$2 as I, type ApiJobDirectory$1 as J, type ApiJobDirectory as K, type Logger as L, type ApiKeyCreate as M, type ApiVersionResponse as N, type OperationMappings as O, AppState as P, type ArgsOf as Q, type AuthResponse as R, AuthResponseType as S, TrueNasApiClient as T, type BaseApiDirectory as U, type CallMethod as V, type CallParams as W, type CallResponse as X, type ConnectionClose as Y, type ConnectionEndpoint as Z, type Container as _, type ApiDirectory$1 as a, type DefaultApiDirectory as a0, type EventKind as a1, type EventName as a2, type EventUnion as a3, type Job as a4, type JobMethod as a5, type JobParams as a6, type JobProgress as a7, type JobResult as a8, JobState as a9, index$6 as aA, index$5 as aB, index$4 as aC, index$3 as aD, index$2 as aE, index$1 as aF, index as aG, TrueNasConnection as aH, type TrueNasMessage as aI, TrueNasAuthenticator as aJ, type DerivedDirectory as aK, type QueryDirectory as aa, type QueryEntity as ab, type QueryListOptions as ac, type QueryMethod as ad, type QuerySingleOptions as ae, type ReconnectOptions as af, SUPPORTED_API_VERSIONS as ag, type SmbStatusInfoLevel as ah, type SmbStatusOptions as ai, type SmbStatusRequest as aj, type SmbStatusResponse as ak, type SmbStatusRow as al, type SupportedApiVersion as am, TrueNasAuthMechanism as an, type TrueNasDate as ao, type TrueNasErrorData as ap, type TrueNasErrorFrame as aq, UserRole as ar, type UserRoleName as as, VersionCompatibility as at, consoleLogger as au, createTrueNasClient as av, getApiErrorMessage as aw, isJobFinished as ax, noopLogger as ay, index$7 as az, type ApiDirectory as b, type ApplianceProtocol as c, type ApiVersion as d, type ApiCallDirectory$7 as e, type ApiCallDirectory$6 as f, type ApiCallDirectory$5 as g, type ApiCallDirectory$4 as h, type ApiCallDirectory$3 as i, type ApiCallDirectory$2 as j, type ApiCallDirectory$1 as k, type ApiCallDirectory as l, type ApiDirectoryByVersion as m, type ApiDirectoryShape as n, type ApiDirectory$6 as o, type ApiDirectory$5 as p, type ApiDirectory$4 as q, type ApiDirectory$3 as r, type ApiDirectory$2 as s, type ApiError as t, type ApiEventDirectory$7 as u, type ApiEventDirectory$6 as v, type ApiEventDirectory$5 as w, type ApiEventDirectory$4 as x, type ApiEventDirectory$3 as y, type ApiEventDirectory$2 as z };
31675
+ export { type ConnectionEndpoint as $, type ApiDirectory$7 as A, type ApiEventDirectory$3 as B, type ApiEventDirectory$2 as C, type ApiEventDirectory$1 as D, type ApiEventDirectory as E, type ApiJobDirectory$7 as F, type ApiJobDirectory$6 as G, type ApiJobDirectory$5 as H, type ApiJobDirectory$4 as I, type ApiJobDirectory$3 as J, type ApiJobDirectory$2 as K, type Logger as L, type ApiJobDirectory$1 as M, type ApiJobDirectory as N, type OperationMappings as O, type ApiKeyCreate as P, type ApiVersionResponse as Q, AppState as R, type ArgsOf as S, TrueNasApiClient as T, type AuthResponse as U, AuthResponseType as V, type BaseApiDirectory as W, type CallMethod as X, type CallParams as Y, type CallResponse as Z, type ConnectionClose as _, type ApiDirectory$1 as a, type Container as a0, type CreateClientOptions as a1, type DefaultApiDirectory as a2, type EventKind as a3, type EventName as a4, type EventSourceName as a5, type EventUnion as a6, type Job as a7, type JobMethod as a8, type JobParams as a9, getApiErrorMessage as aA, isJobFinished as aB, noopLogger as aC, index$7 as aD, index$6 as aE, index$5 as aF, index$4 as aG, index$3 as aH, index$2 as aI, index$1 as aJ, index as aK, TrueNasConnection as aL, type TrueNasMessage as aM, TrueNasAuthenticator as aN, type DerivedDirectory as aO, type JobProgress as aa, type JobResult as ab, JobState as ac, type QueryDirectory as ad, type QueryEntity as ae, type QueryListOptions as af, type QueryMethod as ag, type QuerySingleOptions as ah, type ReconnectOptions as ai, SUPPORTED_API_VERSIONS as aj, type SmbStatusInfoLevel as ak, type SmbStatusOptions as al, type SmbStatusRequest as am, type SmbStatusResponse as an, type SmbStatusRow as ao, type SubscribableEvent as ap, type SubscriptionArgs as aq, type SubscriptionParams as ar, type SupportedApiVersion as as, TrueNasAuthMechanism as at, type TrueNasDate as au, UserRole as av, type UserRoleName as aw, VersionCompatibility as ax, consoleLogger as ay, createTrueNasClient as az, type ApiDirectory as b, type ApplianceProtocol as c, type ApiVersion as d, type TrueNasErrorFrame as e, type TrueNasErrorData as f, type ApiCallDirectory$7 as g, type ApiCallDirectory$6 as h, type ApiCallDirectory$5 as i, type ApiCallDirectory$4 as j, type ApiCallDirectory$3 as k, type ApiCallDirectory$2 as l, type ApiCallDirectory$1 as m, type ApiCallDirectory as n, type ApiDirectoryByVersion as o, type ApiDirectoryShape as p, type ApiDirectory$6 as q, type ApiDirectory$5 as r, type ApiDirectory$4 as s, type ApiDirectory$3 as t, type ApiDirectory$2 as u, type ApiError as v, type ApiEventDirectory$7 as w, type ApiEventDirectory$6 as x, type ApiEventDirectory$5 as y, type ApiEventDirectory$4 as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truenas/api-client",
3
- "version": "9.0.0",
3
+ "version": "9.0.1",
4
4
  "description": "Framework-agnostic TypeScript client for the TrueNAS JSON-RPC 2.0 WebSocket API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -51,7 +51,7 @@
51
51
  "lint": "eslint .",
52
52
  "check:dist": "node scripts/check-dist.mjs",
53
53
  "docs": "typedoc",
54
- "docs:check": "typedoc --emit none",
54
+ "docs:check": "typedoc --out .typedoc-validate",
55
55
  "check:package": "publint && yarn pack -o package.tgz && attw package.tgz && rm -f package.tgz",
56
56
  "clean": "rm -rf dist"
57
57
  },