-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat 52: Import and Export Bucketizer State (#53)
* bump: bump dependency version * bump: bump dependency version * feat: export and import Bucketizer state, and change State object * dist: nw dist * feat: pass null instead of ' ' when no previous state * dist: new dist
- Loading branch information
1 parent
38679a8
commit 07f2ab0
Showing
8 changed files
with
701 additions
and
299 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,18 +1,27 @@ | ||
import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs'; | ||
import type { State } from '@treecg/actor-init-ldes-client'; | ||
|
||
export const saveState = (state: State, storage: string): void => { | ||
export const saveState = (clientState: State, buckerizerState: any, storage: string): void => { | ||
const folder = `./.ldes/${storage}`; | ||
if (!existsSync(folder)) { | ||
mkdirSync(folder, { recursive: true }); | ||
} | ||
const state: LDESActionState = { | ||
LDESClientState: clientState, | ||
BucketizerState: buckerizerState, | ||
}; | ||
writeFileSync(`${folder}/state.json`, JSON.stringify(state)); | ||
}; | ||
|
||
export const loadState = (storage: string): State | null => { | ||
export const loadState = (storage: string): LDESActionState | null => { | ||
const folder = `./.ldes/${storage}`; | ||
if (existsSync(`${folder}/state.json`)) { | ||
return JSON.parse(readFileSync(`${folder}/state.json`).toString()); | ||
} | ||
return null; | ||
}; | ||
|
||
export interface LDESActionState { | ||
LDESClientState: State; | ||
BucketizerState: any; | ||
} |