@@ -8,27 +8,30 @@ import { page } from '$app/state';
88import { user } from '$lib/stores/user' ;
99import deepEqual from 'deep-equal' ;
1010
11- type Preferences = {
11+ type ConsolePreferences = {
1212 limit ?: number ;
1313 view ?: View ;
1414 columns ?: string [ ] ;
15- } ;
15+ } /* support a strict + flexible preference type for TS compatibility */ & Record <
16+ string ,
17+ string | number | boolean | object | null | unknown
18+ > ;
1619
1720type TeamPreferences = {
1821 names ?: string [ ] ;
1922} ;
2023
21- type PreferencesStore = {
22- [ key : string ] : Preferences ;
24+ type ConsolePreferencesStore = {
25+ [ key : string ] : ConsolePreferences ;
2326 collections ?: {
24- [ key : string ] : Preferences [ 'columns' ] ;
27+ [ key : string ] : ConsolePreferences [ 'columns' ] ;
2528 } ;
2629 displayNames ?: {
2730 [ key : string ] : TeamPreferences [ 'names' ] ;
2831 } ;
2932} & { hideAiDisclaimer ?: boolean } ;
3033
31- async function updateConsolePreferences ( store : PreferencesStore ) : Promise < void > {
34+ async function updateConsolePreferences ( store : ConsolePreferencesStore ) : Promise < void > {
3235 const currentPreferences = get ( user ) ?. prefs ?? ( await sdk . forConsole . account . getPrefs ( ) ) ;
3336 if ( ! currentPreferences ?. console || Array . isArray ( currentPreferences . console ) ) {
3437 currentPreferences . console = { } ;
@@ -43,8 +46,8 @@ async function updateConsolePreferences(store: PreferencesStore): Promise<void>
4346}
4447
4548function createPreferences ( ) {
46- const { subscribe, set, update } = writable < PreferencesStore > ( { } ) ;
47- let preferences : PreferencesStore = { } ;
49+ const { subscribe, set, update } = writable < ConsolePreferencesStore > ( { } ) ;
50+ let preferences : ConsolePreferencesStore = { } ;
4851
4952 if ( browser ) {
5053 // fresh fetch.
@@ -73,9 +76,9 @@ function createPreferences() {
7376 /**
7477 * Update the local store and then synchronizes them on user prefs.
7578 */
76- function updateAndSync ( callback : ( prefs : PreferencesStore ) => void ) : Promise < void > {
77- let oldPrefsSnapshot : PreferencesStore ;
78- let newPrefsSnapshot : PreferencesStore ;
79+ function updateAndSync ( callback : ( prefs : ConsolePreferencesStore ) => void ) : Promise < void > {
80+ let oldPrefsSnapshot : ConsolePreferencesStore ;
81+ let newPrefsSnapshot : ConsolePreferencesStore ;
7982
8083 update ( ( currentPrefs ) => {
8184 oldPrefsSnapshot = structuredClone ( currentPrefs ) ;
@@ -96,7 +99,7 @@ function createPreferences() {
9699 subscribe,
97100 set,
98101 update,
99- get : ( route ?: Page [ 'route' ] ) : Preferences => {
102+ get : ( route ?: Page [ 'route' ] ) : ConsolePreferences => {
100103 const parsedRoute = route ?? page . route ;
101104 return (
102105 preferences ?. [ parsedRoute . id ] ?? {
@@ -106,10 +109,10 @@ function createPreferences() {
106109 }
107110 ) ;
108111 } ,
109- getCustomCollectionColumns : ( collectionId : string ) : Preferences [ 'columns' ] => {
112+ getCustomCollectionColumns : ( collectionId : string ) : ConsolePreferences [ 'columns' ] => {
110113 return preferences ?. collections ?. [ collectionId ] ?? [ ] ;
111114 } ,
112- setLimit : ( limit : Preferences [ 'limit' ] ) =>
115+ setLimit : ( limit : ConsolePreferences [ 'limit' ] ) =>
113116 updateAndSync ( ( n ) => {
114117 const path = page . route . id ;
115118
@@ -122,7 +125,7 @@ function createPreferences() {
122125
123126 return n ;
124127 } ) ,
125- setView : ( view : Preferences [ 'view' ] ) =>
128+ setView : ( view : ConsolePreferences [ 'view' ] ) =>
126129 updateAndSync ( ( n ) => {
127130 const path = page . route . id ;
128131
@@ -135,7 +138,7 @@ function createPreferences() {
135138
136139 return n ;
137140 } ) ,
138- setColumns : ( columns : Preferences [ 'columns' ] ) =>
141+ setColumns : ( columns : ConsolePreferences [ 'columns' ] ) =>
139142 updateAndSync ( ( n ) => {
140143 const path = page . route . id ;
141144
@@ -148,7 +151,10 @@ function createPreferences() {
148151
149152 return n ;
150153 } ) ,
151- setCustomCollectionColumns : ( collectionId : string , columns : Preferences [ 'columns' ] ) =>
154+ setCustomCollectionColumns : (
155+ collectionId : string ,
156+ columns : ConsolePreferences [ 'columns' ]
157+ ) =>
152158 updateAndSync ( ( n ) => {
153159 if ( ! n ?. collections ?. [ collectionId ] ) {
154160 n ??= { } ;
0 commit comments