generated from Alorel/basic-library-template-repo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #142
- Loading branch information
Showing
20 changed files
with
399 additions
and
111 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
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,48 @@ | ||
import type {Workflow} from './data/workflow.mjs'; | ||
import update0001 from './updates/update-0001.mjs'; | ||
|
||
export interface SerialisedWorkflow extends Pick<Workflow, 'name' | 'rm'> { | ||
steps: [string[], any[][]]; | ||
} | ||
|
||
export type DataUpdateFn = (workflows: SerialisedWorkflow[]) => void; | ||
|
||
export interface RunUpdatesResult { | ||
|
||
/** Whether at least one update got applied or not */ | ||
applied: boolean; | ||
|
||
/** The data version for this mod version */ | ||
update: number; | ||
} | ||
|
||
function getUpdatesArray(): DataUpdateFn[] { | ||
return [ | ||
update0001, | ||
]; | ||
} | ||
|
||
/** | ||
* Run data updates when the storage format changes to avoid users having to redefine all their workflows | ||
* @param dataVersion The current data version | ||
* @param data The raw loaded data | ||
* @return Whether at least one update got applied or not | ||
*/ | ||
export function runUpdates(dataVersion: number, data: SerialisedWorkflow[]): RunUpdatesResult { | ||
const updateFns = getUpdatesArray(); | ||
|
||
// The version defaults to -1 - add 1 to get array index 0 | ||
const firstIdx = dataVersion + 1; | ||
for (let i = firstIdx; i < updateFns.length; ++i) { | ||
updateFns[i](data); | ||
} | ||
|
||
return { | ||
applied: firstIdx < updateFns.length, | ||
update: updateFns.length - 1, | ||
}; | ||
} | ||
|
||
export function getUpdateNumber(): number { | ||
return getUpdatesArray().length - 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
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.