@molecule/app-svelte 3.0.0 → 3.1.0

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-10-27T23:36:55.367Z
6
+ Generated: 2026-10-31T13:49:38.487Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-svelte
@@ -112,7 +112,10 @@ Reactive authentication state snapshot (initialized, authenticated, user, loadin
112
112
  interface AuthState<T = UserProfile> {
113
113
  /**
114
114
  * The session's state as one value — render from this instead of combining
115
- * `initialized`/`authenticated`/`loading`. See {@link AuthStatus}.
115
+ * `initialized`/`authenticated`/`loading`. `'loading'` is undecided, so wait
116
+ * and redirect only on `'unauthenticated'`; `'unavailable'` keeps the candidate
117
+ * for retry and can have a null profile. A restore failure other than 401/403
118
+ * never signs out. See {@link AuthStatus}.
116
119
  */
117
120
  status: AuthStatus
118
121
  /**
@@ -120,11 +123,14 @@ interface AuthState<T = UserProfile> {
120
123
  */
121
124
  initialized: boolean
122
125
  /**
123
- * Whether the user is authenticated.
126
+ * Whether the client has an authenticated session. This is not a server
127
+ * confirmation flag: during `'unavailable'` it can be false for a retained
128
+ * token/cookie-only candidate with no cached profile. Use `status` for redirects.
124
129
  */
125
130
  authenticated: boolean
126
131
  /**
127
- * Current user (if authenticated).
132
+ * Current user, or null when none is cached. In particular, an `'unavailable'`
133
+ * token/cookie-only restore has a retained candidate but no profile yet.
128
134
  */
129
135
  user: T | null
130
136
  /**
@@ -178,12 +184,23 @@ interface AuthClient<T = UserProfile, TRegister extends RegisterExtraShape<TRegi
178
184
  * Updates the cached user object (state + persistent storage) without
179
185
  * hitting the network. Intended for local refreshes after a per-app
180
186
  * mutation (e.g., the user just PATCHed their own profile and the
181
- * server returned the canonical row). Does NOT change tokens.
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.
182
192
  *
183
- * This does not sign the client in: `authenticated` and `status` are
184
- * unchanged, so an anonymous client stays anonymous. Use
185
- * {@link login} / {@link register} for a credential exchange, or
186
- * {@link setSession} when the token was issued outside the client.
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.
187
204
  */
188
205
  setUser(user: T | null): void;
189
206
  /**
@@ -198,10 +215,13 @@ interface AuthClient<T = UserProfile, TRegister extends RegisterExtraShape<TRegi
198
215
  * which would violate the storage contract and make a stored bearer token
199
216
  * JS-readable (XSS-exfiltratable). Pass `null` to clear it.
200
217
  *
201
- * This changes token storage only; it does not sign the client in
202
- * (`authenticated` and `status` are unchanged). Use {@link login} /
203
- * {@link register} for a credential exchange, or call {@link setSession}
204
- * with the token and the user to establish an already-issued session.
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.
205
225
  */
206
226
  setAccessToken(token: string | null): void;
207
227
  /**
@@ -226,7 +246,16 @@ interface AuthClient<T = UserProfile, TRegister extends RegisterExtraShape<TRegi
226
246
  */
227
247
  login(credentials: LoginCredentials): Promise<AuthResult<T>>;
228
248
  /**
229
- * Logs out the current user.
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.
230
259
  */
231
260
  logout(): Promise<void>;
232
261
  /**
@@ -278,37 +307,6 @@ interface AuthClient<T = UserProfile, TRegister extends RegisterExtraShape<TRegi
278
307
  * until the cookie restore decides.
279
308
  *
280
309
  * Do not put this call (or a `/me` request of your own) in front of the first
281
- * render, and do not render a loading screen over a session it just restored:
282
- * `whenRestored()` already resolves as soon as the restore has settled, and the
283
- * HTTP gate built on it holds requests for exactly that window.
284
- */
285
- initialize(): Promise<void>;
286
- /**
287
- * Re-checks a restored session against the server, in the background — the
288
- * boot-time validation an app with a stored token needs when a revoked or
289
- * expired token must sign the user out. Call it AFTER the first render
290
- * (`initialize()` restores synchronously from storage; this costs one request).
291
- *
292
- * - The server confirms the user: the session is refreshed and {@link AuthState.status}
293
- * stays `'authenticated'`.
294
- * - The server answers 401 or 403: the token is dead — the stored session is
295
- * cleared and the status becomes `'unauthenticated'`.
296
- * - The server cannot confirm the session — a network failure, a 5xx, or a 404
297
- * from a misconfigured {@link AuthClientConfig.currentUserEndpoint}: the
298
- * session (token AND user) is KEPT and the status becomes `'unavailable'`, so
299
- * the app can retry instead of signing the user out over a bad connection or a
300
- * route that does not exist. The 404 error names `currentUserEndpoint`.
301
- *
302
- * Do not hand-write this beside the client: a parallel token/user store for a
303
- * "validating"/"unavailable" flag is the race this method removes.
304
- *
305
- * Optional: a provider with no restorable session has nothing to validate.
306
- */
307
- validateSession?(): Promise<void>;
308
- /**
309
- * Resolves when the session restore started by `initialize()` has settled — the point
310
- * after which the client knows whether this visitor is signed in.
311
- *
312
310
  // … truncated — the full declaration is in node_modules/@molecule/app-svelte/dist
313
311
  ```
314
312
 
@@ -397,9 +395,20 @@ interface FormController<T extends FormValuesConstraint<T> = Record<string, unkn
397
395
  * `defaultValues`, or the values a previous `reset(values)` established.
398
396
  * Passing `values` merges them over the current baseline and makes the
399
397
  * result the new baseline, so a form reset to freshly loaded or saved data
400
- * reads clean (`isDirty === false`).
398
+ * reads clean (`isDirty === false`). A changed non-null `id` replaces the
399
+ * record and cancels a pending submit.
401
400
  */
402
401
  reset(values?: Partial<T>): void
402
+ /**
403
+ * Applies externally loaded values without clearing submission state.
404
+ *
405
+ * The new clean baseline is the original `defaultValues` plus this latest
406
+ * record, never a merge of earlier records. With `keepDirtyValues`, edited
407
+ * fields retain their values while pristine fields take the loaded values.
408
+ * A changed non-null `id` still replaces the record and cancels a pending
409
+ * submit. Equal-content baselines cause no update.
410
+ */
411
+ updateValues(values: Partial<T>, resetOptions?: FormResetOptions): void
403
412
  /**
404
413
  * Handles form submission.
405
414
  */
@@ -433,6 +442,14 @@ interface FormOptions<T extends FormValuesConstraint<T>> {
433
442
  * is created. Mutating this object afterwards does not change the baseline.
434
443
  */
435
444
  defaultValues?: Partial<T>
445
+ /**
446
+ * Externally loaded values, merged over `defaultValues` as the clean
447
+ * baseline. Framework bindings also apply later content changes; use
448
+ * `resetOptions.keepDirtyValues` to preserve edits while pristine fields fill.
449
+ */
450
+ values?: Partial<T>
451
+ /** Controls how framework bindings apply changed `values`. */
452
+ resetOptions?: FormResetOptions
436
453
  /**
437
454
  * Validation mode.
438
455
  */
@@ -1645,14 +1662,14 @@ Create form stores from a form provider and options.
1645
1662
  ```typescript
1646
1663
  function createFormStores<T extends FormValuesConstraint<T>>(
1647
1664
  provider: FormProvider,
1648
- options: FormOptions<T>,
1665
+ options: SvelteFormOptions<T>,
1649
1666
  ): FormStores<T>
1650
1667
  ```
1651
1668
 
1652
1669
  - `provider` — Form provider instance
1653
- - `options` — Form creation options
1670
+ - `options` — Narrowed creation options; `values` and `resetOptions` are not accepted.
1654
1671
 
1655
- **Returns:** Form stores and actions
1672
+ **Returns:** Form stores and actions, including `updateValues(values, { keepDirtyValues })` for explicit late-record delivery. `keepDirtyValues` defaults to false; true retains edited fields while pristine fields take the delivered record.
1656
1673
 
1657
1674
  #### `createFieldStore(controller, name)`
1658
1675
 
@@ -4,7 +4,15 @@
4
4
  * @module
5
5
  */
6
6
  import { type Readable } from 'svelte/store';
7
- import type { FieldRegistration, FieldState, FormController, FormOptions, FormProvider, FormState, FormValuesConstraint, RegisterOptions } from '@molecule/app-forms';
7
+ import type { FieldRegistration, FieldState, FormController, FormOptions, FormProvider, FormResetOptions, FormState, FormValuesConstraint, RegisterOptions } from '@molecule/app-forms';
8
+ /**
9
+ * Svelte form creation options. Unlike `FormOptions`, this narrowed type does
10
+ * not accept `values` or `resetOptions`: store-backed getters are not observed.
11
+ * Deliver records after creation through the returned `updateValues(values,
12
+ * { keepDirtyValues })` method. The option defaults to false; pass true to retain
13
+ * edited fields while pristine fields take the record.
14
+ */
15
+ type SvelteFormOptions<T extends FormValuesConstraint<T>> = Omit<FormOptions<T>, 'values' | 'resetOptions'>;
8
16
  /**
9
17
  * Form stores and actions return type.
10
18
  */
@@ -27,6 +35,8 @@ interface FormStores<T extends FormValuesConstraint<T>> {
27
35
  handleSubmit: (onSubmit: (values: T) => void | Promise<void>, onError?: (errors: Partial<Record<keyof T, string>>) => void) => (event?: {
28
36
  preventDefault?: () => void;
29
37
  }) => Promise<void>;
38
+ /** Deliver a record; `keepDirtyValues` retains edits while pristine fields fill. */
39
+ updateValues: (values: Partial<T>, resetOptions?: FormResetOptions) => void;
30
40
  reset: (values?: Partial<T>) => void;
31
41
  validate: () => Promise<boolean>;
32
42
  destroy: () => void;
@@ -36,8 +46,10 @@ interface FormStores<T extends FormValuesConstraint<T>> {
36
46
  * Create form stores from a form provider and options.
37
47
  *
38
48
  * @param provider - Form provider instance
39
- * @param options - Form creation options
40
- * @returns Form stores and actions
49
+ * @param options - Narrowed creation options; `values` and `resetOptions` are not accepted.
50
+ * @returns Form stores and actions, including `updateValues(values, { keepDirtyValues })`
51
+ * for explicit late-record delivery. `keepDirtyValues` defaults to false; true retains
52
+ * edited fields while pristine fields take the delivered record.
41
53
  *
42
54
  * @example
43
55
  * ```svelte
@@ -72,7 +84,7 @@ interface FormStores<T extends FormValuesConstraint<T>> {
72
84
  * </form>
73
85
  * ```
74
86
  */
75
- export declare function createFormStores<T extends FormValuesConstraint<T>>(provider: FormProvider, options: FormOptions<T>): FormStores<T>;
87
+ export declare function createFormStores<T extends FormValuesConstraint<T>>(provider: FormProvider, options: SvelteFormOptions<T>): FormStores<T>;
76
88
  /**
77
89
  * Create a readable store that tracks a single field's state.
78
90
  *
@@ -1 +1 @@
1
- {"version":3,"file":"forms.d.ts","sourceRoot":"","sources":["../../src/stores/forms.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAW,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAE/D,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAE5B;;GAEG;AACH,UAAU,UAAU,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC;IACpD,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;IACjC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1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,CAAC,CAAC,EAC7B,IAAI,EAAE,CAAC,GACN,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAI5B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EACnF,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,EAC7B,IAAI,EAAE,CAAC,GACN,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAIhB"}
@@ -4,12 +4,21 @@
4
4
  * @module
5
5
  */
6
6
  import { derived, readable } from 'svelte/store';
7
+ /** Subscribe first, then publish state delivered before this readable started. */
8
+ function subscribeAndRefresh(controller, read, set) {
9
+ const refresh = () => set(read());
10
+ const unsubscribe = controller.subscribe(refresh);
11
+ refresh();
12
+ return unsubscribe;
13
+ }
7
14
  /**
8
15
  * Create form stores from a form provider and options.
9
16
  *
10
17
  * @param provider - Form provider instance
11
- * @param options - Form creation options
12
- * @returns Form stores and actions
18
+ * @param options - Narrowed creation options; `values` and `resetOptions` are not accepted.
19
+ * @returns Form stores and actions, including `updateValues(values, { keepDirtyValues })`
20
+ * for explicit late-record delivery. `keepDirtyValues` defaults to false; true retains
21
+ * edited fields while pristine fields take the delivered record.
13
22
  *
14
23
  * @example
15
24
  * ```svelte
@@ -47,11 +56,7 @@ import { derived, readable } from 'svelte/store';
47
56
  export function createFormStores(provider, options) {
48
57
  const controller = provider.createForm(options);
49
58
  // Main form state store
50
- const formState = readable(controller.getState(), (set) => {
51
- return controller.subscribe((state) => {
52
- set(state);
53
- });
54
- });
59
+ const formState = readable(controller.getState(), (set) => subscribeAndRefresh(controller, () => controller.getState(), set));
55
60
  // Derived stores
56
61
  const isValid = derived(formState, ($state) => $state.isValid);
57
62
  const isDirty = derived(formState, ($state) => $state.isDirty);
@@ -90,6 +95,9 @@ export function createFormStores(provider, options) {
90
95
  const handleSubmit = (onSubmit, onError) => {
91
96
  return controller.handleSubmit(onSubmit, onError);
92
97
  };
98
+ const updateValues = (values, resetOptions = {}) => {
99
+ controller.updateValues(values, resetOptions);
100
+ };
93
101
  const reset = (values) => {
94
102
  controller.reset(values);
95
103
  };
@@ -112,6 +120,7 @@ export function createFormStores(provider, options) {
112
120
  setError,
113
121
  clearErrors,
114
122
  handleSubmit,
123
+ updateValues,
115
124
  reset,
116
125
  validate,
117
126
  destroy,
@@ -141,11 +150,7 @@ export function createFormStores(provider, options) {
141
150
  * ```
142
151
  */
143
152
  export function createFieldStore(controller, name) {
144
- return readable(controller.getFieldState(name), (set) => {
145
- return controller.subscribe(() => {
146
- set(controller.getFieldState(name));
147
- });
148
- });
153
+ return readable(controller.getFieldState(name), (set) => subscribeAndRefresh(controller, () => controller.getFieldState(name), set));
149
154
  }
150
155
  /**
151
156
  * Create a readable store that tracks a single field's value.
@@ -169,10 +174,6 @@ export function createFieldStore(controller, name) {
169
174
  * ```
170
175
  */
171
176
  export function createWatchStore(controller, name) {
172
- return readable(controller.getValue(name), (set) => {
173
- return controller.subscribe(() => {
174
- set(controller.getValue(name));
175
- });
176
- });
177
+ return readable(controller.getValue(name), (set) => subscribeAndRefresh(controller, () => controller.getValue(name), set));
177
178
  }
178
179
  //# sourceMappingURL=forms.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"forms.js","sourceRoot":"","sources":["../../src/stores/forms.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAiB,QAAQ,EAAE,MAAM,cAAc,CAAA;AA0C/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAsB,EACtB,OAAuB;IAEvB,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAI,OAAO,CAAC,CAAA;IAElD,wBAAwB;IACxB,MAAM,SAAS,GAA2B,QAAQ,CAChD,UAAU,CAAC,QAA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,OAAO;QACL,SAAS;QACT,OAAO;QACP,OAAO;QACP,YAAY;QACZ,MAAM;QACN,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,KAAK;QACL,QAAQ;QACR,OAAO;QACP,mGAAmG;QACnG,UAAU;KACX,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAA6B,EAC7B,IAAO;IAEP,OAAO,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,GAAsC,EAAE,EAAE,CACzF,mBAAmB,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAC3E,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAA6B,EAC7B,IAAO;IAEP,OAAO,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,GAA0B,EAAE,EAAE,CACxE,mBAAmB,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CACtE,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-svelte",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Svelte framework bindings for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",