@zelgadis87/utils-core 5.4.5 → 5.4.6

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/.rollup/index.cjs CHANGED
@@ -3883,12 +3883,12 @@ function isUpgradable(obj) {
3883
3883
  *
3884
3884
  * // Step 2: Build the upgrader with type-safe transitions
3885
3885
  * const upgrader = DataUpgraderBuilder.start<V1>()
3886
- * .addTransition<V1, V2>(1, 2, async (data) => ({
3886
+ * .addTransition<V2>(2, async (data) => ({
3887
3887
  * ...data,
3888
3888
  * age: 0,
3889
3889
  * $version: 2
3890
3890
  * }))
3891
- * .addTransition<V2, V3>(2, 3, async (data) => ({
3891
+ * .addTransition<V3>(3, async (data) => ({
3892
3892
  * ...data,
3893
3893
  * email: "",
3894
3894
  * $version: 3
@@ -3900,7 +3900,7 @@ function isUpgradable(obj) {
3900
3900
  * email: "",
3901
3901
  * $version: 3
3902
3902
  * }))
3903
- * .build<V3>(3);
3903
+ * .build(3);
3904
3904
  *
3905
3905
  * // Step 3: Use the upgrader
3906
3906
  * async function loadData(json: string): Promise<V3> {
@@ -3915,32 +3915,34 @@ function isUpgradable(obj) {
3915
3915
  * ```
3916
3916
  */
3917
3917
  class DataUpgraderBuilder {
3918
+ latestVersion;
3918
3919
  transitions;
3919
- constructor(transitions = {}) {
3920
+ constructor(latestVersion, transitions = {}) {
3921
+ this.latestVersion = latestVersion;
3920
3922
  this.transitions = transitions;
3921
3923
  }
3922
3924
  /** Starts building a new DataUpgrader from the lowest version. */
3923
3925
  static start() {
3924
- return new DataUpgraderBuilder();
3926
+ return new DataUpgraderBuilder(1);
3925
3927
  }
3926
3928
  /**
3927
- * Adds a sequential transition from the current version to the next version.
3928
- * Prevents backward transitions and duplicates at compile-time.
3929
+ * Adds a sequential transition from the current latest version to a new version.
3930
+ * Only the new version type needs to be specified.
3929
3931
  *
3930
3932
  * @example
3931
3933
  * ```typescript
3932
- * builder.addTransition<V1, V2>(1, 2, async (d) => ({ ...d, extra: 0, $version: 2 }))
3934
+ * builder.addTransition<V2>(2, async (d) => ({ ...d, extra: 0, $version: 2 }))
3933
3935
  * ```
3934
3936
  */
3935
- addTransition(fromVersion, toVersion, apply) {
3937
+ addTransition(toVersion, apply) {
3936
3938
  const newTransitions = {
3937
3939
  ...this.transitions,
3938
3940
  [toVersion]: {
3939
3941
  ...(this.transitions[toVersion] ?? {}),
3940
- [fromVersion]: { from: fromVersion, to: toVersion, apply: async (d) => apply(d) }
3942
+ [this.latestVersion]: { from: this.latestVersion, to: toVersion, apply: async (d) => apply(d) }
3941
3943
  }
3942
3944
  };
3943
- const builder = new DataUpgraderBuilder(newTransitions);
3945
+ const builder = new DataUpgraderBuilder(toVersion, newTransitions);
3944
3946
  return builder;
3945
3947
  }
3946
3948
  /**
@@ -3960,16 +3962,15 @@ class DataUpgraderBuilder {
3960
3962
  [fromVersion]: { from: fromVersion, to: toVersion, apply: async (d) => apply(d) }
3961
3963
  }
3962
3964
  };
3963
- const builder = new DataUpgraderBuilder(newTransitions);
3965
+ const builder = new DataUpgraderBuilder(this.latestVersion, newTransitions);
3964
3966
  return builder;
3965
3967
  }
3966
3968
  /**
3967
- * Builds the DataUpgrader with the specified latest version.
3968
- * The latest version must be in the accumulated union type.
3969
+ * Builds the DataUpgrader with the current latest version.
3969
3970
  *
3970
3971
  * @example
3971
3972
  * ```typescript
3972
- * const upgrader = builder.build<V3>(3);
3973
+ * const upgrader = builder.build(3);
3973
3974
  * ```
3974
3975
  */
3975
3976
  build(latestVersion) {