@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 +16 -15
- package/.rollup/index.cjs.map +1 -1
- package/.rollup/index.d.ts +18 -16
- package/.rollup/index.mjs +16 -15
- package/.rollup/index.mjs.map +1 -1
- package/.rollup/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +6 -0
- package/package.json +2 -1
- package/src/upgrade/DataUpgraderBuilder.ts +25 -26
- package/src/utils/css.ts +1 -1
- package/src/utils/operations.ts +1 -1
package/.rollup/index.d.ts
CHANGED
|
@@ -1020,7 +1020,7 @@ type TCssSelectorDeclarationRulesDictionary = {
|
|
|
1020
1020
|
[selector: string]: TCssDeclarationRulesDictionary | TCssSelectorDeclarationRulesDictionary;
|
|
1021
1021
|
};
|
|
1022
1022
|
declare function cssDeclarationRulesDictionaryToCss(syleDeclarationRulesForSelectorsProduceable: TProduceable<TCssSelectorDeclarationRulesDictionary>, indent?: number): string;
|
|
1023
|
-
declare function transformCssDictionary(dict: TCssSelectorDeclarationRulesDictionary, transformer: (key: TCssGenericDeclarationKey, value: string) => string): TCssSelectorDeclarationRulesDictionary;
|
|
1023
|
+
declare function transformCssDictionary(dict: TCssDeclarationRulesDictionary | TCssSelectorDeclarationRulesDictionary, transformer: (key: TCssGenericDeclarationKey, value: string) => string): TCssSelectorDeclarationRulesDictionary;
|
|
1024
1024
|
type TProduceable<T> = T | TProducer<T>;
|
|
1025
1025
|
|
|
1026
1026
|
/**
|
|
@@ -1108,7 +1108,7 @@ type TOperationAggregateFlattenedError<E> = E extends OperationAggregateError<in
|
|
|
1108
1108
|
* @param results - Array of operation results to combine
|
|
1109
1109
|
* @returns A single operation with either all data or all aggregated errors (flattened)
|
|
1110
1110
|
*/
|
|
1111
|
-
declare function combine<T, E = Error>(results: TReadableArray<TOperation<T, E
|
|
1111
|
+
declare function combine<T, E = Error>(results: TReadableArray<TOperation<T, E | OperationAggregateError<E>>>): TOperation<T[], OperationAggregateError<TOperationAggregateFlattenedError<E>>>;
|
|
1112
1112
|
declare const Operation: {
|
|
1113
1113
|
ok: <const T>(data: T) => {
|
|
1114
1114
|
readonly success: true;
|
|
@@ -1623,12 +1623,12 @@ type TAddTransition<T extends readonly TTransitionRecord[], From extends number,
|
|
|
1623
1623
|
*
|
|
1624
1624
|
* // Step 2: Build the upgrader with type-safe transitions
|
|
1625
1625
|
* const upgrader = DataUpgraderBuilder.start<V1>()
|
|
1626
|
-
* .addTransition<
|
|
1626
|
+
* .addTransition<V2>(2, async (data) => ({
|
|
1627
1627
|
* ...data,
|
|
1628
1628
|
* age: 0,
|
|
1629
1629
|
* $version: 2
|
|
1630
1630
|
* }))
|
|
1631
|
-
* .addTransition<
|
|
1631
|
+
* .addTransition<V3>(3, async (data) => ({
|
|
1632
1632
|
* ...data,
|
|
1633
1633
|
* email: "",
|
|
1634
1634
|
* $version: 3
|
|
@@ -1640,7 +1640,7 @@ type TAddTransition<T extends readonly TTransitionRecord[], From extends number,
|
|
|
1640
1640
|
* email: "",
|
|
1641
1641
|
* $version: 3
|
|
1642
1642
|
* }))
|
|
1643
|
-
* .build
|
|
1643
|
+
* .build(3);
|
|
1644
1644
|
*
|
|
1645
1645
|
* // Step 3: Use the upgrader
|
|
1646
1646
|
* async function loadData(json: string): Promise<V3> {
|
|
@@ -1654,21 +1654,22 @@ type TAddTransition<T extends readonly TTransitionRecord[], From extends number,
|
|
|
1654
1654
|
* const v3 = await loadData('{"name":"Carol","age":30,"email":"c@example.com","$version":3}'); // → V3
|
|
1655
1655
|
* ```
|
|
1656
1656
|
*/
|
|
1657
|
-
declare class DataUpgraderBuilder<VLowest extends TUpgradable, VUnion extends TUpgradable = VLowest, TTransitions extends readonly TTransitionRecord[] = readonly []> {
|
|
1657
|
+
declare class DataUpgraderBuilder<VLowest extends TUpgradable, VUnion extends TUpgradable = VLowest, VLatest extends TUpgradable = VLowest, TTransitions extends readonly TTransitionRecord[] = readonly []> {
|
|
1658
|
+
private latestVersion;
|
|
1658
1659
|
private transitions;
|
|
1659
1660
|
private constructor();
|
|
1660
1661
|
/** Starts building a new DataUpgrader from the lowest version. */
|
|
1661
|
-
static start<V1 extends TUpgradable>(): DataUpgraderBuilder<V1, V1, readonly []>;
|
|
1662
|
+
static start<V1 extends TUpgradable>(): DataUpgraderBuilder<V1, V1, V1, readonly []>;
|
|
1662
1663
|
/**
|
|
1663
|
-
* Adds a sequential transition from the current version to
|
|
1664
|
-
*
|
|
1664
|
+
* Adds a sequential transition from the current latest version to a new version.
|
|
1665
|
+
* Only the new version type needs to be specified.
|
|
1665
1666
|
*
|
|
1666
1667
|
* @example
|
|
1667
1668
|
* ```typescript
|
|
1668
|
-
* builder.addTransition<
|
|
1669
|
+
* builder.addTransition<V2>(2, async (d) => ({ ...d, extra: 0, $version: 2 }))
|
|
1669
1670
|
* ```
|
|
1670
1671
|
*/
|
|
1671
|
-
addTransition<VNext extends TUpgradable,
|
|
1672
|
+
addTransition<VNext extends TUpgradable, NewUnion extends TUpgradable = VUnion | VNext, LatestNumber extends number = VLatest["$version"], NextNumber extends number = VNext["$version"], NewTransitions extends readonly TTransitionRecord[] = TAddTransition<TTransitions, LatestNumber, NextNumber>>(toVersion: NextNumber, apply: (data: VLatest) => Promise<VNext> | VNext): DataUpgraderBuilder<VLowest, NewUnion, VNext, NewTransitions>;
|
|
1672
1673
|
/**
|
|
1673
1674
|
* Adds a shortcut transition between arbitrary versions.
|
|
1674
1675
|
* Both versions must already be in the accumulated union type.
|
|
@@ -1678,17 +1679,18 @@ declare class DataUpgraderBuilder<VLowest extends TUpgradable, VUnion extends TU
|
|
|
1678
1679
|
* builder.addShortcut<V1, V3>(1, 3, async (d) => ({ ...d, extra: 0, flag: false, $version: 3 }))
|
|
1679
1680
|
* ```
|
|
1680
1681
|
*/
|
|
1681
|
-
addShortcut<VFrom extends TUpgradable & VUnion, VTo extends TUpgradable & VUnion, From extends number = VFrom["$version"], To extends number = VTo["$version"], NewTransitions extends readonly TTransitionRecord[] = TAddTransition<TTransitions, From, To>>(fromVersion: From, toVersion: To, apply: (data: VFrom) => Promise<VTo> | VTo): DataUpgraderBuilder<VLowest, VUnion, NewTransitions>;
|
|
1682
|
+
addShortcut<VFrom extends TUpgradable & VUnion, VTo extends TUpgradable & VUnion, From extends number = VFrom["$version"], To extends number = VTo["$version"], NewTransitions extends readonly TTransitionRecord[] = TAddTransition<TTransitions, From, To>>(fromVersion: From, toVersion: To, apply: (data: VFrom) => Promise<VTo> | VTo): DataUpgraderBuilder<VLowest, VUnion, VLatest, NewTransitions>;
|
|
1682
1683
|
/**
|
|
1683
|
-
* Builds the DataUpgrader with the
|
|
1684
|
-
* The latest version must be in the accumulated union type.
|
|
1684
|
+
* Builds the DataUpgrader with the current latest version.
|
|
1685
1685
|
*
|
|
1686
1686
|
* @example
|
|
1687
1687
|
* ```typescript
|
|
1688
|
-
* const upgrader = builder.build
|
|
1688
|
+
* const upgrader = builder.build(3);
|
|
1689
1689
|
* ```
|
|
1690
1690
|
*/
|
|
1691
|
-
build
|
|
1691
|
+
build(latestVersion: VLatest["$version"]): DataUpgrader<VUnion, Extract<VUnion, {
|
|
1692
|
+
$version: VLatest["$version"];
|
|
1693
|
+
}>>;
|
|
1692
1694
|
/** @internal */
|
|
1693
1695
|
getTransitions(): Record<number, Record<number, {
|
|
1694
1696
|
from: number;
|
package/.rollup/index.mjs
CHANGED
|
@@ -3881,12 +3881,12 @@ function isUpgradable(obj) {
|
|
|
3881
3881
|
*
|
|
3882
3882
|
* // Step 2: Build the upgrader with type-safe transitions
|
|
3883
3883
|
* const upgrader = DataUpgraderBuilder.start<V1>()
|
|
3884
|
-
* .addTransition<
|
|
3884
|
+
* .addTransition<V2>(2, async (data) => ({
|
|
3885
3885
|
* ...data,
|
|
3886
3886
|
* age: 0,
|
|
3887
3887
|
* $version: 2
|
|
3888
3888
|
* }))
|
|
3889
|
-
* .addTransition<
|
|
3889
|
+
* .addTransition<V3>(3, async (data) => ({
|
|
3890
3890
|
* ...data,
|
|
3891
3891
|
* email: "",
|
|
3892
3892
|
* $version: 3
|
|
@@ -3898,7 +3898,7 @@ function isUpgradable(obj) {
|
|
|
3898
3898
|
* email: "",
|
|
3899
3899
|
* $version: 3
|
|
3900
3900
|
* }))
|
|
3901
|
-
* .build
|
|
3901
|
+
* .build(3);
|
|
3902
3902
|
*
|
|
3903
3903
|
* // Step 3: Use the upgrader
|
|
3904
3904
|
* async function loadData(json: string): Promise<V3> {
|
|
@@ -3913,32 +3913,34 @@ function isUpgradable(obj) {
|
|
|
3913
3913
|
* ```
|
|
3914
3914
|
*/
|
|
3915
3915
|
class DataUpgraderBuilder {
|
|
3916
|
+
latestVersion;
|
|
3916
3917
|
transitions;
|
|
3917
|
-
constructor(transitions = {}) {
|
|
3918
|
+
constructor(latestVersion, transitions = {}) {
|
|
3919
|
+
this.latestVersion = latestVersion;
|
|
3918
3920
|
this.transitions = transitions;
|
|
3919
3921
|
}
|
|
3920
3922
|
/** Starts building a new DataUpgrader from the lowest version. */
|
|
3921
3923
|
static start() {
|
|
3922
|
-
return new DataUpgraderBuilder();
|
|
3924
|
+
return new DataUpgraderBuilder(1);
|
|
3923
3925
|
}
|
|
3924
3926
|
/**
|
|
3925
|
-
* Adds a sequential transition from the current version to
|
|
3926
|
-
*
|
|
3927
|
+
* Adds a sequential transition from the current latest version to a new version.
|
|
3928
|
+
* Only the new version type needs to be specified.
|
|
3927
3929
|
*
|
|
3928
3930
|
* @example
|
|
3929
3931
|
* ```typescript
|
|
3930
|
-
* builder.addTransition<
|
|
3932
|
+
* builder.addTransition<V2>(2, async (d) => ({ ...d, extra: 0, $version: 2 }))
|
|
3931
3933
|
* ```
|
|
3932
3934
|
*/
|
|
3933
|
-
addTransition(
|
|
3935
|
+
addTransition(toVersion, apply) {
|
|
3934
3936
|
const newTransitions = {
|
|
3935
3937
|
...this.transitions,
|
|
3936
3938
|
[toVersion]: {
|
|
3937
3939
|
...(this.transitions[toVersion] ?? {}),
|
|
3938
|
-
[
|
|
3940
|
+
[this.latestVersion]: { from: this.latestVersion, to: toVersion, apply: async (d) => apply(d) }
|
|
3939
3941
|
}
|
|
3940
3942
|
};
|
|
3941
|
-
const builder = new DataUpgraderBuilder(newTransitions);
|
|
3943
|
+
const builder = new DataUpgraderBuilder(toVersion, newTransitions);
|
|
3942
3944
|
return builder;
|
|
3943
3945
|
}
|
|
3944
3946
|
/**
|
|
@@ -3958,16 +3960,15 @@ class DataUpgraderBuilder {
|
|
|
3958
3960
|
[fromVersion]: { from: fromVersion, to: toVersion, apply: async (d) => apply(d) }
|
|
3959
3961
|
}
|
|
3960
3962
|
};
|
|
3961
|
-
const builder = new DataUpgraderBuilder(newTransitions);
|
|
3963
|
+
const builder = new DataUpgraderBuilder(this.latestVersion, newTransitions);
|
|
3962
3964
|
return builder;
|
|
3963
3965
|
}
|
|
3964
3966
|
/**
|
|
3965
|
-
* Builds the DataUpgrader with the
|
|
3966
|
-
* The latest version must be in the accumulated union type.
|
|
3967
|
+
* Builds the DataUpgrader with the current latest version.
|
|
3967
3968
|
*
|
|
3968
3969
|
* @example
|
|
3969
3970
|
* ```typescript
|
|
3970
|
-
* const upgrader = builder.build
|
|
3971
|
+
* const upgrader = builder.build(3);
|
|
3971
3972
|
* ```
|
|
3972
3973
|
*/
|
|
3973
3974
|
build(latestVersion) {
|