@truenas/api-client 8.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.
package/README.md CHANGED
@@ -17,7 +17,7 @@ const users = await firstValueFrom(
17
17
  for every supported release. A misspelled method, a missing parameter or a
18
18
  filter on a field that doesn't exist fails the build, not the user.
19
19
  - **Version-aware.** The client asks the appliance which API it speaks and
20
- builds the matching implementation. API versions v25.10.0 through v27.0.0
20
+ builds the matching implementation. API versions v25.10.0 through v28.0.0
21
21
  are supported side by side.
22
22
  - **One call across releases.** `client.ops` keeps working when middleware
23
23
  renames or reshapes an endpoint between versions.
@@ -89,7 +89,9 @@ client.api.call('alert.dismiss', ['uuid-1']); // params checked against the me
89
89
  client.api.call('nope.nope'); // ✗ compile error
90
90
  ```
91
91
 
92
- A failed call errors with middleware's own message.
92
+ A failed call errors with a `TrueNasApiError`. Its `message` is middleware's own
93
+ reason, and the rest of the error is there too: `errname` (such as `EINVAL`),
94
+ and `data.extra`, where a validation error names the fields it rejected.
93
95
 
94
96
  ## Queries
95
97
 
@@ -116,7 +118,9 @@ client.api.job('pool.dataset.export_key', ['tank/encrypted']).subscribe(job => {
116
118
  ```
117
119
 
118
120
  The stream emits each state and completes when the job finishes. A failed job
119
- completes too, with `state` and `error` set.
121
+ completes too, with `state` and `error` set. A job method refused before it
122
+ starts a job, such as for a validation error, errors with a `TrueNasApiError`
123
+ instead, because there is no job to report.
120
124
 
121
125
  ## Events
122
126
 
@@ -129,7 +133,20 @@ client.api.events('app.query').subscribe(change => {
129
133
 
130
134
  Changes are typed per collection and discriminated on `msg`. One server
131
135
  subscription is shared by every subscriber and re-registered after each
132
- reconnect.
136
+ reconnect. When the last subscriber leaves, it is released with
137
+ `core.unsubscribe`.
138
+
139
+ Event sources take their arguments after the name, typed from the method's
140
+ `subscriptionParams`:
141
+
142
+ ```typescript
143
+ client.api.events('filesystem.file_tail_follow', { path: '/var/log/messages' })
144
+ .subscribe(line => append(line.fields.data));
145
+ ```
146
+
147
+ A source with different arguments is a separate subscription. If middleware
148
+ ends a source, the stream completes. If it rejects the arguments, the stream
149
+ errors with a `TrueNasApiError`.
133
150
 
134
151
  ## Working across versions
135
152
 
@@ -137,12 +154,12 @@ Without a hint, the client is typed as the oldest supported version, since that
137
154
  is a safe floor against any appliance. Reach newer methods one of two ways:
138
155
 
139
156
  ```typescript
140
- // Discover the version, and write against v26:
141
- const client = await createTrueNasClient<ApiDirectoryV26_0_0>(options);
157
+ // Discover the version, and write against v27:
158
+ const client = await createTrueNasClient<ApiDirectoryV27_0_0>(options);
142
159
  client.api.query('container.query');
143
160
 
144
161
  // Or skip discovery, and let the types follow the version:
145
- const pinned = await createTrueNasClient({ ...options, version: 'v27.0.0' });
162
+ const pinned = await createTrueNasClient({ ...options, version: 'v28.0.0' });
146
163
  pinned.api.query('container.query');
147
164
  ```
148
165
 
@@ -164,6 +181,17 @@ client.ops.smbStatus({ infoLevel: 'SESSIONS' });
164
181
  Per-version details, such as permissions that differ between releases, are in
165
182
  the `OperationMappings` reference.
166
183
 
184
+ Some behaviour differs between versions in ways no type can express, because a
185
+ default is not part of a TypeScript signature. One worth knowing: at v28.0.0,
186
+ `config.save()` with no arguments includes the secret seed in the backup, where
187
+ at v25.10 and v27.0 the same call left it out. That seed decrypts every
188
+ password, private key and API key the backup contains, so treat such a backup
189
+ as a secret; pass `{ secretseed: false }` for the old behaviour, bearing in mind
190
+ a backup saved without it cannot be uploaded. These are recorded as they are
191
+ found in
192
+ [`src/generated/MANIFEST.md`](https://github.com/truenas/api-client-ts/blob/main/src/generated/MANIFEST.md),
193
+ which is in the repository rather than the published package.
194
+
167
195
  ## Connection
168
196
 
169
197
  ```typescript
@@ -212,7 +240,8 @@ the client is doing.
212
240
 
213
241
  ## Errors
214
242
 
215
- - **Calls** error with middleware's message.
243
+ - **Calls, queries and job starts** error with `TrueNasApiError`. Its `message`
244
+ is middleware's reason, and `errname`, `code` and `data` carry the rest.
216
245
  - **Logins** error with `AuthError`. Check `code` against `AuthErrorCode`.
217
246
  - **`createTrueNasClient`** rejects with a `VersionDiscoveryError` subclass, such
218
247
  as `VersionTooOldError`, `VersionTooNewError` or