@pipelab/shared 1.0.0-beta.1 → 1.0.0-beta.3
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/CHANGELOG.md +16 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +60 -89
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/config/migrators.ts +65 -82
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipelab/shared",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared logic and types for the Pipelab ecosystem",
|
|
6
6
|
"license": "FSL-1.1-MIT",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"tslog": "4.9.3",
|
|
38
38
|
"type-fest": "4.26.1",
|
|
39
39
|
"valibot": "0.42.1",
|
|
40
|
-
"@pipelab/migration": "1.0.0-beta.
|
|
40
|
+
"@pipelab/migration": "1.0.0-beta.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"esbuild-plugin-wasm": "1.1.0",
|
|
44
44
|
"tsdown": "0.21.2",
|
|
45
45
|
"typescript": "5.9.3",
|
|
46
|
-
"@pipelab/tsconfig": "1.0.0-beta.
|
|
46
|
+
"@pipelab/tsconfig": "1.0.0-beta.3"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsdown",
|
package/src/config/migrators.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createMigration,
|
|
2
|
+
createMigration as createMigrationBase,
|
|
3
3
|
createMigrator,
|
|
4
4
|
finalVersion,
|
|
5
|
-
initialVersion,
|
|
6
5
|
OmitVersion,
|
|
7
6
|
SemVer,
|
|
7
|
+
Awaitable,
|
|
8
|
+
MigrationSchema,
|
|
8
9
|
} from "@pipelab/migration";
|
|
9
10
|
import {
|
|
10
11
|
AppConfig,
|
|
@@ -21,6 +22,13 @@ import { SavedFileV1, SavedFileV2, SavedFileV3, SavedFileV4, SavedFile } from ".
|
|
|
21
22
|
|
|
22
23
|
// --- Types ---
|
|
23
24
|
|
|
25
|
+
export type Additive<T, P> = OmitVersion<T> & OmitVersion<P>;
|
|
26
|
+
|
|
27
|
+
const createMigration = <From extends MigrationSchema, To extends MigrationSchema>(config: {
|
|
28
|
+
version: SemVer;
|
|
29
|
+
up: (state: OmitVersion<From>, targetVersion: string) => Awaitable<Additive<To, From>>;
|
|
30
|
+
}) => createMigrationBase<From, To>(config);
|
|
31
|
+
|
|
24
32
|
export interface Migrator<T> {
|
|
25
33
|
migrate: (data: any, options?: any) => Promise<T>;
|
|
26
34
|
defaultValue: T;
|
|
@@ -31,11 +39,9 @@ export interface Migrator<T> {
|
|
|
31
39
|
const settingsMigratorInternal = createMigrator<AppConfigV1, AppConfig>();
|
|
32
40
|
|
|
33
41
|
export const defaultAppSettings = settingsMigratorInternal.createDefault({
|
|
34
|
-
cacheFolder: "",
|
|
35
|
-
clearTemporaryFoldersOnPipelineEnd: false,
|
|
36
42
|
locale: "en-US",
|
|
37
43
|
theme: "light",
|
|
38
|
-
version: "7.0.0"
|
|
44
|
+
version: "7.0.0",
|
|
39
45
|
autosave: true,
|
|
40
46
|
agents: [],
|
|
41
47
|
tours: {
|
|
@@ -48,40 +54,39 @@ export const defaultAppSettings = settingsMigratorInternal.createDefault({
|
|
|
48
54
|
completed: false,
|
|
49
55
|
},
|
|
50
56
|
},
|
|
57
|
+
buildHistory: {
|
|
58
|
+
retentionPolicy: {
|
|
59
|
+
enabled: false,
|
|
60
|
+
maxEntries: 50,
|
|
61
|
+
maxAge: 30,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
51
64
|
});
|
|
52
65
|
|
|
53
66
|
export const appSettingsMigrator = settingsMigratorInternal.createMigrations({
|
|
54
67
|
defaultValue: defaultAppSettings,
|
|
55
68
|
migrations: [
|
|
56
|
-
createMigration<
|
|
69
|
+
createMigration<AppConfigV1, AppConfigV2>({
|
|
57
70
|
version: "1.0.0" as SemVer,
|
|
58
|
-
up: (state) => state
|
|
59
|
-
down: initialVersion,
|
|
71
|
+
up: (state) => state,
|
|
60
72
|
}),
|
|
61
|
-
createMigration<
|
|
73
|
+
createMigration<AppConfigV2, AppConfigV3>({
|
|
62
74
|
version: "2.0.0" as SemVer,
|
|
63
75
|
up: (state) => {
|
|
64
76
|
return {
|
|
65
77
|
...state,
|
|
66
78
|
clearTemporaryFoldersOnPipelineEnd: false,
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
down: () => {
|
|
70
|
-
throw new Error("Can't migrate down from 2.0.0");
|
|
79
|
+
};
|
|
71
80
|
},
|
|
72
81
|
}),
|
|
73
|
-
createMigration<
|
|
82
|
+
createMigration<AppConfigV3, AppConfigV4>({
|
|
74
83
|
version: "3.0.0" as SemVer,
|
|
75
84
|
up: (state) => ({
|
|
76
85
|
...state,
|
|
77
86
|
locale: "en-US" as const,
|
|
78
87
|
}),
|
|
79
|
-
down: (state) => {
|
|
80
|
-
const { locale, ...rest } = state as AppConfigV4;
|
|
81
|
-
return rest as unknown as AppConfigV3;
|
|
82
|
-
},
|
|
83
88
|
}),
|
|
84
|
-
createMigration<
|
|
89
|
+
createMigration<AppConfigV4, AppConfigV5>({
|
|
85
90
|
version: "4.0.0" as SemVer,
|
|
86
91
|
up: (state) => ({
|
|
87
92
|
...state,
|
|
@@ -96,39 +101,35 @@ export const appSettingsMigrator = settingsMigratorInternal.createMigrations({
|
|
|
96
101
|
},
|
|
97
102
|
},
|
|
98
103
|
}),
|
|
99
|
-
down: (state) => {
|
|
100
|
-
const { tours, ...rest } = state as AppConfigV5;
|
|
101
|
-
return rest as unknown as AppConfigV4;
|
|
102
|
-
},
|
|
103
104
|
}),
|
|
104
|
-
createMigration<
|
|
105
|
+
createMigration<AppConfigV5, AppConfigV6>({
|
|
105
106
|
version: "5.0.0" as SemVer,
|
|
106
107
|
up: (state) => ({
|
|
107
108
|
...state,
|
|
108
109
|
autosave: true,
|
|
109
110
|
}),
|
|
110
|
-
down: (state) => {
|
|
111
|
-
const { autosave, ...rest } = state as AppConfigV6;
|
|
112
|
-
return rest as unknown as AppConfigV5;
|
|
113
|
-
},
|
|
114
111
|
}),
|
|
115
|
-
createMigration<
|
|
112
|
+
createMigration<AppConfigV6, AppConfigV7>({
|
|
116
113
|
version: "6.0.0" as SemVer,
|
|
117
|
-
up: (state) =>
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
up: (state) => {
|
|
115
|
+
// Upgrades V6 to V7: Add agents, add buildHistory.
|
|
116
|
+
// (Additive only - keeping cacheFolder and clearTemporaryFoldersOnPipelineEnd)
|
|
117
|
+
return {
|
|
118
|
+
...state,
|
|
119
|
+
agents: [],
|
|
120
|
+
buildHistory: {
|
|
121
|
+
retentionPolicy: {
|
|
122
|
+
enabled: false,
|
|
123
|
+
maxEntries: 50,
|
|
124
|
+
maxAge: 30,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
};
|
|
124
128
|
},
|
|
125
129
|
}),
|
|
126
|
-
createMigration<
|
|
130
|
+
createMigration<AppConfigV7, never>({
|
|
127
131
|
version: "7.0.0" as SemVer,
|
|
128
132
|
up: finalVersion,
|
|
129
|
-
down: () => {
|
|
130
|
-
throw new Error("Can't migrate down from 7.0.0");
|
|
131
|
-
},
|
|
132
133
|
}),
|
|
133
134
|
],
|
|
134
135
|
});
|
|
@@ -147,13 +148,12 @@ export const defaultFileRepo = fileRepoMigratorInternal.createDefault({
|
|
|
147
148
|
},
|
|
148
149
|
],
|
|
149
150
|
pipelines: [],
|
|
150
|
-
proxies: [],
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
export const fileRepoMigrations = fileRepoMigratorInternal.createMigrations({
|
|
154
154
|
defaultValue: defaultFileRepo,
|
|
155
155
|
migrations: [
|
|
156
|
-
createMigration<
|
|
156
|
+
createMigration<FileRepoV1, FileRepoV2>({
|
|
157
157
|
version: "1.0.0",
|
|
158
158
|
up: (state) => {
|
|
159
159
|
const pipelines: FileRepoV2["pipelines"] = Object.entries(state.data || {}).map(
|
|
@@ -166,7 +166,7 @@ export const fileRepoMigrations = fileRepoMigratorInternal.createMigrations({
|
|
|
166
166
|
},
|
|
167
167
|
);
|
|
168
168
|
return {
|
|
169
|
-
|
|
169
|
+
...state,
|
|
170
170
|
projects: [
|
|
171
171
|
{
|
|
172
172
|
id: "main",
|
|
@@ -175,17 +175,12 @@ export const fileRepoMigrations = fileRepoMigratorInternal.createMigrations({
|
|
|
175
175
|
},
|
|
176
176
|
],
|
|
177
177
|
pipelines: pipelines,
|
|
178
|
-
|
|
179
|
-
} as any;
|
|
178
|
+
};
|
|
180
179
|
},
|
|
181
|
-
down: initialVersion,
|
|
182
180
|
}),
|
|
183
|
-
createMigration<
|
|
181
|
+
createMigration<FileRepoV2, never>({
|
|
184
182
|
version: "2.0.0",
|
|
185
183
|
up: finalVersion,
|
|
186
|
-
down: (state) => {
|
|
187
|
-
throw new Error("Cannot downgrade to version 1.0.0");
|
|
188
|
-
},
|
|
189
184
|
}),
|
|
190
185
|
],
|
|
191
186
|
});
|
|
@@ -202,19 +197,19 @@ const savedFileDefaultValue = savedFileMigratorInternal.createDefault({
|
|
|
202
197
|
name: "",
|
|
203
198
|
variables: [],
|
|
204
199
|
type: "default",
|
|
205
|
-
version: "4.0.0"
|
|
200
|
+
version: "4.0.0",
|
|
206
201
|
});
|
|
207
202
|
|
|
208
203
|
export const savedFileMigrator = savedFileMigratorInternal.createMigrations({
|
|
209
204
|
defaultValue: savedFileDefaultValue,
|
|
210
205
|
migrations: [
|
|
211
|
-
createMigration<
|
|
206
|
+
createMigration<SavedFileV1, SavedFileV2>({
|
|
212
207
|
version: "1.0.0" as SemVer,
|
|
213
208
|
up: (state) => {
|
|
214
209
|
const blocks = state.canvas.blocks;
|
|
215
210
|
|
|
216
|
-
const triggers:
|
|
217
|
-
const newBlocks:
|
|
211
|
+
const triggers: SavedFileV2["canvas"]["triggers"] = [];
|
|
212
|
+
const newBlocks: SavedFileV2["canvas"]["blocks"] = [];
|
|
218
213
|
|
|
219
214
|
for (const block of blocks) {
|
|
220
215
|
if (block.type === "event") {
|
|
@@ -225,27 +220,25 @@ export const savedFileMigrator = savedFileMigratorInternal.createMigrations({
|
|
|
225
220
|
}
|
|
226
221
|
|
|
227
222
|
return {
|
|
223
|
+
...state,
|
|
228
224
|
canvas: {
|
|
225
|
+
...state.canvas,
|
|
229
226
|
blocks: newBlocks,
|
|
230
227
|
triggers: triggers,
|
|
231
228
|
},
|
|
232
|
-
|
|
233
|
-
name: state.name,
|
|
234
|
-
variables: state.variables,
|
|
235
|
-
} as any;
|
|
229
|
+
};
|
|
236
230
|
},
|
|
237
|
-
down: initialVersion,
|
|
238
231
|
}),
|
|
239
|
-
createMigration<
|
|
232
|
+
createMigration<SavedFileV2, SavedFileV3>({
|
|
240
233
|
version: "2.0.0" as SemVer,
|
|
241
234
|
up: (state) => {
|
|
242
|
-
const { canvas
|
|
235
|
+
const { canvas } = state;
|
|
243
236
|
const { blocks, triggers } = canvas;
|
|
244
237
|
|
|
245
|
-
const newBlocks:
|
|
238
|
+
const newBlocks: SavedFileV3["canvas"]["blocks"] = [];
|
|
246
239
|
|
|
247
240
|
for (const block of blocks) {
|
|
248
|
-
const newParams:
|
|
241
|
+
const newParams: SavedFileV3["canvas"]["blocks"][number]["params"] = {};
|
|
249
242
|
|
|
250
243
|
for (const data of Object.entries(block.params)) {
|
|
251
244
|
if (data === undefined) {
|
|
@@ -266,35 +259,25 @@ export const savedFileMigrator = savedFileMigratorInternal.createMigrations({
|
|
|
266
259
|
}
|
|
267
260
|
|
|
268
261
|
return {
|
|
269
|
-
...
|
|
262
|
+
...state,
|
|
270
263
|
canvas: {
|
|
264
|
+
...canvas,
|
|
271
265
|
triggers,
|
|
272
266
|
blocks: newBlocks,
|
|
273
267
|
},
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
down: () => {
|
|
277
|
-
throw new Error("Migration down not implemented");
|
|
268
|
+
};
|
|
278
269
|
},
|
|
279
270
|
}),
|
|
280
|
-
createMigration<
|
|
271
|
+
createMigration<SavedFileV3, SavedFileV4>({
|
|
281
272
|
version: "3.0.0" as SemVer,
|
|
282
|
-
up: (state) => {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
} as any;
|
|
287
|
-
},
|
|
288
|
-
down: () => {
|
|
289
|
-
throw new Error("Migration down not implemented");
|
|
290
|
-
},
|
|
273
|
+
up: (state) => ({
|
|
274
|
+
...state,
|
|
275
|
+
type: "default",
|
|
276
|
+
}),
|
|
291
277
|
}),
|
|
292
|
-
createMigration<
|
|
278
|
+
createMigration<SavedFileV4, never>({
|
|
293
279
|
version: "4.0.0" as SemVer,
|
|
294
280
|
up: finalVersion,
|
|
295
|
-
down: () => {
|
|
296
|
-
throw new Error("Migration down not implemented");
|
|
297
|
-
},
|
|
298
281
|
}),
|
|
299
282
|
],
|
|
300
283
|
});
|