@molecule/app-svelte 3.6.0 → 3.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-11-14T17:17:26.808Z
6
+ Generated: 2026-11-18T16:22:02.310Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-svelte
@@ -160,55 +160,143 @@ interface AuthClient<
160
160
  T = UserProfile,
161
161
  TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
162
162
  > {
163
- /** Returns the current authentication state snapshot. */
163
+ /**
164
+ * Returns the current authentication state snapshot.
165
+ *
166
+ * READING the state starts the client's one session restore when nobody has called
167
+ * {@link initialize} yet — lazily and exactly once, sharing the promise an explicit
168
+ * `initialize()` returns. A hook (`useAuth()`), a subscriber, `isAuthenticated()` and
169
+ * `getUser()` are reads too, so a client whose entry file dropped the template's
170
+ * `authClient.initialize()` line still restores instead of reporting `'loading'`
171
+ * forever.
172
+ */
164
173
  getState(): AuthState<T>
165
174
 
166
- /** Returns whether the user is currently authenticated. */
175
+ /**
176
+ * Returns whether the user is currently authenticated.
177
+ */
167
178
  isAuthenticated(): boolean
168
179
 
169
- /** Gets the current user. */
180
+ /**
181
+ * Gets the current user.
182
+ */
170
183
  getUser(): T | null
171
184
 
172
- /** Optional ownership marker for the current session. */
185
+ /**
186
+ * Optional ownership marker for the current session. Compare values only within
187
+ * this client: replacing or ending a session changes it, including re-adopting
188
+ * the same token and user. Profile updates and same-session refreshes keep it.
189
+ * Consumers can use it to discard stale async work without treating editable
190
+ * user fields as an immutable account identifier. Providers without this
191
+ * capability require the consumer's own stable identity check.
192
+ */
173
193
  getSessionRevision?(): number
174
194
 
175
195
  /** Updates the cached user object (state + persistent storage) without hitting the network. */
176
196
  setUser(user: T | null): void
177
197
 
178
- /** Gets the current access token. */
198
+ /**
199
+ * Gets the current access token.
200
+ */
179
201
  getAccessToken(): string | null
180
202
 
181
- /** Stores the access token in the configured token storage adapter (in a browser, Web Storage; `'memory'` where no browser store exists). */
203
+ /**
204
+ * Stores the access token in the configured token storage adapter (in a
205
+ * browser, Web Storage; `'memory'` where no browser store exists). Use this
206
+ * to seed the token after an out-of-band exchange (e.g. the OAuth
207
+ * code→token redirect) instead of writing to `localStorage` directly,
208
+ * which would violate the storage contract and make a stored bearer token
209
+ * JS-readable (XSS-exfiltratable). Pass `null` to clear it.
210
+ *
211
+ * Passing `null` does not by itself sign a signed-in client out: use
212
+ * {@link logout} to end a session, or {@link setUser} with `null` for
213
+ * local-only sign-out. A non-null token on a client that is not signed in is
214
+ * the first or second half of the app's own sign-in pair: together with
215
+ * {@link setUser} it adopts the session (see there). Prefer {@link setSession}
216
+ * with the token and user, or {@link login} / {@link register} for a
217
+ * credential exchange.
218
+ */
182
219
  setAccessToken(token: string | null): void
183
220
 
184
- /** Adopts a session an out-of-band exchange already established: stores the access token (and the refresh token when given), caches the user, and sets the COMPLET… */
221
+ /**
222
+ * Adopts a session an out-of-band exchange already established: stores the
223
+ * access token (and the refresh token when given), caches the user, and
224
+ * sets the COMPLETE state — `initialized`, `authenticated`, `status:
225
+ * 'authenticated'`, no error — in one update, with one subscriber
226
+ * notification. Every hook reading the shared client sees the user as
227
+ * signed in immediately.
228
+ *
229
+ * This is the way to seed an OAuth/custom sign-in. The field-setter pair
230
+ * ({@link setAccessToken} then {@link setUser}, or the reverse) on a client
231
+ * that is not signed in adopts the session the same way.
232
+ */
185
233
  setSession(session: AuthSessionSeed<T>): void
186
234
 
187
- /** Gets the refresh token. */
235
+ /**
236
+ * Gets the refresh token.
237
+ */
188
238
  getRefreshToken(): string | null
189
239
 
190
- /** Logs in with credentials. */
240
+ /**
241
+ * Logs in with credentials.
242
+ */
191
243
  login(credentials: LoginCredentials): Promise<AuthResult<T>>
192
244
 
193
- /** Logs out the current user. */
245
+ /**
246
+ * Logs out the current user. The server request is best-effort: a missing
247
+ * logout route (404), any other HTTP failure, or a network error never makes
248
+ * this method reject. It always clears the access token, refresh token and
249
+ * cached user, stops automatic refresh, and publishes one settled
250
+ * `authenticated: false`, `status: 'unauthenticated'` transition. Every pending
251
+ * session operation loses ownership; a persistent marker prevents reload from
252
+ * restoring an older session, and late credentials are revoked best-effort.
253
+ *
254
+ * When the API has no logout route, set {@link AuthClientConfigOptions.logoutEndpoint}
255
+ * to `null` (or `''`) to skip the request. Local sign-out still happens.
256
+ */
194
257
  logout(): Promise<void>
195
258
 
196
- /** Registers a new user. */
259
+ /**
260
+ * Registers a new user. Accepts the base fields plus the app's own fields
261
+ * (`TRegister`) at the top level — see {@link RegisterData}.
262
+ */
197
263
  register(data: RegisterData<TRegister>): Promise<AuthResult<T>>
198
264
 
199
- /** Exchanges a stored refresh token, or re-reads `currentUserEndpoint` with the existing access token/session cookie when the API has no refresh credential. */
265
+ /**
266
+ * Exchanges a stored refresh token, or re-reads `currentUserEndpoint` with the
267
+ * existing access token/session cookie when the API has no refresh credential.
268
+ * That fallback maps, stores and publishes the server user without renewing
269
+ * the access token. Failures reject. A 401/403 ends the session, as does an
270
+ * additional {@link AuthClientConfigOptions.currentUserRejectionStatuses}
271
+ * code from the fallback. Transient failures retain it as unavailable. Use {@link updateProfile} for a profile
272
+ * save, or {@link setUser} with the canonical row from an app-owned mutation.
273
+ */
200
274
  refresh(): Promise<AuthResult<T>>
201
275
 
202
- /** Requests a password reset. */
276
+ /**
277
+ * Requests a password reset.
278
+ */
203
279
  requestPasswordReset(data: PasswordResetRequest): Promise<void>
204
280
 
205
- /** Confirms a password reset. */
281
+ /**
282
+ * Confirms a password reset.
283
+ */
206
284
  confirmPasswordReset(data: PasswordResetConfirm): Promise<void>
207
285
 
208
- /** Updates the current user's profile. */
286
+ /**
287
+ * Updates the current user's profile.
288
+ * Returns the saved profile: the answer applied onto the signed-in user field
289
+ * by field, with or without an `id` — a field it carries replaces the value
290
+ * (`null` clears it), one it omits or leaves `undefined` is kept, so a field
291
+ * cleared by omission must arrive as `null`. A non-object answer is returned
292
+ * as it came. An answer for a replaced or ended session leaves the current one
293
+ * untouched.
294
+ */
209
295
  updateProfile(data: Partial<T>): Promise<T>
210
296
 
211
- /** Changes the current user's password. */
297
+ /**
298
+ * Changes the current user's password.
299
+ */
212
300
  changePassword(oldPassword: string, newPassword: string): Promise<void>
213
301
 
214
302
  /** Initializes auth state (e.g., from stored tokens). */
@@ -220,24 +308,48 @@ interface AuthClient<
220
308
  /** Resolves when the session restore started by `initialize()` has settled — the point after which the client knows whether this visitor is signed in. */
221
309
  whenRestored?(): Promise<void>
222
310
 
223
- /** Subscribes to auth state changes. */
311
+ /**
312
+ * Subscribes to auth state changes.
313
+ */
224
314
  subscribe(callback: (state: AuthState<T>) => void): () => void
225
315
 
226
- /** Subscribes to auth state changes (alias for subscribe). */
316
+ /**
317
+ * Subscribes to auth state changes (alias for subscribe).
318
+ */
227
319
  onAuthChange(callback: (state: AuthState<T>) => void): () => void
228
320
 
229
- /** Gets the current access token (alias for getAccessToken). */
321
+ /**
322
+ * Gets the current access token (alias for getAccessToken).
323
+ */
230
324
  getToken?(): string | null
231
325
 
232
- /** Adds an auth event listener. */
326
+ /**
327
+ * Adds an auth event listener.
328
+ *
329
+ * The listener is typed by this client's profile: one signature,
330
+ * `AuthEventListener<T>`, so an inline arrow is contextually typed and `event`
331
+ * is never implicitly `any`. A client whose profile extends
332
+ * {@link UserProfile} also accepts a default {@link AuthEventListener}: when
333
+ * `T` extends `UserProfile`, `AuthEvent<T>` is assignable to
334
+ * `AuthEvent<UserProfile>`, so a listener that takes the wider default event
335
+ * accepts every event this client emits and keeps compiling. (`UserProfile`
336
+ * is the wider type here — it has fewer required fields — and the assignable
337
+ * direction runs from the client's `AuthEvent<T>` to the listener's
338
+ * `AuthEvent<UserProfile>`.) A profile that does not extend `UserProfile`
339
+ * (no `id`) rejects the default listener: an `AuthEvent<UserProfile>` would
340
+ * promise an `id` the runtime user does not have, and the narrower-typed
341
+ * event is not assignable to it.
342
+ */
233
343
  addEventListener(listener: AuthEventListener<T>): () => void
234
344
 
235
- /** Destroys the auth client. */
345
+ /**
346
+ * Destroys the auth client.
347
+ */
236
348
  destroy(): void
237
349
  }
238
350
  ```
239
351
 
240
- _(Member comments are shortened to their first sentence to fit; the full declaration is in `node_modules/@molecule/app-auth/dist/types.d.ts`.)_
352
+ _(The 4 longest member comments are shortened to their first sentence to fit; the full declaration is in `node_modules/@molecule/app-auth/dist/types.d.ts`.)_
241
353
 
242
354
  #### `FormController`
243
355
 
@@ -343,9 +455,10 @@ interface FormController<T extends FormValuesConstraint<T> = Record<string, unkn
343
455
  * record, never a merge of earlier records. With `keepDirtyValues`, edited
344
456
  * fields retain their values while pristine fields take the loaded values.
345
457
  * A changed non-null `id` still replaces the record and cancels a pending
346
- * submit. Equal-content baselines cause no update.
458
+ * submit. Equal-content baselines cause no update. `keepOmittedValues` opts
459
+ * into incremental top-level field fills using the current clean baseline.
347
460
  */
348
- updateValues(values: Partial<T>, resetOptions?: FormResetOptions): void
461
+ updateValues(values: Partial<T>, resetOptions?: FormUpdateOptions): void
349
462
 
350
463
  /**
351
464
  * Handles form submission.
@@ -423,6 +536,15 @@ interface FormOptions<T extends FormValuesConstraint<T>> {
423
536
  HTTP client interface.
424
537
 
425
538
  All HTTP providers must implement this interface.
539
+ An explicit text, blob or arraybuffer parser determines the data type even when
540
+ a JSON generic is supplied. Keep JSON as the default for mutations returning a
541
+ record. A successful DELETE with no body already resolves with null data.
542
+
543
+ Every verb also takes a URL alone, through a signature with the same three parameters on every
544
+ verb, so a verb chosen at runtime (`client[verb](url)`) type-checks and a wrapper can implement
545
+ a verb with an arrow (`get: (url, config) => inner.get(url, config)`). With a body or a config,
546
+ choose the verb through `request({ method, url, data })` instead: the second argument is the
547
+ body for post/put/patch but the config for get/delete, so one call cannot serve both.
426
548
 
427
549
  ```typescript
428
550
  interface HttpClient {
@@ -440,11 +562,33 @@ interface HttpClient {
440
562
  * Makes a generic HTTP request. `data` is a field of THIS config object — the same body
441
563
  * `post(url, data, config)` takes as its second argument.
442
564
  */
565
+ request<T = unknown>(
566
+ config: FullRequestConfig & { responseType: 'text' },
567
+ ): Promise<HttpResponse<string>>
568
+ request<T = unknown>(
569
+ config: FullRequestConfig & { responseType: 'blob' },
570
+ ): Promise<HttpResponse<Blob>>
571
+ request<T = unknown>(
572
+ config: FullRequestConfig & { responseType: 'arraybuffer' },
573
+ ): Promise<HttpResponse<ArrayBuffer>>
443
574
  request<T = unknown>(config: FullRequestConfig): Promise<HttpResponse<T>>
444
575
 
445
576
  /**
446
577
  * Makes a GET request.
447
578
  */
579
+ get<T = unknown>(
580
+ url: string,
581
+ config: RequestConfig & { responseType: 'text' },
582
+ ): Promise<HttpResponse<string>>
583
+ get<T = unknown>(
584
+ url: string,
585
+ config: RequestConfig & { responseType: 'blob' },
586
+ ): Promise<HttpResponse<Blob>>
587
+ get<T = unknown>(
588
+ url: string,
589
+ config: RequestConfig & { responseType: 'arraybuffer' },
590
+ ): Promise<HttpResponse<ArrayBuffer>>
591
+ get<T = unknown>(url: string, config?: undefined, unused?: undefined): Promise<HttpResponse<T>>
448
592
  get<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
449
593
 
450
594
  /**
@@ -452,23 +596,84 @@ interface HttpClient {
452
596
  * `data` itself, so `post(url, { data: body })` sends `{"data":body}` — pass `body` directly.
453
597
  * A config (headers, params) is the THIRD argument.
454
598
  */
599
+ post<T = unknown>(
600
+ url: string,
601
+ data: unknown,
602
+ config: RequestConfig & { responseType: 'text' },
603
+ ): Promise<HttpResponse<string>>
604
+ post<T = unknown>(
605
+ url: string,
606
+ data: unknown,
607
+ config: RequestConfig & { responseType: 'blob' },
608
+ ): Promise<HttpResponse<Blob>>
609
+ post<T = unknown>(
610
+ url: string,
611
+ data: unknown,
612
+ config: RequestConfig & { responseType: 'arraybuffer' },
613
+ ): Promise<HttpResponse<ArrayBuffer>>
614
+ post<T = unknown>(url: string, data?: undefined, config?: undefined): Promise<HttpResponse<T>>
455
615
  post<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
456
616
 
457
617
  /**
458
618
  * Makes a PUT request. `data` is the request BODY (second argument) — never `{ data: body }`,
459
619
  * which sends `{"data":body}`; a config is the THIRD argument.
460
620
  */
621
+ put<T = unknown>(
622
+ url: string,
623
+ data: unknown,
624
+ config: RequestConfig & { responseType: 'text' },
625
+ ): Promise<HttpResponse<string>>
626
+ put<T = unknown>(
627
+ url: string,
628
+ data: unknown,
629
+ config: RequestConfig & { responseType: 'blob' },
630
+ ): Promise<HttpResponse<Blob>>
631
+ put<T = unknown>(
632
+ url: string,
633
+ data: unknown,
634
+ config: RequestConfig & { responseType: 'arraybuffer' },
635
+ ): Promise<HttpResponse<ArrayBuffer>>
636
+ put<T = unknown>(url: string, data?: undefined, config?: undefined): Promise<HttpResponse<T>>
461
637
  put<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
462
638
 
463
639
  /**
464
640
  * Makes a PATCH request. `data` is the request BODY (second argument) — never `{ data: body }`,
465
641
  * which sends `{"data":body}`; a config is the THIRD argument.
466
642
  */
643
+ patch<T = unknown>(
644
+ url: string,
645
+ data: unknown,
646
+ config: RequestConfig & { responseType: 'text' },
647
+ ): Promise<HttpResponse<string>>
648
+ patch<T = unknown>(
649
+ url: string,
650
+ data: unknown,
651
+ config: RequestConfig & { responseType: 'blob' },
652
+ ): Promise<HttpResponse<Blob>>
653
+ patch<T = unknown>(
654
+ url: string,
655
+ data: unknown,
656
+ config: RequestConfig & { responseType: 'arraybuffer' },
657
+ ): Promise<HttpResponse<ArrayBuffer>>
658
+ patch<T = unknown>(url: string, data?: undefined, config?: undefined): Promise<HttpResponse<T>>
467
659
  patch<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
468
660
 
469
661
  /**
470
662
  * Makes a DELETE request.
471
663
  */
664
+ delete<T = unknown>(
665
+ url: string,
666
+ config: RequestConfig & { responseType: 'text' },
667
+ ): Promise<HttpResponse<string>>
668
+ delete<T = unknown>(
669
+ url: string,
670
+ config: RequestConfig & { responseType: 'blob' },
671
+ ): Promise<HttpResponse<Blob>>
672
+ delete<T = unknown>(
673
+ url: string,
674
+ config: RequestConfig & { responseType: 'arraybuffer' },
675
+ ): Promise<HttpResponse<ArrayBuffer>>
676
+ delete<T = unknown>(url: string, config?: undefined, unused?: undefined): Promise<HttpResponse<T>>
472
677
  delete<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
473
678
 
474
679
  /**
@@ -1223,7 +1428,10 @@ Result returned by `useAIModels`.
1223
1428
 
1224
1429
  ```typescript
1225
1430
  interface UseAIModelsResult {
1226
- /** Available models, or an empty array while loading, as a readable store. */
1431
+ /**
1432
+ * Available models, or an empty array while loading or after a failed fetch, as a readable store. The list
1433
+ * keeps its identity until the catalog changes, the empty one included.
1434
+ */
1227
1435
  models: Readable<AppModelDefinition[]>
1228
1436
  /**
1229
1437
  * Per-mode server default model ids for the requester's tier, or `undefined`
@@ -1444,7 +1652,7 @@ interface UseFormResult<T extends FormValuesConstraint<T>> {
1444
1652
  /** Restores the baseline (optionally a new one) and clears touched, errors and submit state. */
1445
1653
  reset: (values?: Partial<T>) => void
1446
1654
  /** Applies externally loaded values without clearing submission state. */
1447
- updateValues: (values: Partial<T>, resetOptions?: FormResetOptions) => void
1655
+ updateValues: (values: Partial<T>, resetOptions?: FormUpdateOptions) => void
1448
1656
  /** Whole-form state tuple: edits mark only changed fields dirty; fills preserve them. */
1449
1657
  asState(): readonly [
1450
1658
  T,
@@ -1600,6 +1808,39 @@ interface UseOAuthConfig {
1600
1808
  }
1601
1809
  ```
1602
1810
 
1811
+ #### `UseOptimisticToggleOptions`
1812
+
1813
+ Options for {@link useOptimisticToggle}.
1814
+
1815
+ ```typescript
1816
+ interface UseOptimisticToggleOptions {
1817
+ /** The loaded server value. Mount the control only after its record exists. */
1818
+ value: boolean
1819
+ /** Saves the DESIRED value and returns the server-confirmed value; reject on failure. */
1820
+ commit: (desired: boolean) => Promise<boolean>
1821
+ /** Receives the newest failed save and the confirmed value restored by the controller. */
1822
+ onError?: (error: unknown, value: boolean) => void
1823
+ }
1824
+ ```
1825
+
1826
+ #### `UseOptimisticToggleResult`
1827
+
1828
+ What {@link useOptimisticToggle} returns: the boolean to render as readable stores and
1829
+ an argument-free action (the same names React returns).
1830
+
1831
+ ```typescript
1832
+ interface UseOptimisticToggleResult {
1833
+ /** The value to render. */
1834
+ value: Readable<boolean>
1835
+ /** Whether a save is running or waiting. */
1836
+ pending: Readable<boolean>
1837
+ /** The failure of the newest change. */
1838
+ error: Readable<unknown>
1839
+ /** Flips the value shown now and saves it; the same function for the component's life. */
1840
+ toggle: () => void
1841
+ }
1842
+ ```
1843
+
1603
1844
  #### `UseOptimisticValueResult`
1604
1845
 
1605
1846
  What {@link useOptimisticValue} returns: the state to render as readable
@@ -3355,6 +3596,29 @@ function useOAuth(config?: MaybeReadable<UseOAuthConfig | undefined>): UseOAuthR
3355
3596
 
3356
3597
  **Returns:** OAuth helpers: providers, getOAuthUrl, redirect, and loginViaPopup.
3357
3598
 
3599
+ #### `useOptimisticToggle(options)`
3600
+
3601
+ Owns the state and save ordering of a follow, favorite, star or subscription control
3602
+ while all markup stays in the app. Pass `toggle` straight to the click handler: it takes
3603
+ no argument and flips the value shown now. `commit(desired)` receives the value to SAVE,
3604
+ never the old one, and returns the server's boolean answer. Only the newest failure
3605
+ rolls the shown value back.
3606
+
3607
+ Saves run one at a time; clicks during a save coalesce to the newest desired value. Use
3608
+ `pending` for feedback, not to disable the control or drop a click. Mount it only after
3609
+ the record loads, key it by record identity, and keep it mounted through refetches. For
3610
+ a flag with a related count, use `useOptimisticValue` with both fields in one value.
3611
+
3612
+ ```typescript
3613
+ function useOptimisticToggle(
3614
+ options: MaybeReadable<UseOptimisticToggleOptions>,
3615
+ ): UseOptimisticToggleResult
3616
+ ```
3617
+
3618
+ - `options` — The server value, the save and an optional error callback (or a readable store of them: a new `value` syncs in while nothing is saving).
3619
+
3620
+ **Returns:** The value, pending and error state as readable stores, and the stable `toggle`.
3621
+
3358
3622
  #### `useOptimisticValue(options)`
3359
3623
 
3360
3624
  A server-backed value — a favorite, follow, like or bookmark button, a
@@ -4698,7 +4962,7 @@ Peer dependencies:
4698
4962
  - `@molecule/app-auth` ^3.0.0
4699
4963
  - `@molecule/app-code-editor` ^1.0.1
4700
4964
  - `@molecule/app-device` ^1.0.1
4701
- - `@molecule/app-forms` ^2.3.1
4965
+ - `@molecule/app-forms` ^2.4.0
4702
4966
  - `@molecule/app-http` ^1.0.1
4703
4967
  - `@molecule/app-i18n` ^1.0.1
4704
4968
  - `@molecule/app-ide` ^1.0.1
@@ -19,6 +19,7 @@ export * from './useHttp.js';
19
19
  export * from './useLogger.js';
20
20
  export * from './useLogin.js';
21
21
  export * from './useOAuth.js';
22
+ export * from './useOptimisticToggle.js';
22
23
  export * from './useOptimisticValue.js';
23
24
  export * from './usePasswordReset.js';
24
25
  export * from './usePlatform.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,yBAAyB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A6B,CAAA;AAC3C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
@@ -19,6 +19,7 @@ export * from './useHttp.js';
19
19
  export * from './useLogger.js';
20
20
  export * from './useLogin.js';
21
21
  export * from './useOAuth.js';
22
+ export * from './useOptimisticToggle.js';
22
23
  export * from './useOptimisticValue.js';
23
24
  export * from './usePasswordReset.js';
24
25
  export * from './usePlatform.js';
@@ -23,7 +23,10 @@ export declare function resetAIModelsCache(): void;
23
23
  * Result returned by `useAIModels`.
24
24
  */
25
25
  export interface UseAIModelsResult {
26
- /** Available models, or an empty array while loading, as a readable store. */
26
+ /**
27
+ * Available models, or an empty array while loading or after a failed fetch, as a readable store. The list
28
+ * keeps its identity until the catalog changes, the empty one included.
29
+ */
27
30
  models: Readable<AppModelDefinition[]>;
28
31
  /**
29
32
  * Per-mode server default model ids for the requester's tier, or `undefined`
@@ -1 +1 @@
1
- {"version":3,"file":"useAIModels.d.ts","sourceRoot":"","sources":["../../src/hooks/useAIModels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAgB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAMvF,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AA8FpE;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CASzC;AAWD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,8EAA8E;IAC9E,MAAM,EAAE,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAA;IACtC;;;OAGG;IACH,QAAQ,EAAE,QAAQ,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAA;IACpD,gEAAgE;IAChE,aAAa,EAAE,QAAQ,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAA;IACvD,mDAAmD;IACnD,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,+CAA+C;IAC/C,KAAK,EAAE,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,iBAAiB,CAuD5F"}
1
+ {"version":3,"file":"useAIModels.d.ts","sourceRoot":"","sources":["../../src/hooks/useAIModels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAgB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAMvF,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAqGpE;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CASzC;AAWD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,MAAM,EAAE,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAA;IACtC;;;OAGG;IACH,QAAQ,EAAE,QAAQ,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAAA;IACpD,gEAAgE;IAChE,aAAa,EAAE,QAAQ,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAAA;IACvD,mDAAmD;IACnD,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,+CAA+C;IAC/C,KAAK,EAAE,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,iBAAiB,CAuD5F"}
@@ -17,6 +17,12 @@ import { loadAIModelCatalog, pickFreeTierModel } from '@molecule/app-ai-models';
17
17
  import { useHttpClient } from '../context.js';
18
18
  import { fieldStore } from './live-store.js';
19
19
  import { toReadable } from './maybe-readable.js';
20
+ /**
21
+ * The list returned while the catalog loads or after it fails. One module-level array, like the catalog's
22
+ * own lists, which every caller on a scope shares: a new `[]` per read would change the identity of an
23
+ * unchanged catalog.
24
+ */
25
+ const NO_MODELS = [];
20
26
  /** One cache entry per scope — `''` for the unscoped catalog, else the projectId. */
21
27
  const caches = new Map();
22
28
  /**
@@ -173,9 +179,9 @@ export function useAIModels(projectId) {
173
179
  onDestroy(stopProjectId);
174
180
  const loading = derived(snapshot, (current) => !current.models && !current.error);
175
181
  return {
176
- models: derived(snapshot, (current) => current.models ?? []),
182
+ models: derived(snapshot, (current) => current.models ?? NO_MODELS),
177
183
  defaults: fieldStore(snapshot, 'defaults'),
178
- freeTierModel: derived(snapshot, (current) => pickFreeTierModel(current.models ?? [])),
184
+ freeTierModel: derived(snapshot, (current) => pickFreeTierModel(current.models ?? NO_MODELS)),
179
185
  loading,
180
186
  error: fieldStore(snapshot, 'error'),
181
187
  };
@@ -4,7 +4,7 @@
4
4
  * @module
5
5
  */
6
6
  import { type Readable } from 'svelte/store';
7
- import type { FieldRegistration, FieldState, FormController, FormOptions, FormResetOptions, FormState, FormValuesConstraint, RegisterOptions } from '@molecule/app-forms';
7
+ import type { FieldRegistration, FieldState, FormController, FormOptions, FormResetOptions, FormState, FormUpdateOptions, FormValuesConstraint, RegisterOptions } from '@molecule/app-forms';
8
8
  import { type MaybeReadable } from './maybe-readable.js';
9
9
  /**
10
10
  * Options for useForm hook.
@@ -59,7 +59,7 @@ export interface UseFormResult<T extends FormValuesConstraint<T>> {
59
59
  /** Restores the baseline (optionally a new one) and clears touched, errors and submit state. */
60
60
  reset: (values?: Partial<T>) => void;
61
61
  /** Applies externally loaded values without clearing submission state. */
62
- updateValues: (values: Partial<T>, resetOptions?: FormResetOptions) => void;
62
+ updateValues: (values: Partial<T>, resetOptions?: FormUpdateOptions) => void;
63
63
  /** Whole-form state tuple: edits mark only changed fields dirty; fills preserve them. */
64
64
  asState(): readonly [
65
65
  T,
@@ -1 +1 @@
1
- {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../src/hooks/useForm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAgB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEpE,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,oBAAoB,EACpB,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAO5B,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAEpE;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IACvF,+GAA+G;IAC/G,YAAY,CAAC,EAAE,gBAAgB,CAAA;IAC/B,+GAA+G;IAC/G,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAAA;IACpD;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,CAAA;CAC5D;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC;IAC9D,4BAA4B;IAC5B,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;IACjC,6CAA6C;IAC7C,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,mDAAmD;IACnD,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,mCAAmC;IACnC,YAAY,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAE/B,sDAAsD;IACtD,QAAQ,EAAE,CACR,IAAI,EAAE,MAA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AAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjF,OAAO,GAAE,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,SAAS,CAAM,GACzD,aAAa,CAAC,CAAC,CAAC,CAiMlB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAC3E,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,EACvB,IAAI,EAAE,CAAC,GACN,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAahB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,EAC7D,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,EACvB,IAAI,EAAE,MAAM,CAAC,GACZ,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAUlC"}
@@ -170,7 +170,7 @@ export function useForm(options = {}) {
170
170
  const next = typeof value === 'function'
171
171
  ? value(read())
172
172
  : value;
173
- form.updateValues(name === undefined ? next : { [name]: next }, { keepDirtyValues: true });
173
+ form.updateValues(name === undefined ? next : { [name]: next }, { keepDirtyValues: true, keepOmittedValues: name !== undefined });
174
174
  };
175
175
  stateTuples.set(name, [edit, fill]);
176
176
  return [visible, edit, fill];
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Svelte hook for a server-backed boolean toggle rendered with the app's own markup,
3
+ * porting React's `useOptimisticToggle`.
4
+ *
5
+ * @module
6
+ */
7
+ import { type Readable } from 'svelte/store';
8
+ import { type MaybeReadable } from './maybe-readable.js';
9
+ /** Options for {@link useOptimisticToggle}. */
10
+ export interface UseOptimisticToggleOptions {
11
+ /** The loaded server value. Mount the control only after its record exists. */
12
+ value: boolean;
13
+ /** Saves the DESIRED value and returns the server-confirmed value; reject on failure. */
14
+ commit: (desired: boolean) => Promise<boolean>;
15
+ /** Receives the newest failed save and the confirmed value restored by the controller. */
16
+ onError?: (error: unknown, value: boolean) => void;
17
+ }
18
+ /**
19
+ * What {@link useOptimisticToggle} returns: the boolean to render as readable stores and
20
+ * an argument-free action (the same names React returns).
21
+ */
22
+ export interface UseOptimisticToggleResult {
23
+ /** The value to render. */
24
+ value: Readable<boolean>;
25
+ /** Whether a save is running or waiting. */
26
+ pending: Readable<boolean>;
27
+ /** The failure of the newest change. */
28
+ error: Readable<unknown>;
29
+ /** Flips the value shown now and saves it; the same function for the component's life. */
30
+ toggle: () => void;
31
+ }
32
+ /**
33
+ * Owns the state and save ordering of a follow, favorite, star or subscription control
34
+ * while all markup stays in the app. Pass `toggle` straight to the click handler: it takes
35
+ * no argument and flips the value shown now. `commit(desired)` receives the value to SAVE,
36
+ * never the old one, and returns the server's boolean answer. Only the newest failure
37
+ * rolls the shown value back.
38
+ *
39
+ * Saves run one at a time; clicks during a save coalesce to the newest desired value. Use
40
+ * `pending` for feedback, not to disable the control or drop a click. Mount it only after
41
+ * the record loads, key it by record identity, and keep it mounted through refetches. For
42
+ * a flag with a related count, use `useOptimisticValue` with both fields in one value.
43
+ *
44
+ * @param options - The server value, the save and an optional error callback (or a
45
+ * readable store of them: a new `value` syncs in while nothing is saving).
46
+ * @returns The value, pending and error state as readable stores, and the stable `toggle`.
47
+ * @example
48
+ * ```svelte
49
+ * <script lang="ts">
50
+ * const subscription = useOptimisticToggle({
51
+ * value: thread.subscribed,
52
+ * commit: async (desired) => {
53
+ * const path = `/threads/${encodeURIComponent(thread.id)}/subscription`
54
+ * const response = desired
55
+ * ? await http.put<{ subscribed: boolean }>(path)
56
+ * : await http.delete<{ subscribed: boolean }>(path)
57
+ * return response.data.subscribed
58
+ * },
59
+ * })
60
+ * const { value, pending } = subscription
61
+ * </script>
62
+ *
63
+ * <button type="button" aria-pressed={$value} aria-busy={$pending} onclick={subscription.toggle}>
64
+ * ```
65
+ */
66
+ export declare const useOptimisticToggle: (options: MaybeReadable<UseOptimisticToggleOptions>) => UseOptimisticToggleResult;
67
+ //# sourceMappingURL=useOptimisticToggle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOptimisticToggle.d.ts","sourceRoot":"","sources":["../../src/hooks/useOptimisticToggle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAErD,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAGpE,+CAA+C;AAC/C,MAAM,WAAW,0BAA0B;IACzC,+EAA+E;IAC/E,KAAK,EAAE,OAAO,CAAA;IACd,yFAAyF;IACzF,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9C,0FAA0F;IAC1F,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnD;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,2BAA2B;IAC3B,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,4CAA4C;IAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,wCAAwC;IACxC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,0FAA0F;IAC1F,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,aAAa,CAAC,0BAA0B,CAAC,KACjD,yBAUF,CAAA"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Svelte hook for a server-backed boolean toggle rendered with the app's own markup,
3
+ * porting React's `useOptimisticToggle`.
4
+ *
5
+ * @module
6
+ */
7
+ import { derived } from 'svelte/store';
8
+ import { toReadable } from './maybe-readable.js';
9
+ import { useOptimisticValue } from './useOptimisticValue.js';
10
+ /**
11
+ * Owns the state and save ordering of a follow, favorite, star or subscription control
12
+ * while all markup stays in the app. Pass `toggle` straight to the click handler: it takes
13
+ * no argument and flips the value shown now. `commit(desired)` receives the value to SAVE,
14
+ * never the old one, and returns the server's boolean answer. Only the newest failure
15
+ * rolls the shown value back.
16
+ *
17
+ * Saves run one at a time; clicks during a save coalesce to the newest desired value. Use
18
+ * `pending` for feedback, not to disable the control or drop a click. Mount it only after
19
+ * the record loads, key it by record identity, and keep it mounted through refetches. For
20
+ * a flag with a related count, use `useOptimisticValue` with both fields in one value.
21
+ *
22
+ * @param options - The server value, the save and an optional error callback (or a
23
+ * readable store of them: a new `value` syncs in while nothing is saving).
24
+ * @returns The value, pending and error state as readable stores, and the stable `toggle`.
25
+ * @example
26
+ * ```svelte
27
+ * <script lang="ts">
28
+ * const subscription = useOptimisticToggle({
29
+ * value: thread.subscribed,
30
+ * commit: async (desired) => {
31
+ * const path = `/threads/${encodeURIComponent(thread.id)}/subscription`
32
+ * const response = desired
33
+ * ? await http.put<{ subscribed: boolean }>(path)
34
+ * : await http.delete<{ subscribed: boolean }>(path)
35
+ * return response.data.subscribed
36
+ * },
37
+ * })
38
+ * const { value, pending } = subscription
39
+ * </script>
40
+ *
41
+ * <button type="button" aria-pressed={$value} aria-busy={$pending} onclick={subscription.toggle}>
42
+ * ```
43
+ */
44
+ export const useOptimisticToggle = (options) => {
45
+ // `commit` gets only the desired boolean, never the previous value or a confirm callback.
46
+ const { value, pending, error, update } = useOptimisticValue(derived(toReadable(options), (current) => ({
47
+ ...current,
48
+ commit: (desired) => current.commit(desired),
49
+ })));
50
+ const toggle = () => update((current) => !current);
51
+ return { value, pending, error, toggle };
52
+ };
@@ -18,8 +18,8 @@ interface AuthStores<T, TRegister extends RegisterExtraShape<TRegister> = Record
18
18
  * signed out, or unavailable. Gate a public page's first render on it
19
19
  * (`{#if $sessionReady}`) so a handler that checks `user` never runs against a session
20
20
  * restore still in flight. `'unavailable'` also becomes ready and may still have a
21
- * null user. Without a session hint, an anonymous visitor settles in microtasks without
22
- * a request.
21
+ * null user. A stored token and cached user are ready synchronously. A visitor with
22
+ * no session candidate is ready synchronously without a request.
23
23
  */
24
24
  sessionReady: Readable<boolean>;
25
25
  error?: Readable<string | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-svelte",
3
- "version": "3.6.0",
3
+ "version": "3.7.2",
4
4
  "description": "Svelte framework bindings for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -38,7 +38,7 @@
38
38
  "@molecule/app-auth": "^3.0.0",
39
39
  "@molecule/app-code-editor": "^1.0.1",
40
40
  "@molecule/app-device": "^1.0.1",
41
- "@molecule/app-forms": "^2.3.1",
41
+ "@molecule/app-forms": "^2.4.0",
42
42
  "@molecule/app-http": "^1.0.1",
43
43
  "@molecule/app-i18n": "^1.0.1",
44
44
  "@molecule/app-ide": "^1.0.1",
@@ -67,10 +67,10 @@
67
67
  }
68
68
  },
69
69
  "devDependencies": {
70
- "@molecule/app-ai-chat": "1.8.0",
70
+ "@molecule/app-ai-chat": "1.8.1",
71
71
  "@molecule/app-ai-models": "1.4.4",
72
72
  "@molecule/app-framework-conformance": "0.0.0",
73
- "@molecule/app-utilities": "1.0.6",
73
+ "@molecule/app-utilities": "1.0.7",
74
74
  "@sveltejs/package": "3.0.2",
75
75
  "@sveltejs/vite-plugin-svelte": "7.1.2",
76
76
  "@types/node": "26.6.5",