@truenas/api-client 3.0.0 → 3.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/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.),
@@ -3224,6 +3233,68 @@ function toContainer2(container) {
3224
3233
  description
3225
3234
  };
3226
3235
  }
3236
+ var TrueNasApiClientV27 = class extends TrueNasApiClient {
3237
+ /**
3238
+ * Create v27-specific operation mappings
3239
+ *
3240
+ * Operations return Observable<Job | null>:
3241
+ * - Async operations emit Job updates until complete
3242
+ * - Sync operations emit null once
3243
+ */
3244
+ createOperations() {
3245
+ return {
3246
+ // A polymorphic `.query`, so it goes through the verb rather than
3247
+ // `call`: the directory types the raw method's response as the five-way
3248
+ // union the server may return, and the verb is what fixes it to a list.
3249
+ containerQuery: () => this.api.query("container.query").pipe(
3250
+ rxjs.map((containers) => containers.map(toContainer3))
3251
+ ),
3252
+ // container.start is synchronous in v27 - emit null
3253
+ containerStart: (id) => this.api.call("container.start", [parseInt(id, 10)]).pipe(rxjs.map(() => null)),
3254
+ // container.stop emits job updates
3255
+ containerStop: (id, options) => this.api.job("container.stop", [
3256
+ parseInt(id, 10),
3257
+ {
3258
+ force: options.force,
3259
+ force_after_timeout: options.force
3260
+ }
3261
+ ]),
3262
+ // v27 still has no container.restart - chain stop + start.
3263
+ // Emits Job updates during stop, then null when start completes.
3264
+ containerRestart: (id, options) => {
3265
+ const numericId = parseInt(id, 10);
3266
+ return this.api.job("container.stop", [
3267
+ numericId,
3268
+ {
3269
+ force: options.force,
3270
+ force_after_timeout: options.force
3271
+ }
3272
+ ]).pipe(
3273
+ // Collect all job updates to ensure stop fully completes
3274
+ rxjs.toArray(),
3275
+ // Re-emit job updates, then call start after stop is done
3276
+ rxjs.switchMap(
3277
+ (jobUpdates) => rxjs.concat(
3278
+ rxjs.from(jobUpdates),
3279
+ this.api.call("container.start", [numericId]).pipe(rxjs.map(() => null))
3280
+ )
3281
+ )
3282
+ );
3283
+ }
3284
+ };
3285
+ }
3286
+ };
3287
+ function toContainer3(container) {
3288
+ const { description } = container;
3289
+ return {
3290
+ id: container.id.toString(),
3291
+ name: container.name,
3292
+ status: toAppState(container.status.state),
3293
+ // Optional in the generated entry, required by `Container`.
3294
+ autostart: container.autostart ?? false,
3295
+ description
3296
+ };
3297
+ }
3227
3298
 
3228
3299
  // src/errors/version-discovery.errors.ts
3229
3300
  var VersionDiscoveryError = class extends Error {
@@ -3593,7 +3664,8 @@ function selectRepresentativeFailure(failures) {
3593
3664
  }
3594
3665
  var CLIENT_BY_VERSION_KEY = {
3595
3666
  "25.10": TrueNasApiClientV2510,
3596
- "26": TrueNasApiClientV26
3667
+ "26": TrueNasApiClientV26,
3668
+ "27": TrueNasApiClientV27
3597
3669
  };
3598
3670
  function clientVersionKey(version) {
3599
3671
  if (version.year <= legacyCutoffYear) {
@@ -3649,6 +3721,7 @@ exports.SUPPORTED_API_VERSIONS = SUPPORTED_API_VERSIONS;
3649
3721
  exports.TrueNasApiClient = TrueNasApiClient;
3650
3722
  exports.TrueNasApiClientV2510 = TrueNasApiClientV2510;
3651
3723
  exports.TrueNasApiClientV26 = TrueNasApiClientV26;
3724
+ exports.TrueNasApiClientV27 = TrueNasApiClientV27;
3652
3725
  exports.TrueNasAuthMechanism = TrueNasAuthMechanism;
3653
3726
  exports.VersionCompatibility = VersionCompatibility;
3654
3727
  exports.VersionDiscovery = VersionDiscovery;