@griffin-app/griffin-ts 0.1.10 → 0.1.11
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/package.json +1 -1
- package/src/migrations.test.ts +2 -5
- package/src/migrations.ts +16 -14
- package/src/schema-exports.ts +1 -0
package/package.json
CHANGED
package/src/migrations.test.ts
CHANGED
|
@@ -9,10 +9,7 @@ import {
|
|
|
9
9
|
isSupportedVersion,
|
|
10
10
|
getSupportedVersions,
|
|
11
11
|
} from "./migrations.js";
|
|
12
|
-
import {
|
|
13
|
-
CURRENT_PLAN_VERSION,
|
|
14
|
-
SUPPORTED_PLAN_VERSIONS,
|
|
15
|
-
} from "./schema.js";
|
|
12
|
+
import { CURRENT_PLAN_VERSION, SUPPORTED_PLAN_VERSIONS } from "./schema.js";
|
|
16
13
|
import type { ResolvedPlanV1 } from "./schema.js";
|
|
17
14
|
|
|
18
15
|
describe("migrations", () => {
|
|
@@ -144,7 +141,7 @@ describe("migrations", () => {
|
|
|
144
141
|
// expect(v2Plan.version).toBe("2.0");
|
|
145
142
|
// expect(v2Plan.name).toBe(v1Plan.name);
|
|
146
143
|
// // Add assertions for new v2 fields
|
|
147
|
-
|
|
144
|
+
|
|
148
145
|
expect(true).toBe(true); // Placeholder
|
|
149
146
|
});
|
|
150
147
|
});
|
package/src/migrations.ts
CHANGED
|
@@ -26,21 +26,23 @@ const migrations: Record<string, MigrationFn<any, any>> = {
|
|
|
26
26
|
function getNextVersion(currentVersion: string): string {
|
|
27
27
|
const versions = SUPPORTED_PLAN_VERSIONS as readonly string[];
|
|
28
28
|
const currentIndex = versions.indexOf(currentVersion);
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
if (currentIndex === -1) {
|
|
31
31
|
throw new Error(`Unsupported plan version: ${currentVersion}`);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
if (currentIndex === versions.length - 1) {
|
|
35
|
-
throw new Error(
|
|
35
|
+
throw new Error(
|
|
36
|
+
`No migration path available from version ${currentVersion}`,
|
|
37
|
+
);
|
|
36
38
|
}
|
|
37
|
-
|
|
39
|
+
|
|
38
40
|
return versions[currentIndex + 1];
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/**
|
|
42
44
|
* Migrate a plan from its current version to a target version
|
|
43
|
-
*
|
|
45
|
+
*
|
|
44
46
|
* @param plan - Plan to migrate (must have a version field)
|
|
45
47
|
* @param targetVersion - Target version to migrate to
|
|
46
48
|
* @returns Migrated plan at target version
|
|
@@ -51,33 +53,33 @@ export function migratePlan<T>(
|
|
|
51
53
|
targetVersion: string,
|
|
52
54
|
): T {
|
|
53
55
|
let current: any = plan;
|
|
54
|
-
|
|
56
|
+
|
|
55
57
|
// Already at target version
|
|
56
58
|
if (current.version === targetVersion) {
|
|
57
59
|
return current as T;
|
|
58
60
|
}
|
|
59
|
-
|
|
61
|
+
|
|
60
62
|
// Migrate step by step through versions
|
|
61
63
|
while (current.version !== targetVersion) {
|
|
62
64
|
const nextVersion = getNextVersion(current.version);
|
|
63
65
|
const migrationKey = `${current.version}->${nextVersion}`;
|
|
64
66
|
const migrate = migrations[migrationKey];
|
|
65
|
-
|
|
67
|
+
|
|
66
68
|
if (!migrate) {
|
|
67
69
|
throw new Error(
|
|
68
70
|
`No migration path from version ${current.version} to ${nextVersion}`,
|
|
69
71
|
);
|
|
70
72
|
}
|
|
71
|
-
|
|
73
|
+
|
|
72
74
|
current = migrate(current);
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
|
|
75
77
|
return current as T;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
/**
|
|
79
81
|
* Migrate a plan to the latest supported version
|
|
80
|
-
*
|
|
82
|
+
*
|
|
81
83
|
* @param plan - Plan to migrate (must have a version field)
|
|
82
84
|
* @returns Plan migrated to latest version
|
|
83
85
|
*/
|
|
@@ -87,7 +89,7 @@ export function migrateToLatest(plan: { version: string }): ResolvedPlan {
|
|
|
87
89
|
|
|
88
90
|
/**
|
|
89
91
|
* Check if a plan version is supported
|
|
90
|
-
*
|
|
92
|
+
*
|
|
91
93
|
* @param version - Version string to check
|
|
92
94
|
* @returns True if version is supported
|
|
93
95
|
*/
|
|
@@ -104,9 +106,9 @@ export function getSupportedVersions(): readonly string[] {
|
|
|
104
106
|
|
|
105
107
|
/**
|
|
106
108
|
* Example migration function template (for future use)
|
|
107
|
-
*
|
|
109
|
+
*
|
|
108
110
|
* Uncomment and modify when creating v2.0:
|
|
109
|
-
*
|
|
111
|
+
*
|
|
110
112
|
* function migrateV1ToV2(plan: ResolvedPlanV1): ResolvedPlanV2 {
|
|
111
113
|
* return {
|
|
112
114
|
* ...plan,
|