@truenas/api-client 3.0.0 → 3.0.2

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 CHANGED
@@ -2894,14 +2894,23 @@ var apiVersionConfig = {
2894
2894
  /**
2895
2895
  * Maximum supported API version. Systems above it are rejected.
2896
2896
  *
2897
- * NOT derived, deliberately. This should be the newest generated version by
2898
- * the same argument as MIN, but `instantiateClientForVersion` only maps
2899
- * `25.10` and `26` a v27 system would pass the range check and then throw
2900
- * on client selection. It moves to the newest generated version once a v27
2901
- * client exists. Until then it lags on purpose, and the `satisfies` clause
2902
- * below still pins it to a version that was actually generated.
2897
+ * NOT derived, deliberately and for a different reason than it used to
2898
+ * lag. It sat at v26.0.0 while types for v27 already shipped, because
2899
+ * `CLIENT_BY_VERSION_KEY` had no `27` and a v27 system would have passed the
2900
+ * range check only to throw on client selection. `TrueNasApiClientV27` now
2901
+ * exists, so this moves up with it.
2902
+ *
2903
+ * What it must not become is `SUPPORTED_API_VERSIONS[length - 1]`, the mirror
2904
+ * of how MIN is derived. MIN is safe to derive because the oldest generated
2905
+ * version always has a client — it is the floor the clients were built from.
2906
+ * The ceiling is not symmetric: generating types for v28 does not write a v28
2907
+ * client, so deriving this would re-create the exact gap described above on
2908
+ * the next regeneration, silently. The real invariant is "the newest version
2909
+ * a client can be built for", which lives in `CLIENT_BY_VERSION_KEY`; a
2910
+ * factory test asserts the two agree, which is the check that keeps this
2911
+ * literal honest without importing the factory here.
2903
2912
  */
2904
- MAX_SUPPORTED_VERSION: "v26.0.0",
2913
+ MAX_SUPPORTED_VERSION: "v27.0.0",
2905
2914
  /**
2906
2915
  * Fallback version to use when version discovery fails due to CORS/network errors.
2907
2916
  * When /api/versions returns HTTP status 0 (CORS block, network down, etc.),
@@ -3141,7 +3150,29 @@ var TrueNasApiClientV2510 = class extends TrueNasApiClient {
3141
3150
  containerQuery: () => this.api.query("virt.instance.query", [["type", "=", "CONTAINER"]]).pipe(rxjs.map((instances) => instances.map(toContainer))),
3142
3151
  containerStart: (id) => this.api.job("virt.instance.start", [id]),
3143
3152
  containerStop: (id, options) => this.api.job("virt.instance.stop", [id, options]),
3144
- containerRestart: (id, options) => this.api.job("virt.instance.restart", [id, options])
3153
+ containerRestart: (id, options) => this.api.job("virt.instance.restart", [id, options]),
3154
+ // Already a job here — `virt.instance.delete` has been one since
3155
+ // v25.10.0 — so this needs no synthesis, only the id. It takes nothing
3156
+ // else: there is no `force` and no `recursive` on this version.
3157
+ //
3158
+ // Unsupported options are reported rather than dropped. `recursive`
3159
+ // destroys child datasets, snapshots and clones irrecoverably, so a
3160
+ // caller who asked for it and silently did not get it has been told
3161
+ // something false about what just happened to their data. Reporting is
3162
+ // all this layer can do — refusing outright would make `ops.containerDelete`
3163
+ // unusable on v25.10 for the ordinary case, which is the case that works.
3164
+ containerDelete: (id, options) => {
3165
+ const unsupported = ["force", "recursive"].filter(
3166
+ (key) => options?.[key]
3167
+ );
3168
+ if (unsupported.length > 0) {
3169
+ this.logger.warn(
3170
+ "containerDelete: v25.10 has no counterpart for these options and will delete without them",
3171
+ { ignored: unsupported, id, method: "virt.instance.delete" }
3172
+ );
3173
+ }
3174
+ return this.api.job("virt.instance.delete", [id]);
3175
+ }
3145
3176
  };
3146
3177
  }
3147
3178
  };
@@ -3209,7 +3240,26 @@ var TrueNasApiClientV26 = class extends TrueNasApiClient {
3209
3240
  )
3210
3241
  )
3211
3242
  );
3212
- }
3243
+ },
3244
+ // A job since v26.0.0 — middleware made deletion long-running (it stops
3245
+ // the container when asked, tears down the libvirt domain and destroys
3246
+ // the dataset), and the generated directory moved it out of `call`
3247
+ // accordingly. `api.job` is what tracks it; `api.call` would not compile.
3248
+ //
3249
+ // Options pass straight through when given: the unified
3250
+ // `ContainerDeleteOptions` is `force`/`recursive`, exactly what the
3251
+ // generated params take.
3252
+ //
3253
+ // When they are not given the argument is *omitted* rather than passed as
3254
+ // `undefined`. `JSON.stringify` renders a trailing `undefined` array
3255
+ // element as `null`, and middleware declares `options: ContainerDeleteOptions`
3256
+ // with a model default and no `| None` — so `[id, null]` is a validation
3257
+ // error rather than "use the defaults", which is the one thing a caller
3258
+ // passing nothing is asking for.
3259
+ containerDelete: (id, options) => this.api.job(
3260
+ "container.delete",
3261
+ options ? [parseInt(id, 10), options] : [parseInt(id, 10)]
3262
+ )
3213
3263
  };
3214
3264
  }
3215
3265
  };
@@ -3224,6 +3274,87 @@ function toContainer2(container) {
3224
3274
  description
3225
3275
  };
3226
3276
  }
3277
+ var TrueNasApiClientV27 = class extends TrueNasApiClient {
3278
+ /**
3279
+ * Create v27-specific operation mappings
3280
+ *
3281
+ * Operations return Observable<Job | null>:
3282
+ * - Async operations emit Job updates until complete
3283
+ * - Sync operations emit null once
3284
+ */
3285
+ createOperations() {
3286
+ return {
3287
+ // A polymorphic `.query`, so it goes through the verb rather than
3288
+ // `call`: the directory types the raw method's response as the five-way
3289
+ // union the server may return, and the verb is what fixes it to a list.
3290
+ containerQuery: () => this.api.query("container.query").pipe(
3291
+ rxjs.map((containers) => containers.map(toContainer3))
3292
+ ),
3293
+ // container.start is synchronous in v27 - emit null
3294
+ containerStart: (id) => this.api.call("container.start", [parseInt(id, 10)]).pipe(rxjs.map(() => null)),
3295
+ // container.stop emits job updates
3296
+ containerStop: (id, options) => this.api.job("container.stop", [
3297
+ parseInt(id, 10),
3298
+ {
3299
+ force: options.force,
3300
+ force_after_timeout: options.force
3301
+ }
3302
+ ]),
3303
+ // v27 still has no container.restart - chain stop + start.
3304
+ // Emits Job updates during stop, then null when start completes.
3305
+ containerRestart: (id, options) => {
3306
+ const numericId = parseInt(id, 10);
3307
+ return this.api.job("container.stop", [
3308
+ numericId,
3309
+ {
3310
+ force: options.force,
3311
+ force_after_timeout: options.force
3312
+ }
3313
+ ]).pipe(
3314
+ // Collect all job updates to ensure stop fully completes
3315
+ rxjs.toArray(),
3316
+ // Re-emit job updates, then call start after stop is done
3317
+ rxjs.switchMap(
3318
+ (jobUpdates) => rxjs.concat(
3319
+ rxjs.from(jobUpdates),
3320
+ this.api.call("container.start", [numericId]).pipe(rxjs.map(() => null))
3321
+ )
3322
+ )
3323
+ );
3324
+ },
3325
+ // A job since v26.0.0 — middleware made deletion long-running (it stops
3326
+ // the container when asked, tears down the libvirt domain and destroys
3327
+ // the dataset), and the generated directory moved it out of `call`
3328
+ // accordingly. `api.job` is what tracks it; `api.call` would not compile.
3329
+ //
3330
+ // Options pass straight through when given: the unified
3331
+ // `ContainerDeleteOptions` is `force`/`recursive`, exactly what the
3332
+ // generated params take.
3333
+ //
3334
+ // When they are not given the argument is *omitted* rather than passed as
3335
+ // `undefined`. `JSON.stringify` renders a trailing `undefined` array
3336
+ // element as `null`, and middleware declares `options: ContainerDeleteOptions`
3337
+ // with a model default and no `| None` — so `[id, null]` is a validation
3338
+ // error rather than "use the defaults", which is the one thing a caller
3339
+ // passing nothing is asking for.
3340
+ containerDelete: (id, options) => this.api.job(
3341
+ "container.delete",
3342
+ options ? [parseInt(id, 10), options] : [parseInt(id, 10)]
3343
+ )
3344
+ };
3345
+ }
3346
+ };
3347
+ function toContainer3(container) {
3348
+ const { description } = container;
3349
+ return {
3350
+ id: container.id.toString(),
3351
+ name: container.name,
3352
+ status: toAppState(container.status.state),
3353
+ // Optional in the generated entry, required by `Container`.
3354
+ autostart: container.autostart ?? false,
3355
+ description
3356
+ };
3357
+ }
3227
3358
 
3228
3359
  // src/errors/version-discovery.errors.ts
3229
3360
  var VersionDiscoveryError = class extends Error {
@@ -3593,7 +3724,8 @@ function selectRepresentativeFailure(failures) {
3593
3724
  }
3594
3725
  var CLIENT_BY_VERSION_KEY = {
3595
3726
  "25.10": TrueNasApiClientV2510,
3596
- "26": TrueNasApiClientV26
3727
+ "26": TrueNasApiClientV26,
3728
+ "27": TrueNasApiClientV27
3597
3729
  };
3598
3730
  function clientVersionKey(version) {
3599
3731
  if (version.year <= legacyCutoffYear) {
@@ -3649,6 +3781,7 @@ exports.SUPPORTED_API_VERSIONS = SUPPORTED_API_VERSIONS;
3649
3781
  exports.TrueNasApiClient = TrueNasApiClient;
3650
3782
  exports.TrueNasApiClientV2510 = TrueNasApiClientV2510;
3651
3783
  exports.TrueNasApiClientV26 = TrueNasApiClientV26;
3784
+ exports.TrueNasApiClientV27 = TrueNasApiClientV27;
3652
3785
  exports.TrueNasAuthMechanism = TrueNasAuthMechanism;
3653
3786
  exports.VersionCompatibility = VersionCompatibility;
3654
3787
  exports.VersionDiscovery = VersionDiscovery;