77 PullRequestListFilters ,
88 PullRequestListState ,
99} from "@t3tools/contracts" ;
10+ import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations" ;
1011
1112export const PullRequestListSort = Schema . Literals ( [
1213 "ready" ,
@@ -43,7 +44,11 @@ const DEFAULT_PULL_REQUEST_LIST_PREFERENCES = {
4344 state : "open" ,
4445} as const satisfies PullRequestListPreferences ;
4546
46- const BoundedPreference = Schema . String . check ( Schema . isMaxLength ( 200 ) ) ;
47+ const TEXT_MAX = 200 ;
48+ const LABELS_MAX = 10 ;
49+ const BoundedPreference = Schema . String . check ( Schema . isMaxLength ( TEXT_MAX ) ) ;
50+ const bounded = ( value : string ) =>
51+ value . slice ( 0 , splitsSurrogatePair ( value , TEXT_MAX ) ? TEXT_MAX - 1 : TEXT_MAX ) ;
4752export const PullRequestListPreferencesSchema = Schema . Struct ( {
4853 involvement : PullRequestInvolvement ,
4954 state : PullRequestListState ,
@@ -55,7 +60,7 @@ export const PullRequestListPreferencesSchema = Schema.Struct({
5560 review : PullRequestListFilters . fields . review ,
5661 checks : PullRequestListFilters . fields . checks ,
5762 author : Schema . optional ( BoundedPreference ) ,
58- labels : Schema . optional ( Schema . Array ( BoundedPreference ) . check ( Schema . isMaxLength ( 10 ) ) ) ,
63+ labels : Schema . optional ( Schema . Array ( BoundedPreference ) . check ( Schema . isMaxLength ( LABELS_MAX ) ) ) ,
5964 sort : Schema . optional ( PullRequestListSort ) ,
6065} ) ;
6166
@@ -79,13 +84,13 @@ export function pullRequestListPreferences(
7984 state : search . state ,
8085 ...( search . environmentId ? { environmentId : search . environmentId } : { } ) ,
8186 ...( search . projectId ? { projectId : search . projectId } : { } ) ,
82- ...( search . host ? { host : search . host } : { } ) ,
83- ...( search . q ? { q : search . q } : { } ) ,
87+ ...( search . host ? { host : bounded ( search . host ) } : { } ) ,
88+ ...( search . q ? { q : bounded ( search . q ) } : { } ) ,
8489 ...( search . draft ? { draft : search . draft } : { } ) ,
8590 ...( search . review ? { review : search . review } : { } ) ,
8691 ...( search . checks ? { checks : search . checks } : { } ) ,
87- ...( search . author ? { author : search . author } : { } ) ,
88- ...( search . labels && search . labels . length > 0 ? { labels : search . labels } : { } ) ,
92+ ...( search . author ? { author : bounded ( search . author ) } : { } ) ,
93+ ...( search . labels ?. length ? { labels : search . labels . slice ( 0 , LABELS_MAX ) . map ( bounded ) } : { } ) ,
8994 ...( search . sort && search . sort !== "ready" ? { sort : search . sort } : { } ) ,
9095 } ;
9196}
@@ -114,7 +119,7 @@ export function writePullRequestListPreferences(
114119 try {
115120 resolvePreferenceStorage ( storage ) ?. setItem (
116121 PULL_REQUEST_LIST_PREFERENCES_STORAGE_KEY ,
117- JSON . stringify ( preferences ) ,
122+ JSON . stringify ( pullRequestListPreferences ( preferences ) ) ,
118123 ) ;
119124 } catch { }
120125}
0 commit comments