@truenas/api-client 2.0.1 → 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
@@ -2521,7 +2521,6 @@ __export(v26_0_0_exports, {
2521
2521
  Aclmode: () => Aclmode,
2522
2522
  Acltype: () => Acltype,
2523
2523
  Advpowermgmt: () => Advpowermgmt,
2524
- Algorithm: () => Algorithm,
2525
2524
  AppContainerDetailsState: () => AppContainerDetailsState,
2526
2525
  AppContainerDetailsStateInput: () => AppContainerDetailsStateInput,
2527
2526
  Atime: () => Atime,
@@ -2659,11 +2658,13 @@ var ContainerNICDeviceTypeInput = {
2659
2658
  };
2660
2659
  var ContainerStatusState = {
2661
2660
  Running: "RUNNING",
2662
- Stopped: "STOPPED"
2661
+ Stopped: "STOPPED",
2662
+ Suspended: "SUSPENDED"
2663
2663
  };
2664
2664
  var ContainerStatusStateInput = {
2665
2665
  Running: "RUNNING",
2666
- Stopped: "STOPPED"
2666
+ Stopped: "STOPPED",
2667
+ Suspended: "SUSPENDED"
2667
2668
  };
2668
2669
  var Feature2 = {
2669
2670
  Apps: "APPS",
@@ -2743,7 +2744,6 @@ __export(v27_0_0_exports, {
2743
2744
  Aclmode: () => Aclmode,
2744
2745
  Acltype: () => Acltype,
2745
2746
  Advpowermgmt: () => Advpowermgmt,
2746
- Algorithm: () => Algorithm,
2747
2747
  AppContainerDetailsState: () => AppContainerDetailsState,
2748
2748
  AppContainerDetailsStateInput: () => AppContainerDetailsStateInput,
2749
2749
  Atime: () => Atime,
@@ -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.),
@@ -3066,6 +3075,10 @@ var AppState = /* @__PURE__ */ ((AppState2) => {
3066
3075
  AppState2["Stopped"] = "STOPPED";
3067
3076
  AppState2["Stopping"] = "STOPPING";
3068
3077
  AppState2["Deploying"] = "DEPLOYING";
3078
+ AppState2["Suspended"] = "SUSPENDED";
3079
+ AppState2["Suspending"] = "SUSPENDING";
3080
+ AppState2["Error"] = "ERROR";
3081
+ AppState2["Unknown"] = "UNKNOWN";
3069
3082
  return AppState2;
3070
3083
  })(AppState || {});
3071
3084
 
@@ -3076,7 +3089,10 @@ function toAppState(state) {
3076
3089
  return "RUNNING" /* Running */;
3077
3090
  case "STOPPED":
3078
3091
  return "STOPPED" /* Stopped */;
3092
+ // `ABORTING` is v25.10 only: the instance is being forced down, which ends
3093
+ // at `STOPPED` and is what `Stopping` already means.
3079
3094
  case "STOPPING":
3095
+ case "ABORTING":
3080
3096
  return "STOPPING" /* Stopping */;
3081
3097
  // `STARTING` is v25.10 `virt.instance` only, and folding it into `Stopped`
3082
3098
  // told callers a container that is coming up is at rest — enough for a UI
@@ -3085,8 +3101,35 @@ function toAppState(state) {
3085
3101
  case "STARTING":
3086
3102
  case "DEPLOYING":
3087
3103
  return "DEPLOYING" /* Deploying */;
3104
+ // v25.10's freezer states are the same idea as v26's `SUSPENDED`: the
3105
+ // processes are paused, not exited. `FROZEN` is that pause completed, so it
3106
+ // and `SUSPENDED` are the same answer.
3107
+ case "SUSPENDED":
3108
+ case "FROZEN":
3109
+ return "SUSPENDED" /* Suspended */;
3110
+ // `FREEZING` is on the way there and not there yet. It used to answer
3111
+ // `Suspended`, defended by analogy with `STARTING` — but `STARTING` maps to
3112
+ // `Deploying`, which is itself an in-progress word, so the analogy ran the
3113
+ // wrong way. Answering `Suspended` tells a caller polling for "the memory
3114
+ // is quiesced" that it is, one poll before it is true: the same false
3115
+ // claim this mapping was rewritten to stop making, one state along.
3116
+ // `ABORTING` had `Stopping` to land on; the freeze path needed its own.
3117
+ case "FREEZING":
3118
+ return "SUSPENDING" /* Suspending */;
3119
+ // `THAWED` is the freezer lifted: the processes are scheduled again, so
3120
+ // this is `RUNNING` reported through the transition rather than a state a
3121
+ // caller should act on differently.
3122
+ case "THAWED":
3123
+ return "RUNNING" /* Running */;
3124
+ case "ERROR":
3125
+ return "ERROR" /* Error */;
3126
+ // `UNKNOWN` is middleware's own word for it, and anything unrecognised is
3127
+ // the same situation: a state this mapping has no word for. Neither is
3128
+ // evidence the container is stopped.
3129
+ case "UNKNOWN":
3130
+ return "UNKNOWN" /* Unknown */;
3088
3131
  default:
3089
- return "STOPPED" /* Stopped */;
3132
+ return "UNKNOWN" /* Unknown */;
3090
3133
  }
3091
3134
  }
3092
3135
 
@@ -3190,6 +3233,68 @@ function toContainer2(container) {
3190
3233
  description
3191
3234
  };
3192
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
+ }
3193
3298
 
3194
3299
  // src/errors/version-discovery.errors.ts
3195
3300
  var VersionDiscoveryError = class extends Error {
@@ -3559,7 +3664,8 @@ function selectRepresentativeFailure(failures) {
3559
3664
  }
3560
3665
  var CLIENT_BY_VERSION_KEY = {
3561
3666
  "25.10": TrueNasApiClientV2510,
3562
- "26": TrueNasApiClientV26
3667
+ "26": TrueNasApiClientV26,
3668
+ "27": TrueNasApiClientV27
3563
3669
  };
3564
3670
  function clientVersionKey(version) {
3565
3671
  if (version.year <= legacyCutoffYear) {
@@ -3615,6 +3721,7 @@ exports.SUPPORTED_API_VERSIONS = SUPPORTED_API_VERSIONS;
3615
3721
  exports.TrueNasApiClient = TrueNasApiClient;
3616
3722
  exports.TrueNasApiClientV2510 = TrueNasApiClientV2510;
3617
3723
  exports.TrueNasApiClientV26 = TrueNasApiClientV26;
3724
+ exports.TrueNasApiClientV27 = TrueNasApiClientV27;
3618
3725
  exports.TrueNasAuthMechanism = TrueNasAuthMechanism;
3619
3726
  exports.VersionCompatibility = VersionCompatibility;
3620
3727
  exports.VersionDiscovery = VersionDiscovery;