@molecule/app-svelte 3.2.0 → 3.2.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.
Files changed (2) hide show
  1. package/README.md +209 -185
  2. package/package.json +1 -1
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-10-31T13:49:38.487Z
6
+ Generated: 2026-11-08T06:24:48.844Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-svelte
@@ -118,25 +118,30 @@ interface AuthState<T = UserProfile> {
118
118
  * never signs out. See {@link AuthStatus}.
119
119
  */
120
120
  status: AuthStatus
121
+
121
122
  /**
122
123
  * Whether auth state has been initialized.
123
124
  */
124
125
  initialized: boolean
126
+
125
127
  /**
126
128
  * Whether the client has an authenticated session. This is not a server
127
129
  * confirmation flag: during `'unavailable'` it can be false for a retained
128
130
  * token/cookie-only candidate with no cached profile. Use `status` for redirects.
129
131
  */
130
132
  authenticated: boolean
133
+
131
134
  /**
132
135
  * Current user, or null when none is cached. In particular, an `'unavailable'`
133
136
  * token/cookie-only restore has a retained candidate but no profile yet.
134
137
  */
135
138
  user: T | null
139
+
136
140
  /**
137
141
  * Whether an auth operation is in progress.
138
142
  */
139
143
  loading: boolean
144
+
140
145
  /**
141
146
  * Last auth error (if any).
142
147
  */
@@ -151,165 +156,89 @@ Provides login/logout/register flows, token management, profile
151
156
  updates, and auth state subscription.
152
157
 
153
158
  ```typescript
154
- interface AuthClient<T = UserProfile, TRegister extends RegisterExtraShape<TRegister> = Record<never, never>> {
155
- /**
156
- * Returns the current authentication state snapshot.
157
- *
158
- * READING the state starts the client's one session restore when nobody has called
159
- * {@link initialize} yet — lazily and exactly once, sharing the promise an explicit
160
- * `initialize()` returns. A hook (`useAuth()`), a subscriber, `isAuthenticated()` and
161
- * `getUser()` are reads too, so a client whose entry file dropped the template's
162
- * `authClient.initialize()` line still restores instead of reporting `'loading'`
163
- * forever.
164
- */
165
- getState(): AuthState<T>;
166
- /**
167
- * Returns whether the user is currently authenticated.
168
- */
169
- isAuthenticated(): boolean;
170
- /**
171
- * Gets the current user.
172
- */
173
- getUser(): T | null;
174
- /**
175
- * Optional ownership marker for the current session. Compare values only within
176
- * this client: replacing or ending a session changes it, including re-adopting
177
- * the same token and user. Profile updates and same-session refreshes keep it.
178
- * Consumers can use it to discard stale async work without treating editable
179
- * user fields as an immutable account identifier. Providers without this
180
- * capability require the consumer's own stable identity check.
181
- */
182
- getSessionRevision?(): number;
183
- /**
184
- * Updates the cached user object (state + persistent storage) without
185
- * hitting the network. Intended for local refreshes after a per-app
186
- * mutation (e.g., the user just PATCHed their own profile and the
187
- * server returned the canonical row). A non-null profile does NOT change
188
- * tokens or sign the client in: `authenticated` and `status` are unchanged,
189
- * so an anonymous client stays anonymous. Use {@link login} /
190
- * {@link register} for a credential exchange, or {@link setSession} when
191
- * the token was issued outside the client.
192
- *
193
- * Passing `null` on a signed-in client, or while any session operation is
194
- * pending, ends the local session: it clears the access token, refresh token
195
- * and cached user, stops automatic refresh, and settles `authenticated: false`
196
- * with `status: 'unauthenticated'` in one notification. Every older operation
197
- * loses session ownership, and a persistent sign-out marker prevents a reload
198
- * from restoring its credentials or a late cookie. A late credential exchange
199
- * is revoked best-effort when a logout endpoint is configured, without blocking
200
- * the caller. This method does not otherwise call the server for a settled
201
- * session; use {@link logout} for explicit server revocation. On a settled
202
- * anonymous client, `null` only clears the cached profile and leaves tokens
203
- * and auth state unchanged.
204
- */
205
- setUser(user: T | null): void;
206
- /**
207
- * Gets the current access token.
208
- */
209
- getAccessToken(): string | null;
210
- /**
211
- * Stores the access token in the configured token storage adapter (in a
212
- * browser, Web Storage; `'memory'` where no browser store exists). Use this
213
- * to seed the token after an out-of-band exchange (e.g. the OAuth
214
- * code→token redirect) instead of writing to `localStorage` directly,
215
- * which would violate the storage contract and make a stored bearer token
216
- * JS-readable (XSS-exfiltratable). Pass `null` to clear it.
217
- *
218
- * This changes token storage only: passing `null` does not by itself sign a
219
- * signed-in client out, and a non-null token does not sign an anonymous
220
- * client in (`authenticated` and `status` are unchanged). Use {@link logout}
221
- * to end a session, or {@link setUser} with `null` for local-only sign-out.
222
- * Use {@link login} / {@link register} for a credential exchange, or call
223
- * {@link setSession} with the token and user to establish an already-issued
224
- * session.
225
- */
226
- setAccessToken(token: string | null): void;
227
- /**
228
- * Adopts a session an out-of-band exchange already established: stores the
229
- * access token (and the refresh token when given), caches the user, and
230
- * sets the COMPLETE state — `initialized`, `authenticated`, `status:
231
- * 'authenticated'`, no error — in one update, with one subscriber
232
- * notification. Every hook reading the shared client sees the user as
233
- * signed in immediately.
234
- *
235
- * This is the way to seed an OAuth/custom sign-in. Calling
236
- * {@link setAccessToken} and {@link setUser} instead does NOT sign the
237
- * client in.
238
- */
239
- setSession(session: AuthSessionSeed<T>): void;
240
- /**
241
- * Gets the refresh token.
242
- */
243
- getRefreshToken(): string | null;
244
- /**
245
- * Logs in with credentials.
246
- */
247
- login(credentials: LoginCredentials): Promise<AuthResult<T>>;
248
- /**
249
- * Logs out the current user. The server request is best-effort: a missing
250
- * logout route (404), any other HTTP failure, or a network error never makes
251
- * this method reject. It always clears the access token, refresh token and
252
- * cached user, stops automatic refresh, and publishes one settled
253
- * `authenticated: false`, `status: 'unauthenticated'` transition. Every pending
254
- * session operation loses ownership; a persistent marker prevents reload from
255
- * restoring an older session, and late credentials are revoked best-effort.
256
- *
257
- * When the API has no logout route, set {@link AuthClientConfigOptions.logoutEndpoint}
258
- * to `null` (or `''`) to skip the request. Local sign-out still happens.
259
- */
260
- logout(): Promise<void>;
261
- /**
262
- * Registers a new user. Accepts the base fields plus the app's own fields
263
- * (`TRegister`) at the top level — see {@link RegisterData}.
264
- */
265
- register(data: RegisterData<TRegister>): Promise<AuthResult<T>>;
266
- /**
267
- * Refreshes the access token.
268
- */
269
- refresh(): Promise<AuthResult<T>>;
270
- /**
271
- * Requests a password reset.
272
- */
273
- requestPasswordReset(data: PasswordResetRequest): Promise<void>;
274
- /**
275
- * Confirms a password reset.
276
- */
277
- confirmPasswordReset(data: PasswordResetConfirm): Promise<void>;
278
- /**
279
- * Updates the current user's profile.
280
- * Returns the saved profile: the answer applied onto the signed-in user field
281
- * by field, with or without an `id` — a field it carries replaces the value
282
- * (`null` clears it), one it omits or leaves `undefined` is kept, so a field
283
- * cleared by omission must arrive as `null`. A non-object answer is returned
284
- * as it came. An answer for a replaced or ended session leaves the current one
285
- * untouched.
286
- */
287
- updateProfile(data: Partial<T>): Promise<T>;
288
- /**
289
- * Changes the current user's password.
290
- */
291
- changePassword(oldPassword: string, newPassword: string): Promise<void>;
292
- /**
293
- * Initializes auth state (e.g., from stored tokens).
294
- *
295
- * LAZY and IDEMPOTENT: the first read of the state ({@link getState},
296
- * {@link subscribe}, `useAuth()`) starts this same restore when nobody has called
297
- * `initialize()`, and every later call shares the one promise instead of sending a
298
- * second request. An app that keeps the template's explicit call behaves exactly as
299
- * before; an app that loses that line still restores its session.
300
- *
301
- * With a stored token AND a stored user it marks the session `'authenticated'`
302
- * SYNCHRONOUSLY — before its first `await` — so the first render is the
303
- * signed-in UI and no page waits on a verification round trip. Any check
304
- * (a refresh, the cookie-restore probe) settles behind that render, and only an
305
- * explicit 401/403 ends the session; a network/5xx/404 failure keeps it and
306
- * reports `'unavailable'`. With no stored user the client stays `'loading'`
307
- * until the cookie restore decides.
308
- *
309
- * Do not put this call (or a `/me` request of your own) in front of the first
310
- // … truncated — the full declaration is in node_modules/@molecule/app-svelte/dist
159
+ interface AuthClient<
160
+ T = UserProfile,
161
+ TRegister extends RegisterExtraShape<TRegister> = Record<never, never>,
162
+ > {
163
+ /** Returns the current authentication state snapshot. */
164
+ getState(): AuthState<T>
165
+
166
+ /** Returns whether the user is currently authenticated. */
167
+ isAuthenticated(): boolean
168
+
169
+ /** Gets the current user. */
170
+ getUser(): T | null
171
+
172
+ /** Optional ownership marker for the current session. */
173
+ getSessionRevision?(): number
174
+
175
+ /** Updates the cached user object (state + persistent storage) without hitting the network. */
176
+ setUser(user: T | null): void
177
+
178
+ /** Gets the current access token. */
179
+ getAccessToken(): string | null
180
+
181
+ /** Stores the access token in the configured token storage adapter (in a browser, Web Storage; `'memory'` where no browser store exists). */
182
+ setAccessToken(token: string | null): void
183
+
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… */
185
+ setSession(session: AuthSessionSeed<T>): void
186
+
187
+ /** Gets the refresh token. */
188
+ getRefreshToken(): string | null
189
+
190
+ /** Logs in with credentials. */
191
+ login(credentials: LoginCredentials): Promise<AuthResult<T>>
192
+
193
+ /** Logs out the current user. */
194
+ logout(): Promise<void>
195
+
196
+ /** Registers a new user. */
197
+ register(data: RegisterData<TRegister>): Promise<AuthResult<T>>
198
+
199
+ /** Refreshes the access token. */
200
+ refresh(): Promise<AuthResult<T>>
201
+
202
+ /** Requests a password reset. */
203
+ requestPasswordReset(data: PasswordResetRequest): Promise<void>
204
+
205
+ /** Confirms a password reset. */
206
+ confirmPasswordReset(data: PasswordResetConfirm): Promise<void>
207
+
208
+ /** Updates the current user's profile. */
209
+ updateProfile(data: Partial<T>): Promise<T>
210
+
211
+ /** Changes the current user's password. */
212
+ changePassword(oldPassword: string, newPassword: string): Promise<void>
213
+
214
+ /** Initializes auth state (e.g., from stored tokens). */
215
+ initialize(): Promise<void>
216
+
217
+ /** Re-checks a restored session against the server, in the background — the boot-time validation an app with a stored token needs when a revoked or expired token… */
218
+ validateSession?(): Promise<void>
219
+
220
+ /** Resolves when the session restore started by `initialize()` has settled — the point after which the client knows whether this visitor is signed in. */
221
+ whenRestored?(): Promise<void>
222
+
223
+ /** Subscribes to auth state changes. */
224
+ subscribe(callback: (state: AuthState<T>) => void): () => void
225
+
226
+ /** Subscribes to auth state changes (alias for subscribe). */
227
+ onAuthChange(callback: (state: AuthState<T>) => void): () => void
228
+
229
+ /** Gets the current access token (alias for getAccessToken). */
230
+ getToken?(): string | null
231
+
232
+ /** Adds an auth event listener. */
233
+ addEventListener(listener: AuthEventListener<T>): () => void
234
+
235
+ /** Destroys the auth client. */
236
+ destroy(): void
237
+ }
311
238
  ```
312
239
 
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`.)_
241
+
313
242
  #### `FormController`
314
243
 
315
244
  Form controller interface.
@@ -322,72 +251,77 @@ interface FormController<T extends FormValuesConstraint<T> = Record<string, unkn
322
251
  * Gets the current form state.
323
252
  */
324
253
  getState(): FormState<T>
254
+
325
255
  /**
326
256
  * Gets the value of a specific field.
327
257
  */
328
258
  getValue(name: string): unknown
329
259
  getValue<K extends keyof T>(name: K): T[K]
260
+
330
261
  /**
331
262
  * Gets all form values.
332
263
  */
333
264
  getValues(): T
265
+
334
266
  /**
335
267
  * Sets the value of a specific field.
336
268
  */
337
269
  setValue(
338
270
  name: string,
339
271
  value: unknown,
340
- options?: {
341
- shouldValidate?: boolean
342
- shouldDirty?: boolean
343
- shouldTouch?: boolean
344
- },
272
+ options?: { shouldValidate?: boolean; shouldDirty?: boolean; shouldTouch?: boolean },
345
273
  ): void
274
+
346
275
  /**
347
276
  * Sets multiple values at once.
348
277
  */
349
- setValues(
350
- values: Partial<T>,
351
- options?: {
352
- shouldValidate?: boolean
353
- },
354
- ): void
278
+ setValues(values: Partial<T>, options?: { shouldValidate?: boolean }): void
279
+
355
280
  /**
356
281
  * Gets the error for a specific field.
357
282
  */
358
283
  getError(name: string): string | undefined
284
+
359
285
  /**
360
286
  * Sets the error for a specific field.
361
287
  */
362
288
  setError(name: string, error: string | undefined): void
289
+
363
290
  /**
364
291
  * Clears the error for a specific field.
365
292
  */
366
293
  clearError<K extends keyof T>(name: K): void
294
+
367
295
  /**
368
296
  * Clears all errors.
369
297
  */
370
298
  clearErrors(): void
299
+
371
300
  /**
372
301
  * Gets the field state for a specific field.
373
302
  */
374
303
  getFieldState<K extends keyof T>(name: K): FieldState<T[K]>
304
+
375
305
  /**
376
306
  * Registers a field for form management.
377
307
  */
378
308
  register(nameOrOptions: string | RegisterOptions, options?: RegisterOptions): FieldRegistration
309
+
379
310
  /**
380
311
  * Unregisters a field.
381
312
  */
382
313
  unregister(name: string): void
314
+
383
315
  /**
384
316
  * Validates a specific field.
385
317
  */
386
318
  validateField<K extends keyof T>(name: K): Promise<boolean>
319
+
387
320
  /**
388
321
  * Validates all fields.
389
322
  */
390
323
  validate(): Promise<boolean>
324
+
391
325
  /**
392
326
  * Resets the form and clears errors, touched fields and submission state.
393
327
  *
@@ -399,6 +333,7 @@ interface FormController<T extends FormValuesConstraint<T> = Record<string, unkn
399
333
  * record and cancels a pending submit.
400
334
  */
401
335
  reset(values?: Partial<T>): void
336
+
402
337
  /**
403
338
  * Applies externally loaded values without clearing submission state.
404
339
  *
@@ -409,6 +344,7 @@ interface FormController<T extends FormValuesConstraint<T> = Record<string, unkn
409
344
  * submit. Equal-content baselines cause no update.
410
345
  */
411
346
  updateValues(values: Partial<T>, resetOptions?: FormResetOptions): void
347
+
412
348
  /**
413
349
  * Handles form submission.
414
350
  */
@@ -416,14 +352,17 @@ interface FormController<T extends FormValuesConstraint<T> = Record<string, unkn
416
352
  onSubmit: (values: T) => void | Promise<void>,
417
353
  onError?: (errors: Partial<Record<keyof T, string>>) => void,
418
354
  ): (event?: { preventDefault?: () => void }) => Promise<void>
355
+
419
356
  /**
420
357
  * Sets focus to a field.
421
358
  */
422
359
  setFocus(name: keyof T): void
360
+
423
361
  /**
424
362
  * Subscribes to form state changes.
425
363
  */
426
364
  subscribe(callback: (state: FormState<T>) => void): () => void
365
+
427
366
  /**
428
367
  * Destroys the form controller.
429
368
  */
@@ -442,26 +381,32 @@ interface FormOptions<T extends FormValuesConstraint<T>> {
442
381
  * is created. Mutating this object afterwards does not change the baseline.
443
382
  */
444
383
  defaultValues?: Partial<T>
384
+
445
385
  /**
446
386
  * Externally loaded values, merged over `defaultValues` as the clean
447
387
  * baseline. Framework bindings also apply later content changes; use
448
388
  * `resetOptions.keepDirtyValues` to preserve edits while pristine fields fill.
449
389
  */
450
390
  values?: Partial<T>
391
+
451
392
  /** Controls how framework bindings apply changed `values`. */
452
393
  resetOptions?: FormResetOptions
394
+
453
395
  /**
454
396
  * Validation mode.
455
397
  */
456
398
  mode?: 'onSubmit' | 'onChange' | 'onBlur' | 'all'
399
+
457
400
  /**
458
401
  * Revalidation mode.
459
402
  */
460
403
  reValidateMode?: 'onChange' | 'onBlur' | 'onSubmit'
404
+
461
405
  /**
462
406
  * Whether to focus the first error field on submit.
463
407
  */
464
408
  shouldFocusError?: boolean
409
+
465
410
  /**
466
411
  * Form-level validation function.
467
412
  */
@@ -483,54 +428,65 @@ interface HttpClient {
483
428
  * Base URL for all requests.
484
429
  */
485
430
  baseURL: string
431
+
486
432
  /**
487
433
  * Default headers for all requests.
488
434
  */
489
435
  defaultHeaders: Record<string, string>
436
+
490
437
  /**
491
438
  * Makes a generic HTTP request. `data` is a field of THIS config object — the same body
492
439
  * `post(url, data, config)` takes as its second argument.
493
440
  */
494
441
  request<T = unknown>(config: FullRequestConfig): Promise<HttpResponse<T>>
442
+
495
443
  /**
496
444
  * Makes a GET request.
497
445
  */
498
446
  get<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
447
+
499
448
  /**
500
449
  * Makes a POST request. `data` is the request BODY, not a config object: the wire body is
501
450
  * `data` itself, so `post(url, { data: body })` sends `{"data":body}` — pass `body` directly.
502
451
  * A config (headers, params) is the THIRD argument.
503
452
  */
504
453
  post<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
454
+
505
455
  /**
506
456
  * Makes a PUT request. `data` is the request BODY (second argument) — never `{ data: body }`,
507
457
  * which sends `{"data":body}`; a config is the THIRD argument.
508
458
  */
509
459
  put<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
460
+
510
461
  /**
511
462
  * Makes a PATCH request. `data` is the request BODY (second argument) — never `{ data: body }`,
512
463
  * which sends `{"data":body}`; a config is the THIRD argument.
513
464
  */
514
465
  patch<T = unknown>(url: string, data?: unknown, config?: RequestConfig): Promise<HttpResponse<T>>
466
+
515
467
  /**
516
468
  * Makes a DELETE request.
517
469
  */
518
470
  delete<T = unknown>(url: string, config?: RequestConfig): Promise<HttpResponse<T>>
471
+
519
472
  /**
520
473
  * Adds a request interceptor.
521
474
  * Returns a function to remove the interceptor.
522
475
  */
523
476
  addRequestInterceptor(interceptor: RequestInterceptor): () => void
477
+
524
478
  /**
525
479
  * Adds a response interceptor.
526
480
  * Returns a function to remove the interceptor.
527
481
  */
528
482
  addResponseInterceptor(interceptor: ResponseInterceptor): () => void
483
+
529
484
  /**
530
485
  * Adds an error interceptor.
531
486
  * Returns a function to remove the interceptor.
532
487
  */
533
488
  addErrorInterceptor(interceptor: ErrorInterceptor): () => void
489
+
534
490
  /**
535
491
  * Sets the authorization token.
536
492
  *
@@ -542,11 +498,13 @@ interface HttpClient {
542
498
  * the resolver is removed, the static token is sent again.
543
499
  */
544
500
  setAuthToken(token: string | null): void
501
+
545
502
  /**
546
503
  * Returns the token the client applies to its next request: the resolver's answer when one
547
504
  * is registered, else the static token from `setAuthToken`.
548
505
  */
549
506
  getAuthToken(): string | null
507
+
550
508
  /**
551
509
  * Registers the LIVE token resolver every request of this client reads, or clears it with
552
510
  * `null`.
@@ -577,6 +535,7 @@ interface HttpClient {
577
535
  * @param resolver - Returns the current access token (or null/undefined), or `null` to clear.
578
536
  */
579
537
  setAuthTokenResolver?(resolver: AuthTokenResolver | null): void
538
+
580
539
  /**
581
540
  * Registers a handler for authentication errors (401).
582
541
  *
@@ -598,6 +557,7 @@ interface I18nProvider {
598
557
  * Gets the current locale.
599
558
  */
600
559
  getLocale(): string
560
+
601
561
  /**
602
562
  * Sets the current locale.
603
563
  *
@@ -612,14 +572,17 @@ interface I18nProvider {
612
572
  * from a working one until a user notices the wrong language on screen.
613
573
  */
614
574
  setLocale(locale: string): Promise<void>
575
+
615
576
  /**
616
577
  * Gets all available locales.
617
578
  */
618
579
  getLocales(): LocaleConfig[]
580
+
619
581
  /**
620
582
  * Adds a locale.
621
583
  */
622
584
  addLocale(config: LocaleConfig): void
585
+
623
586
  /**
624
587
  * Removes a locale by code, notifying subscribers so language pickers
625
588
  * built on `onLocaleChange` re-render their list. If the removed locale
@@ -631,6 +594,7 @@ interface I18nProvider {
631
594
  * otherwise.
632
595
  */
633
596
  removeLocale(code: string): boolean
597
+
634
598
  /**
635
599
  * Adds translations to a locale. Auto-creates the locale if it doesn't exist.
636
600
  *
@@ -641,6 +605,7 @@ interface I18nProvider {
641
605
  * contract on the API side.
642
606
  */
643
607
  addTranslations(locale: string, translations: Translations, namespace?: string): void
608
+
644
609
  /**
645
610
  * Translates a key with optional interpolation values and pluralization.
646
611
  *
@@ -658,11 +623,9 @@ interface I18nProvider {
658
623
  t(
659
624
  key: string,
660
625
  values?: InterpolationValues,
661
- options?: {
662
- defaultValue?: string
663
- count?: number
664
- },
626
+ options?: { defaultValue?: string; count?: number },
665
627
  ): string
628
+
666
629
  /**
667
630
  * Checks if a translation key exists.
668
631
  *
@@ -677,46 +640,42 @@ interface I18nProvider {
677
640
  * @returns `true` if the key has a translation.
678
641
  */
679
642
  exists(key: string): boolean
643
+
680
644
  /**
681
645
  * Formats a number according to the current locale.
682
646
  *
683
647
  * @returns The locale-formatted number string.
684
648
  */
685
649
  formatNumber(value: number, options?: NumberFormatOptions): string
650
+
686
651
  /**
687
652
  * Formats a date according to the current locale.
688
653
  *
689
654
  * @returns The locale-formatted date string.
690
655
  */
691
656
  formatDate(value: Date | number | string, options?: DateFormatOptions): string
657
+
692
658
  /**
693
659
  * Formats a relative time (e.g. "2 hours ago").
694
660
  *
695
661
  * @returns The locale-formatted relative time string.
696
662
  */
697
- formatRelativeTime(
698
- value: Date | number,
699
- options?: {
700
- unit?: Intl.RelativeTimeFormatUnit
701
- },
702
- ): string
663
+ formatRelativeTime(value: Date | number, options?: { unit?: Intl.RelativeTimeFormatUnit }): string
664
+
703
665
  /**
704
666
  * Formats a list (e.g. "A, B, and C").
705
667
  *
706
668
  * @returns The locale-formatted list string.
707
669
  */
708
- formatList(
709
- values: string[],
710
- options?: {
711
- type?: 'conjunction' | 'disjunction' | 'unit'
712
- },
713
- ): string
670
+ formatList(values: string[], options?: { type?: 'conjunction' | 'disjunction' | 'unit' }): string
671
+
714
672
  /**
715
673
  * Subscribes to locale changes.
716
674
  *
717
675
  * @returns An unsubscribe function.
718
676
  */
719
677
  onLocaleChange(listener: (locale: string) => void): () => void
678
+
720
679
  /**
721
680
  * Gets a counter that advances for every change `onLocaleChange` announces:
722
681
  * a locale switch, a locale-list change, or translations added for a locale
@@ -738,24 +697,29 @@ interface I18nProvider {
738
697
  * @returns The provider's current revision.
739
698
  */
740
699
  getRevision?(): number
700
+
741
701
  /**
742
702
  * Gets the text direction for the current locale.
743
703
  *
744
704
  * @returns `'ltr'` or `'rtl'`.
745
705
  */
746
706
  getDirection(): 'ltr' | 'rtl'
707
+
747
708
  /**
748
709
  * Checks if a translation key exists (alias for exists).
749
710
  */
750
711
  hasKey?(key: string): boolean
712
+
751
713
  /**
752
714
  * Checks if the provider is ready.
753
715
  */
754
716
  isReady?(): boolean
717
+
755
718
  /**
756
719
  * Registers a callback for when the provider is ready.
757
720
  */
758
721
  onReady?(callback: () => void): () => void
722
+
759
723
  /**
760
724
  * Registers a lazily-loaded content module for automatic reload on locale changes.
761
725
  * All registered content is reloaded during `setLocale()` before listeners fire,
@@ -778,42 +742,52 @@ interface Logger {
778
742
  * Logs a trace message.
779
743
  */
780
744
  trace(message: string, ...args: unknown[]): void
745
+
781
746
  /**
782
747
  * Logs a debug message.
783
748
  */
784
749
  debug(message: string, ...args: unknown[]): void
750
+
785
751
  /**
786
752
  * Logs an info message.
787
753
  */
788
754
  info(message: string, ...args: unknown[]): void
755
+
789
756
  /**
790
757
  * Logs a warning message.
791
758
  */
792
759
  warn(message: string, ...args: unknown[]): void
760
+
793
761
  /**
794
762
  * Logs an error message.
795
763
  */
796
764
  error(message: string | Error, ...args: unknown[]): void
765
+
797
766
  /**
798
767
  * Sets the log level.
799
768
  */
800
769
  setLevel(level: LogLevel): void
770
+
801
771
  /**
802
772
  * Gets the current log level.
803
773
  */
804
774
  getLevel(): LogLevel
775
+
805
776
  /**
806
777
  * Creates a child logger with a namespace.
807
778
  */
808
779
  child(name: string, context?: Record<string, unknown>): Logger
780
+
809
781
  /**
810
782
  * Adds additional context to the logger.
811
783
  */
812
784
  withContext(context: Record<string, unknown>): Logger
785
+
813
786
  /**
814
787
  * Adds a transport.
815
788
  */
816
789
  addTransport(transport: LogTransport): () => void
790
+
817
791
  /**
818
792
  * Removes a transport.
819
793
  */
@@ -832,30 +806,37 @@ interface LoggerProvider {
832
806
  * Gets a logger by name, or the root logger if no name given.
833
807
  */
834
808
  getLogger(name?: string): Logger
809
+
835
810
  /**
836
811
  * Creates a named logger.
837
812
  */
838
813
  createLogger(nameOrConfig: string | LoggerConfig, config?: LoggerConfig): Logger
814
+
839
815
  /**
840
816
  * Sets the global log level.
841
817
  */
842
818
  setLevel(level: LogLevel): void
819
+
843
820
  /**
844
821
  * Gets the global log level.
845
822
  */
846
823
  getLevel(): LogLevel
824
+
847
825
  /**
848
826
  * Adds a global transport.
849
827
  */
850
828
  addTransport(transport: LogTransport): () => void
829
+
851
830
  /**
852
831
  * Enables logging.
853
832
  */
854
833
  enable(): void
834
+
855
835
  /**
856
836
  * Disables logging.
857
837
  */
858
838
  disable(): void
839
+
859
840
  /**
860
841
  * Checks if logging is enabled.
861
842
  *
@@ -875,18 +856,22 @@ interface RouteLocation {
875
856
  * Current pathname.
876
857
  */
877
858
  pathname: string
859
+
878
860
  /**
879
861
  * Query string (including leading ?).
880
862
  */
881
863
  search: string
864
+
882
865
  /**
883
866
  * Hash (including leading #).
884
867
  */
885
868
  hash: string
869
+
886
870
  /**
887
871
  * State data passed with navigation.
888
872
  */
889
873
  state?: unknown
874
+
890
875
  /**
891
876
  * Unique key for this location.
892
877
  */
@@ -906,26 +891,32 @@ interface Router {
906
891
  * Returns the current route location (pathname, search, hash, state).
907
892
  */
908
893
  getLocation(): RouteLocation
894
+
909
895
  /**
910
896
  * Gets the current route params.
911
897
  */
912
898
  getParams<T extends RouteParams = RouteParams>(): T
899
+
913
900
  /**
914
901
  * Gets the current query params.
915
902
  */
916
903
  getQuery(): QueryParams
904
+
917
905
  /**
918
906
  * Gets a specific query parameter.
919
907
  */
920
908
  getQueryParam(key: string): string | undefined
909
+
921
910
  /**
922
911
  * Gets the current hash.
923
912
  */
924
913
  getHash(): string
914
+
925
915
  /**
926
916
  * Navigates to a path.
927
917
  */
928
918
  navigate(path: string, options?: NavigateOptions): void
919
+
929
920
  /**
930
921
  * Navigates to a named route.
931
922
  */
@@ -935,36 +926,44 @@ interface Router {
935
926
  query?: QueryParams,
936
927
  options?: NavigateOptions,
937
928
  ): void
929
+
938
930
  /**
939
931
  * Goes back in history.
940
932
  */
941
933
  back(): void
934
+
942
935
  /**
943
936
  * Goes forward in history.
944
937
  */
945
938
  forward(): void
939
+
946
940
  /**
947
941
  * Goes to a specific point in history.
948
942
  */
949
943
  go(delta: number): void
944
+
950
945
  /**
951
946
  * Updates the current query params.
952
947
  */
953
948
  setQuery(params: QueryParams, options?: NavigateOptions): void
949
+
954
950
  /**
955
951
  * Updates a specific query parameter.
956
952
  */
957
953
  setQueryParam(key: string, value: string | undefined, options?: NavigateOptions): void
954
+
958
955
  /**
959
956
  * Updates the current hash.
960
957
  */
961
958
  setHash(hash: string, options?: NavigateOptions): void
959
+
962
960
  /**
963
961
  * Checks if a path matches the current location.
964
962
  *
965
963
  * @returns `true` if the path matches the current route.
966
964
  */
967
965
  isActive(path: string, exact?: boolean): boolean
966
+
968
967
  /**
969
968
  * Matches a path pattern against a pathname.
970
969
  */
@@ -972,26 +971,32 @@ interface Router {
972
971
  pattern: string,
973
972
  pathname: string,
974
973
  ): RouteMatch<Params> | null
974
+
975
975
  /**
976
976
  * Generates a URL from a named route.
977
977
  */
978
978
  generatePath(name: string, params?: RouteParams, query?: QueryParams): string
979
+
979
980
  /**
980
981
  * Subscribes to route changes.
981
982
  */
982
983
  subscribe(listener: RouteChangeListener): () => void
984
+
983
985
  /**
984
986
  * Adds a navigation guard.
985
987
  */
986
988
  addGuard(guard: NavigationGuard): () => void
989
+
987
990
  /**
988
991
  * Registers route definitions.
989
992
  */
990
993
  registerRoutes(routes: RouteDefinition[]): void
994
+
991
995
  /**
992
996
  * Gets all registered routes.
993
997
  */
994
998
  getRoutes(): RouteDefinition[]
999
+
995
1000
  /**
996
1001
  * Destroys the router.
997
1002
  */
@@ -1009,10 +1014,12 @@ interface StoreConfig<T> {
1009
1014
  * Initial state value.
1010
1015
  */
1011
1016
  initialState: T
1017
+
1012
1018
  /**
1013
1019
  * Optional name for debugging.
1014
1020
  */
1015
1021
  name?: string
1022
+
1016
1023
  /**
1017
1024
  * Optional middleware functions.
1018
1025
  */
@@ -1032,15 +1039,18 @@ interface Store<T> {
1032
1039
  * Gets the current state.
1033
1040
  */
1034
1041
  getState(): T
1042
+
1035
1043
  /**
1036
1044
  * Sets the state (partial or via updater function).
1037
1045
  */
1038
1046
  setState(partial: Partial<T> | ((state: T) => Partial<T>)): void
1047
+
1039
1048
  /**
1040
1049
  * Subscribes to state changes.
1041
1050
  * Returns an unsubscribe function.
1042
1051
  */
1043
1052
  subscribe(listener: StateListener<T>): () => void
1053
+
1044
1054
  /**
1045
1055
  * Destroys the store and cleans up subscriptions.
1046
1056
  */
@@ -1074,34 +1084,42 @@ interface StorageProvider {
1074
1084
  * Gets a value from storage.
1075
1085
  */
1076
1086
  get<T = unknown>(key: string): Promise<T | null>
1087
+
1077
1088
  /**
1078
1089
  * Sets a value in storage.
1079
1090
  */
1080
1091
  set<T = unknown>(key: string, value: T): Promise<void>
1092
+
1081
1093
  /**
1082
1094
  * Removes a value from storage.
1083
1095
  */
1084
1096
  remove(key: string): Promise<void>
1097
+
1085
1098
  /**
1086
1099
  * Clears all values from storage.
1087
1100
  */
1088
1101
  clear(): Promise<void>
1102
+
1089
1103
  /**
1090
1104
  * Gets all keys in storage.
1091
1105
  */
1092
1106
  keys(): Promise<string[]>
1107
+
1093
1108
  /**
1094
1109
  * Gets multiple values from storage.
1095
1110
  */
1096
1111
  getMany?<T = unknown>(keys: string[]): Promise<Map<string, T | null>>
1112
+
1097
1113
  /**
1098
1114
  * Sets multiple values in storage.
1099
1115
  */
1100
1116
  setMany?<T = unknown>(entries: Array<[string, T]>): Promise<void>
1117
+
1101
1118
  /**
1102
1119
  * Removes multiple values from storage.
1103
1120
  */
1104
1121
  removeMany?(keys: string[]): Promise<void>
1122
+
1105
1123
  /**
1106
1124
  * Reads a value synchronously.
1107
1125
  *
@@ -1115,6 +1133,7 @@ interface StorageProvider {
1115
1133
  * @returns The stored value, or `null` when it is absent, unreadable or corrupt.
1116
1134
  */
1117
1135
  getSync?<T = unknown>(key: string): T | null
1136
+
1118
1137
  /**
1119
1138
  * Subscribes to changes made to a key OUTSIDE this provider instance — for
1120
1139
  * example another browser tab's `localStorage` write.
@@ -1141,16 +1160,19 @@ interface ThemeProvider {
1141
1160
  * Returns the currently active theme.
1142
1161
  */
1143
1162
  getTheme(): Theme
1163
+
1144
1164
  /**
1145
1165
  * Sets the active theme by reference or by name.
1146
1166
  *
1147
1167
  * @param theme - A `Theme` object or a theme name string to activate.
1148
1168
  */
1149
1169
  setTheme(theme: Theme | string): void
1170
+
1150
1171
  /**
1151
1172
  * Toggles between light and dark mode for the active theme.
1152
1173
  */
1153
1174
  toggleMode(): void
1175
+
1154
1176
  /**
1155
1177
  * Subscribes to theme changes. The callback fires whenever
1156
1178
  * `setTheme()` or `toggleMode()` is called.
@@ -1159,11 +1181,13 @@ interface ThemeProvider {
1159
1181
  * @returns An unsubscribe function.
1160
1182
  */
1161
1183
  subscribe(callback: (theme: Theme) => void): () => void
1184
+
1162
1185
  /**
1163
1186
  * Returns all registered themes. Optional — not all providers
1164
1187
  * support multiple themes.
1165
1188
  */
1166
1189
  getThemes?(): Theme[]
1190
+
1167
1191
  /**
1168
1192
  * Returns the theme a render WITHOUT a browser produces — a server or
1169
1193
  * build-time render, which has no storage and no `prefers-color-scheme`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-svelte",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
4
4
  "description": "Svelte framework bindings for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",