Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

mobile-preferences.ts

576 lines21.8 KB

1import * as Context from "effect/Context";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as Option from "effect/Option";
5import * as Ref from "effect/Ref";
6import * as Schema from "effect/Schema";
7import * as Semaphore from "effect/Semaphore";
8import {
9 EnvironmentId,
10 PullRequestInvolvement,
11 PullRequestListFilters,
12 PullRequestListState,
13 type ProviderInstanceId,
14 type PullRequestMergeMethod,
15 type SidebarProjectGroupingMode,
16} from "@t3tools/contracts";
17import { ToolCallVisibility } from "@t3tools/contracts/settings";
18import type { AndroidNavigationStyle } from "../lib/androidNavigationStyle";
19import type { ComposerEnterBehavior } from "../lib/composerEnterBehavior";
20import type { FollowUpBehavior } from "../lib/followUpBehavior";
21import { isMicrophoneKind, type MicrophoneEntry } from "../lib/microphonePriority";
22import { MOBILE_THEME_IDS, type MobileThemeId, type MobileThemeMode } from "../lib/mobileTheme";
23import * as MobileDatabase from "./mobile-database";
24import * as MobileSecureStorage from "./mobile-secure-storage";
25import { MobileStorageDecodeError, MobileStorageEncodeError } from "./mobile-storage";
26​
27const PREFERENCES_KEY = "t3code.preferences";
28const PREFERENCES_FALLBACK_KEY = "t3code.preferences.fallback";
29const encodeJson = Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
30​
31export const PullRequestListControls = Schema.Struct({
32 state: PullRequestListState,
33 involvement: PullRequestInvolvement,
34 filters: PullRequestListFilters,
35 projectId: Schema.optional(Schema.String),
36 projectEnvironmentId: Schema.optional(Schema.String),
37 sort: Schema.Literals(["updated", "created", "oldest"]),
38});
39export type PullRequestListControls = typeof PullRequestListControls.Type;
40​
41const ThreadListFilters = Schema.Struct({
42 environmentId: Schema.NullOr(EnvironmentId),
43 projectKey: Schema.NullOr(Schema.String),
44});
45export type ThreadListFilters = typeof ThreadListFilters.Type;
46​
47const PullRequestListPreferences = Schema.Struct({
48 environmentId: Schema.NullOr(Schema.String),
49 controls: Schema.Record(Schema.String, PullRequestListControls),
50});
51export type PullRequestListPreferences = typeof PullRequestListPreferences.Type;
52​
53/**
54 * The page each workspace tab last showed, reopened when the tab returns with columns. `key` is
55 * that page's route key: reopening under the same key reuses the screen a tab kept mounted.
56 */
57const WorkspaceSelections = Schema.Struct({
58 threads: Schema.optional(
59 Schema.Struct({
60 environmentId: Schema.String,
61 threadId: Schema.String,
62 key: Schema.optional(Schema.String),
63 }),
64 ),
65 pullRequests: Schema.optional(
66 Schema.Struct({
67 environmentId: Schema.String,
68 projectId: Schema.String,
69 repository: Schema.String,
70 number: Schema.Number,
71 host: Schema.optional(Schema.String),
72 key: Schema.optional(Schema.String),
73 }),
74 ),
75 settings: Schema.optional(Schema.String),
76 settingsKey: Schema.optional(Schema.String),
77 /** A draft the threads tab showed after its last chat; only meaningful in its session. */
78 threadsDraft: Schema.optional(Schema.Struct({ key: Schema.String, params: Schema.Unknown })),
79});
80export type WorkspaceSelections = typeof WorkspaceSelections.Type;
81​
82const isThreadListFilters = Schema.is(ThreadListFilters);
83const isWorkspaceSelections = Schema.is(WorkspaceSelections);
84const isPullRequestListPreferences = Schema.is(PullRequestListPreferences);
85const ThreadProject = Schema.Struct({
86 environmentId: Schema.NonEmptyString,
87 projectId: Schema.NonEmptyString,
88});
89const isThreadProject = Schema.is(ThreadProject);
90​
91export interface Preferences {
92 readonly navigationTabOrder?: readonly string[];
93 readonly hiddenNavigationTabs?: readonly string[];
94 readonly pullRequestHideTestFiles?: boolean;
95 readonly pullRequestMergeMethod?: PullRequestMergeMethod;
96 readonly liveActivitiesEnabled?: boolean;
97 readonly themeId?: MobileThemeId;
98 readonly lightThemeId?: MobileThemeId;
99 readonly darkThemeId?: MobileThemeId;
100 readonly themeMode?: MobileThemeMode;
101 readonly androidNavigationStyle?: AndroidNavigationStyle;
102 readonly baseFontSize?: number;
103 readonly terminalFontSize?: number | null;
104 readonly markdownFontSize?: number;
105 readonly codeFontSize?: number | null;
106 readonly codeWordBreak?: boolean;
107 readonly mathRenderingEnabled?: boolean;
108 /** Unset means on: crash reports are sent unless the user turns them off. */
109 readonly crashReportsEnabled?: boolean;
110 readonly connectOnboardingOptOutAccounts?: ReadonlyArray<string>;
111 readonly collapsedProjectGroups?: readonly string[];
112 readonly dismissedDatabaseStorageNotices?: readonly string[];
113 /** Hardware Return behavior is iOS-only. */
114 readonly composerEnterBehavior?: ComposerEnterBehavior;
115 readonly followUpBehavior?: FollowUpBehavior;
116 readonly microphones?: ReadonlyArray<MicrophoneEntry>;
117 readonly projectGroupingEnabled?: boolean;
118 readonly projectGroupingMode?: SidebarProjectGroupingMode;
119 readonly planModeEnabled?: boolean;
120 readonly toolCallVisibility?: ToolCallVisibility;
121 readonly workingShelfEnabled?: boolean;
122 readonly useLastProjectForNewThreads?: boolean;
123 readonly lastThreadProject?: typeof ThreadProject.Type;
124 readonly modelFavorites?: ReadonlyArray<{
125 readonly provider: ProviderInstanceId;
126 readonly model: string;
127 }>;
128 readonly threadListSettledShelfExpanded?: boolean;
129 readonly threadListSnoozedShelfExpanded?: boolean;
130 readonly threadListWorkingShelfExpanded?: boolean;
131 readonly threadListFilters?: ThreadListFilters;
132 readonly pullRequestListFilters?: PullRequestListPreferences;
133 readonly workspaceSelections?: WorkspaceSelections;
135​
136export class MobilePreferencesLoadError extends Schema.TaggedError<MobilePreferencesLoadError>()(
137 "MobilePreferencesLoadError",
138 { cause: Schema.Defect() },
139) {
140 override get message(): string {
141 return "Failed to load mobile preferences.";
142 }
144​
145export class MobilePreferencesSaveError extends Schema.TaggedError<MobilePreferencesSaveError>()(
146 "MobilePreferencesSaveError",
147 { cause: Schema.Defect() },
148) {
149 override get message(): string {
150 return "Failed to save mobile preferences.";
151 }
153​
154const isMobilePreferencesSaveError = Schema.is(MobilePreferencesSaveError);
155​
156interface PreferencesFallback {
157 readonly payload: string;
158 readonly updatedAt: number;
159 readonly preferences: Preferences;
161​
162export class MobilePreferencesStore extends Context.Service<
163 MobilePreferencesStore,
164 {
165 readonly load: Effect.Effect<Preferences, MobilePreferencesLoadError>;
166 readonly savePatch: (
167 patch: Partial<Preferences>,
168 ) => Effect.Effect<Preferences, MobilePreferencesSaveError>;
169 readonly update: (
170 transform: (current: Preferences) => Partial<Preferences>,
171 ) => Effect.Effect<Preferences, MobilePreferencesSaveError>;
172 }
173>()("@t3tools/mobile/persistence/mobile-preferences/MobilePreferencesStore") {}
174​
175const isToolCallVisibility = Schema.is(ToolCallVisibility);
176​
177function sanitizePreferences(parsed: Preferences): Preferences {
178 const preferences: {
179 navigationTabOrder?: readonly string[];
180 hiddenNavigationTabs?: readonly string[];
181 pullRequestHideTestFiles?: boolean;
182 pullRequestMergeMethod?: PullRequestMergeMethod;
183 liveActivitiesEnabled?: boolean;
184 themeId?: MobileThemeId;
185 lightThemeId?: MobileThemeId;
186 darkThemeId?: MobileThemeId;
187 themeMode?: MobileThemeMode;
188 androidNavigationStyle?: AndroidNavigationStyle;
189 baseFontSize?: number;
190 terminalFontSize?: number | null;
191 markdownFontSize?: number;
192 codeFontSize?: number | null;
193 codeWordBreak?: boolean;
194 mathRenderingEnabled?: boolean;
195 crashReportsEnabled?: boolean;
196 connectOnboardingOptOutAccounts?: ReadonlyArray<string>;
197 collapsedProjectGroups?: readonly string[];
198 dismissedDatabaseStorageNotices?: readonly string[];
199 composerEnterBehavior?: ComposerEnterBehavior;
200 followUpBehavior?: FollowUpBehavior;
201 microphones?: ReadonlyArray<MicrophoneEntry>;
202 projectGroupingEnabled?: boolean;
203 projectGroupingMode?: SidebarProjectGroupingMode;
204 planModeEnabled?: boolean;
205 toolCallVisibility?: ToolCallVisibility;
206 workingShelfEnabled?: boolean;
207 useLastProjectForNewThreads?: boolean;
208 lastThreadProject?: typeof ThreadProject.Type;
209 modelFavorites?: Preferences["modelFavorites"];
210 threadListSettledShelfExpanded?: boolean;
211 threadListSnoozedShelfExpanded?: boolean;
212 threadListWorkingShelfExpanded?: boolean;
213 threadListFilters?: ThreadListFilters;
214 pullRequestListFilters?: PullRequestListPreferences;
215 workspaceSelections?: WorkspaceSelections;
216 } = {};
217​
218 if (Array.isArray(parsed.hiddenNavigationTabs)) {
219 preferences.hiddenNavigationTabs = parsed.hiddenNavigationTabs.filter(
220 (tab): tab is string => typeof tab === "string",
221 );
222 }
223​
224 if (Array.isArray(parsed.navigationTabOrder)) {
225 preferences.navigationTabOrder = parsed.navigationTabOrder.filter(
226 (tab): tab is string => typeof tab === "string",
227 );
228 }
229​
230 if (typeof parsed.pullRequestHideTestFiles === "boolean") {
231 preferences.pullRequestHideTestFiles = parsed.pullRequestHideTestFiles;
232 }
233​
234 if (
235 parsed.pullRequestMergeMethod === "squash" ||
236 parsed.pullRequestMergeMethod === "merge" ||
237 parsed.pullRequestMergeMethod === "rebase"
238 ) {
239 preferences.pullRequestMergeMethod = parsed.pullRequestMergeMethod;
240 }
241​
242 if (typeof parsed.liveActivitiesEnabled === "boolean") {
243 preferences.liveActivitiesEnabled = parsed.liveActivitiesEnabled;
244 }
245 if (
246 typeof parsed.themeId === "string" &&
247 (MOBILE_THEME_IDS as readonly string[]).includes(parsed.themeId)
248 ) {
249 preferences.themeId = parsed.themeId as MobileThemeId;
250 }
251 if (
252 typeof parsed.lightThemeId === "string" &&
253 (MOBILE_THEME_IDS as readonly string[]).includes(parsed.lightThemeId)
254 ) {
255 preferences.lightThemeId = parsed.lightThemeId as MobileThemeId;
256 }
257 if (
258 typeof parsed.darkThemeId === "string" &&
259 (MOBILE_THEME_IDS as readonly string[]).includes(parsed.darkThemeId)
260 ) {
261 preferences.darkThemeId = parsed.darkThemeId as MobileThemeId;
262 }
263 if (
264 parsed.themeMode === "system" ||
265 parsed.themeMode === "light" ||
266 parsed.themeMode === "dark"
267 ) {
268 preferences.themeMode = parsed.themeMode;
269 }
270 if (parsed.androidNavigationStyle === "one-ui" || parsed.androidNavigationStyle === "material") {
271 preferences.androidNavigationStyle = parsed.androidNavigationStyle;
272 }
273 if (typeof parsed.baseFontSize === "number") preferences.baseFontSize = parsed.baseFontSize;
274 if (typeof parsed.terminalFontSize === "number" || parsed.terminalFontSize === null) {
275 preferences.terminalFontSize = parsed.terminalFontSize;
276 }
277 if (typeof parsed.markdownFontSize === "number") {
278 preferences.markdownFontSize = parsed.markdownFontSize;
279 }
280 if (typeof parsed.codeFontSize === "number" || parsed.codeFontSize === null) {
281 preferences.codeFontSize = parsed.codeFontSize;
282 }
283 if (typeof parsed.codeWordBreak === "boolean") preferences.codeWordBreak = parsed.codeWordBreak;
284 if (typeof parsed.mathRenderingEnabled === "boolean")
285 preferences.mathRenderingEnabled = parsed.mathRenderingEnabled;
286 if (typeof parsed.crashReportsEnabled === "boolean") {
287 preferences.crashReportsEnabled = parsed.crashReportsEnabled;
288 }
289 if (Array.isArray(parsed.connectOnboardingOptOutAccounts)) {
290 preferences.connectOnboardingOptOutAccounts = parsed.connectOnboardingOptOutAccounts.filter(
291 (account): account is string => typeof account === "string",
292 );
293 }
294 if (Array.isArray(parsed.collapsedProjectGroups)) {
295 preferences.collapsedProjectGroups = parsed.collapsedProjectGroups.filter(
296 (key): key is string => typeof key === "string",
297 );
298 }
299 if (Array.isArray(parsed.dismissedDatabaseStorageNotices)) {
300 preferences.dismissedDatabaseStorageNotices = parsed.dismissedDatabaseStorageNotices.filter(
301 (value): value is string => typeof value === "string",
302 );
303 }
304 if (parsed.composerEnterBehavior === "send" || parsed.composerEnterBehavior === "newline") {
305 preferences.composerEnterBehavior = parsed.composerEnterBehavior;
306 }
307 if (parsed.followUpBehavior === "queue" || parsed.followUpBehavior === "steer") {
308 preferences.followUpBehavior = parsed.followUpBehavior;
309 }
310 if (Array.isArray(parsed.microphones)) {
311 preferences.microphones = parsed.microphones.flatMap((entry): MicrophoneEntry[] => {
312 if (typeof entry !== "object" || entry === null || !isMicrophoneKind(entry.kind)) return [];
313 if (!("uid" in entry)) return [{ kind: entry.kind }];
314 return typeof entry.uid === "string" && typeof entry.name === "string"
315 ? [{ kind: entry.kind, uid: entry.uid, name: entry.name }]
316 : [];
317 });
318 }
319 if (typeof parsed.projectGroupingEnabled === "boolean") {
320 preferences.projectGroupingEnabled = parsed.projectGroupingEnabled;
321 }
322 if (
323 parsed.projectGroupingMode === "repository" ||
324 parsed.projectGroupingMode === "repository_path" ||
325 parsed.projectGroupingMode === "separate"
326 ) {
327 preferences.projectGroupingMode = parsed.projectGroupingMode;
328 }
329 if (typeof parsed.planModeEnabled === "boolean") {
330 preferences.planModeEnabled = parsed.planModeEnabled;
331 }
332 if (isToolCallVisibility(parsed.toolCallVisibility)) {
333 preferences.toolCallVisibility = parsed.toolCallVisibility;
334 }
335 if (typeof parsed.workingShelfEnabled === "boolean") {
336 preferences.workingShelfEnabled = parsed.workingShelfEnabled;
337 }
338 if (typeof parsed.useLastProjectForNewThreads === "boolean") {
339 preferences.useLastProjectForNewThreads = parsed.useLastProjectForNewThreads;
340 }
341 if (isThreadProject(parsed.lastThreadProject)) {
342 preferences.lastThreadProject = parsed.lastThreadProject;
343 }
344 if (Array.isArray(parsed.modelFavorites)) {
345 preferences.modelFavorites = parsed.modelFavorites.filter(
346 (favorite) =>
347 typeof favorite === "object" &&
348 favorite !== null &&
349 typeof favorite.provider === "string" &&
350 favorite.provider.length > 0 &&
351 typeof favorite.model === "string" &&
352 favorite.model.trim().length > 0,
353 );
354 }
355 if (typeof parsed.threadListSettledShelfExpanded === "boolean") {
356 preferences.threadListSettledShelfExpanded = parsed.threadListSettledShelfExpanded;
357 }
358 if (typeof parsed.threadListSnoozedShelfExpanded === "boolean") {
359 preferences.threadListSnoozedShelfExpanded = parsed.threadListSnoozedShelfExpanded;
360 }
361 if (typeof parsed.threadListWorkingShelfExpanded === "boolean") {
362 preferences.threadListWorkingShelfExpanded = parsed.threadListWorkingShelfExpanded;
363 }
364 if (isThreadListFilters(parsed.threadListFilters)) {
365 preferences.threadListFilters = parsed.threadListFilters;
366 }
367 if (isPullRequestListPreferences(parsed.pullRequestListFilters)) {
368 preferences.pullRequestListFilters = parsed.pullRequestListFilters;
369 }
370 if (isWorkspaceSelections(parsed.workspaceSelections)) {
371 preferences.workspaceSelections = parsed.workspaceSelections;
372 }
373 return preferences;
375​
376const make = Effect.fn("MobilePreferencesStore.make")(function* () {
377 const database = yield* MobileDatabase.MobileDatabase;
378 const secureStorage = yield* MobileSecureStorage.MobileSecureStorage;
379 const lock = yield* Semaphore.make(1);
380 const lastUpdatedAt = yield* Ref.make(0);
381​
382 const parsePayload = (raw: string | null): Preferences | null => {
383 if (raw === null || !raw.trim()) return null;
384 let parsed: unknown;
385 try {
386 parsed = JSON.parse(raw);
387 } catch (cause) {
388 console.warn(
389 "[mobile-storage] ignored invalid JSON",
390 new MobileStorageDecodeError({ key: PREFERENCES_KEY, cause }),
391 );
392 return null;
393 }
394 return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)
395 ? (parsed as Preferences)
396 : null;
397 };
398​
399 const parseFallback = (raw: string | null): PreferencesFallback | null => {
400 if (raw === null || !raw.trim()) return null;
401 let parsed: unknown;
402 try {
403 parsed = JSON.parse(raw);
404 } catch (cause) {
405 console.warn(
406 "[mobile-storage] ignored invalid JSON",
407 new MobileStorageDecodeError({ key: PREFERENCES_FALLBACK_KEY, cause }),
408 );
409 return null;
410 }
411 if (
412 typeof parsed !== "object" ||
413 parsed === null ||
414 !("payload" in parsed) ||
415 typeof parsed.payload !== "string" ||
416 !("updatedAt" in parsed) ||
417 typeof parsed.updatedAt !== "number"
418 ) {
419 return null;
420 }
421 const preferences = parsePayload(parsed.payload);
422 return preferences === null
423 ? null
424 : { payload: parsed.payload, updatedAt: parsed.updatedAt, preferences };
425 };
426​
427 const encode = Effect.fn("MobilePreferencesStore.encode")(function* (
428 key: string,
429 value: unknown,
430 ) {
431 return yield* encodeJson(value).pipe(
432 Effect.mapError((cause) => new MobileStorageEncodeError({ key, cause })),
433 );
434 });
435​
436 const nextUpdatedAt = Ref.modify(lastUpdatedAt, (last) => {
437 const next = Math.max(Date.now(), last + 1);
438 return [next, next] as const;
439 });
440​
441 const saveJson = Effect.fn("MobilePreferencesStore.saveJson")(function* (
442 payload: string,
443 updatedAt?: number,
444 ) {
445 const timestamp = updatedAt ?? (yield* nextUpdatedAt);
446 yield* Ref.update(lastUpdatedAt, (last) => Math.max(last, timestamp));
447 const databaseResult = yield* Effect.result(database.savePreferencesJson(payload, timestamp));
448 if (databaseResult._tag === "Failure") {
449 yield* Effect.logWarning("Database unavailable; saving preferences to secure storage.").pipe(
450 Effect.annotateLogs({ cause: databaseResult.failure }),
451 );
452 const fallback = yield* encode(PREFERENCES_FALLBACK_KEY, { payload, updatedAt: timestamp });
453 yield* secureStorage.setItem(PREFERENCES_FALLBACK_KEY, fallback);
454 return;
455 }
456 yield* secureStorage
457 .removeItem(PREFERENCES_FALLBACK_KEY)
458 .pipe(
459 Effect.catch((error) =>
460 Effect.logWarning("Could not remove the mobile preferences fallback.").pipe(
461 Effect.annotateLogs({ error }),
462 ),
463 ),
464 );
465 });
466​
467 const loadUnlocked = Effect.gen(function* () {
468 const databaseResult = yield* Effect.result(database.loadPreferencesJson);
469 const databaseAvailable = databaseResult._tag === "Success";
470 const storedJson = databaseAvailable
471 ? databaseResult.success
472 : Option.none<MobileDatabase.StoredPreferencesJson>();
473 if (databaseResult._tag === "Failure") {
474 yield* Effect.logWarning("Database unavailable; loading fallback preferences.").pipe(
475 Effect.annotateLogs({ cause: databaseResult.failure }),
476 );
477 }
478​
479 const fallbackResult = yield* Effect.result(secureStorage.getItem(PREFERENCES_FALLBACK_KEY));
480 let fallbackJson: string | null = null;
481 if (fallbackResult._tag === "Success") {
482 fallbackJson = fallbackResult.success;
483 } else if (Option.isNone(storedJson)) {
484 return yield* fallbackResult.failure;
485 } else {
486 yield* Effect.logWarning("Could not inspect the mobile preferences fallback.").pipe(
487 Effect.annotateLogs({ error: fallbackResult.failure }),
488 );
489 }
490​
491 const fallback = parseFallback(fallbackJson);
492 const storedPreferences = Option.isSome(storedJson)
493 ? parsePayload(storedJson.value.payload)
494 : null;
495 const fallbackIsNewer =
496 fallback !== null &&
497 (storedPreferences === null ||
498 (Option.isSome(storedJson) && fallback.updatedAt > storedJson.value.updatedAt));
499​
500 let parsed: Preferences | null = null;
501 if (fallbackIsNewer) {
502 parsed = fallback.preferences;
503 yield* Ref.update(lastUpdatedAt, (last) => Math.max(last, fallback.updatedAt));
504 if (databaseAvailable) yield* saveJson(fallback.payload, fallback.updatedAt);
505 } else if (storedPreferences !== null && Option.isSome(storedJson)) {
506 parsed = storedPreferences;
507 yield* Ref.update(lastUpdatedAt, (last) => Math.max(last, storedJson.value.updatedAt));
508 if (fallbackJson !== null) {
509 yield* secureStorage
510 .removeItem(PREFERENCES_FALLBACK_KEY)
511 .pipe(
512 Effect.catch((error) =>
513 Effect.logWarning("Could not remove a stale mobile preferences fallback.").pipe(
514 Effect.annotateLogs({ error }),
515 ),
516 ),
517 );
518 }
519 }
520​
521 if (parsed === null) {
522 const legacyJson = yield* secureStorage.getItem(PREFERENCES_KEY);
523 const legacyPreferences = parsePayload(legacyJson);
524 parsed = legacyPreferences;
525 if (legacyJson !== null && legacyPreferences !== null && databaseAvailable) {
526 yield* saveJson(legacyJson);
527 yield* secureStorage
528 .removeItem(PREFERENCES_KEY)
529 .pipe(
530 Effect.catch((error) =>
531 Effect.logWarning("Could not remove migrated mobile preferences.").pipe(
532 Effect.annotateLogs({ error }),
533 ),
534 ),
535 );
536 }
537 }
538​
539 return parsed === null ? {} : sanitizePreferences(parsed);
540 });
541​
542 const load = lock
543 .withPermits(1)(loadUnlocked)
544 .pipe(Effect.mapError((cause) => new MobilePreferencesLoadError({ cause })));
545​
546 const update = Effect.fn("MobilePreferencesStore.update")(
547 (transform: (current: Preferences) => Partial<Preferences>) =>
548 lock
549 .withPermits(1)(
550 Effect.gen(function* () {
551 const current = yield* loadUnlocked;
552 const patch = yield* Effect.try({
553 try: () => transform(current),
554 catch: (cause) => new MobilePreferencesSaveError({ cause }),
555 });
556 const next: Preferences = { ...current, ...patch };
557 const payload = yield* encode(PREFERENCES_KEY, next);
558 yield* saveJson(payload);
559 return next;
560 }),
561 )
562 .pipe(
563 Effect.mapError((cause) =>
564 isMobilePreferencesSaveError(cause) ? cause : new MobilePreferencesSaveError({ cause }),
565 ),
566 ),
567 );
568​
569 return MobilePreferencesStore.of({
570 load,
571 update,
572 savePatch: Effect.fn("MobilePreferencesStore.savePatch")((patch) => update(() => patch)),
573 });
574});
575​
576export const layer = Layer.effect(MobilePreferencesStore, make());