@truenas/api-client 1.0.3 → 1.0.5
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/index.cjs +70 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +862 -540
- package/dist/index.d.ts +862 -540
- package/dist/index.js +70 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -159,6 +159,16 @@ var TrueNasApi = class {
|
|
|
159
159
|
this.initializeJobEventsSubscription();
|
|
160
160
|
}
|
|
161
161
|
call(method, params) {
|
|
162
|
+
return this.dispatch(method, params);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Send a JSON-RPC request and emit its result.
|
|
166
|
+
*
|
|
167
|
+
* Shared by {@link call} and the query verbs, which type the same wire call
|
|
168
|
+
* against different directories — `call` against the hand-maintained one,
|
|
169
|
+
* the verbs against the generated one.
|
|
170
|
+
*/
|
|
171
|
+
dispatch(method, params) {
|
|
162
172
|
const message = createJsonRpcMessage(method, params);
|
|
163
173
|
this.connection.ws.next(message);
|
|
164
174
|
const messageId = message.id ?? "";
|
|
@@ -174,6 +184,58 @@ var TrueNasApi = class {
|
|
|
174
184
|
rxjs.take(1)
|
|
175
185
|
);
|
|
176
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Query a collection and emit the matching entries.
|
|
189
|
+
*
|
|
190
|
+
* ```typescript
|
|
191
|
+
* api.query('user.query') // UserEntry[]
|
|
192
|
+
* api.query('user.query', [['uid', '>', 1000]]) // UserEntry[]
|
|
193
|
+
* api.query('user.query', [], { select: ['id', 'username'] })
|
|
194
|
+
* // Pick<UserEntry, 'id' | 'username'>[]
|
|
195
|
+
* ```
|
|
196
|
+
*
|
|
197
|
+
* The precise result type comes from reading the options *literal*. Options
|
|
198
|
+
* annotated as `QueryListOptions<E>` lose that, and the result degrades to
|
|
199
|
+
* `Partial<E>[]` — not only when a `select` is present, but whenever the
|
|
200
|
+
* annotation merely permits one:
|
|
201
|
+
*
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const opts: QueryListOptions<UserEntry> = { limit: 10 };
|
|
204
|
+
* api.query('user.query', [], opts); // Partial<UserEntry>[]
|
|
205
|
+
*
|
|
206
|
+
* const opts = { limit: 10 } satisfies QueryListOptions<UserEntry>;
|
|
207
|
+
* api.query('user.query', [], opts); // UserEntry[]
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* That is imprecise, never unsound: `Partial<E>` is a supertype of `E`, so a
|
|
211
|
+
* field is only ever reported as *possibly* missing, never as present when it
|
|
212
|
+
* is not. Reach for `satisfies` over an annotation to keep the precision —
|
|
213
|
+
* the checking is the same, the inferred type is narrower.
|
|
214
|
+
*
|
|
215
|
+
* `count` and `get` are rejected: they would change the shape of the
|
|
216
|
+
* response, which is {@link queryCount} and {@link queryOne}'s job.
|
|
217
|
+
*/
|
|
218
|
+
query(method, filters, options) {
|
|
219
|
+
return this.dispatch(method, [filters ?? [], options ?? {}]);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Query a collection and emit the single matching entry.
|
|
223
|
+
*
|
|
224
|
+
* Middleware errors unless exactly one entry matches, so this rejects
|
|
225
|
+
* `limit` and `offset` as well as the shape switches.
|
|
226
|
+
*/
|
|
227
|
+
queryOne(method, filters, options) {
|
|
228
|
+
return this.dispatch(method, [filters ?? [], { ...options, get: true }]);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Emit the number of entries matching the filters.
|
|
232
|
+
*
|
|
233
|
+
* Takes no options: `select` and `order_by` cannot affect a count, and
|
|
234
|
+
* `limit` / `offset` would silently cap it.
|
|
235
|
+
*/
|
|
236
|
+
queryCount(method, filters) {
|
|
237
|
+
return this.dispatch(method, [filters ?? [], { count: true }]);
|
|
238
|
+
}
|
|
177
239
|
/**
|
|
178
240
|
* Makes an API call and returns the job ID from the websocket event.
|
|
179
241
|
* Used for v26 where API calls return null but job events contain the job ID.
|
|
@@ -3429,7 +3491,14 @@ function instantiateClientForVersion(version, opts, logger) {
|
|
|
3429
3491
|
version: version.version,
|
|
3430
3492
|
versionKey
|
|
3431
3493
|
});
|
|
3432
|
-
return new Client(
|
|
3494
|
+
return new Client(
|
|
3495
|
+
uuid,
|
|
3496
|
+
hostnames,
|
|
3497
|
+
version,
|
|
3498
|
+
enabled,
|
|
3499
|
+
systemName,
|
|
3500
|
+
logger
|
|
3501
|
+
);
|
|
3433
3502
|
}
|
|
3434
3503
|
function errorMessageOrDefault(error, fallback) {
|
|
3435
3504
|
if (error instanceof Error) {
|