-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration to store switch branch conditions as constvalues
- Loading branch information
1 parent
df79286
commit 5f93128
Showing
19 changed files
with
1,226 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/lib/project/migrateLegacyProject.ts → .../migration/legacy/migrateLegacyProject.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { CompressedProjectResources } from "shared/lib/resources/types"; | ||
import { | ||
ProjectResourcesMigration, | ||
applyProjectResourcesMigration, | ||
} from "./helpers"; | ||
import { migrate410r1To420r1 } from "./versions/410to420"; | ||
|
||
const migrations: ProjectResourcesMigration[] = [ | ||
// 4.1.0 to 4.2.0 | ||
migrate410r1To420r1, | ||
]; | ||
|
||
const lastMigration = migrations[migrations.length - 1]; | ||
|
||
export const LATEST_PROJECT_VERSION = lastMigration.to.version; | ||
export const LATEST_PROJECT_MINOR_VERSION = lastMigration.to.release; | ||
|
||
export const migrateProjectResources = async ( | ||
resources: CompressedProjectResources | ||
): Promise<CompressedProjectResources> => { | ||
return migrations.reduce((migratedResources, migration) => { | ||
return applyProjectResourcesMigration(migratedResources, migration); | ||
}, resources); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
ScriptEventMigrationFn, | ||
ProjectResourcesMigration, | ||
createScriptEventsMigrator, | ||
} from "lib/project/migration/helpers"; | ||
|
||
export const migrateFrom410r1To420r1Event: ScriptEventMigrationFn = ( | ||
scriptEvent | ||
) => { | ||
if (scriptEvent.args && scriptEvent.command === "EVENT_SWITCH") { | ||
const args: Record<string, unknown> = { ...scriptEvent.args }; | ||
for (let i = 0; i < 16; i++) { | ||
const key = `value${i}`; | ||
const defaultValue = i + 1; | ||
const storedValue = args[key]; | ||
const value = | ||
typeof storedValue === "number" ? storedValue : defaultValue; | ||
// Convert to constvalue | ||
args[key] = { | ||
type: "number", | ||
value, | ||
}; | ||
} | ||
return { | ||
...scriptEvent, | ||
args, | ||
}; | ||
} | ||
return scriptEvent; | ||
}; | ||
|
||
export const migrate410r1To420r1: ProjectResourcesMigration = { | ||
from: { version: "4.1.0", release: "1" }, | ||
to: { version: "4.2.0", release: "1" }, | ||
migrationFn: createScriptEventsMigrator(migrateFrom410r1To420r1Event), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { CompressedProjectResources } from "shared/lib/resources/types"; | ||
import { | ||
dummyCompressedProjectResources, | ||
dummyScriptResource, | ||
} from "../../dummydata"; | ||
|
||
export const migrationTestProject: CompressedProjectResources = { | ||
...dummyCompressedProjectResources, | ||
scripts: [ | ||
{ | ||
...dummyScriptResource, | ||
script: [ | ||
{ | ||
id: "event1", | ||
command: "EVENT_SWITCH", | ||
args: { | ||
value1: 1, | ||
value2: 10, | ||
value3: 100, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
metadata: { | ||
...dummyCompressedProjectResources.metadata, | ||
_version: "4.1.0", | ||
_release: "1", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.