From 81137cf258bce2d8b3f9dbbe1e66eeb16bb1abf9 Mon Sep 17 00:00:00 2001 From: Bastian Jakobi <55296998+bastianjakobi@users.noreply.github.com> Date: Wed, 9 Oct 2024 12:20:34 +0200 Subject: [PATCH] feat: add util for using nested key definitions in ngrx-local-storage-sync (#519) * feat: add util for using nested key definitions in ngrx-local-storage-sync * fix: rename method --------- Co-authored-by: SchettlerKoehler <62466958+SchettlerKoehler@users.noreply.github.com> --- libs/ngrx-accelerator/src/index.ts | 3 ++- .../create-nested-key-configuration.ts | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 libs/ngrx-accelerator/src/lib/utils/local-storage/create-nested-key-configuration.ts diff --git a/libs/ngrx-accelerator/src/index.ts b/libs/ngrx-accelerator/src/index.ts index f457c2fe..a3e63c79 100644 --- a/libs/ngrx-accelerator/src/index.ts +++ b/libs/ngrx-accelerator/src/index.ts @@ -8,4 +8,5 @@ export * from './lib/utils/effects/filter-for-query-params-changed' export * from './lib/utils/selectors/create-child-selectors' // Local Storage -export * from './lib/utils/local-storage/lazy-loading-merge-reducer' \ No newline at end of file +export * from './lib/utils/local-storage/lazy-loading-merge-reducer' +export * from './lib/utils/local-storage/create-nested-key-configuration' \ No newline at end of file diff --git a/libs/ngrx-accelerator/src/lib/utils/local-storage/create-nested-key-configuration.ts b/libs/ngrx-accelerator/src/lib/utils/local-storage/create-nested-key-configuration.ts new file mode 100644 index 00000000..8fbefac1 --- /dev/null +++ b/libs/ngrx-accelerator/src/lib/utils/local-storage/create-nested-key-configuration.ts @@ -0,0 +1,24 @@ +export interface Options { + serialize?: (state: any) => any + deserialize?: (state: any) => any + reviver?: (key: string, value: any) => any + replacer?: ((key: string, value: any) => any) | string[] + encrypt?: (message: string) => string + decrypt?: (message: string) => string + filter?: string[] + space?: string | number +} + +type CommonKeyConfigurationTypes = Options | ((key: string, value: any) => any) + +export interface KeyConfiguration { + [key: string]: string[] | number[] | KeyConfiguration[] | CommonKeyConfigurationTypes +} + +export interface NestedKeyConfiguration { + [key: string]: (string | number | NestedKeyConfiguration)[] | CommonKeyConfigurationTypes + } + +export function createNestedKeyConfiguration(nestedKeyConfiguration: (string | NestedKeyConfiguration)[]): KeyConfiguration[] { + return nestedKeyConfiguration as KeyConfiguration[] +}