@fougere/svelte 0.6.0-alpha.0 → 0.7.0-alpha.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/dist/index.d.ts +1 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -13
- package/dist/index.js.map +1 -1
- package/dist/useCurrentUser.d.ts +1 -8
- package/dist/useCurrentUser.d.ts.map +1 -1
- package/dist/useCurrentUser.js +1 -8
- package/dist/useCurrentUser.js.map +1 -1
- package/dist/useFormFor.d.ts +2 -9
- package/dist/useFormFor.d.ts.map +1 -1
- package/dist/useFormFor.js +6 -13
- package/dist/useFormFor.js.map +1 -1
- package/dist/useFougereData.d.ts +1 -14
- package/dist/useFougereData.d.ts.map +1 -1
- package/dist/useFougereData.js +1 -14
- package/dist/useFougereData.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +1 -13
- package/src/useCurrentUser.ts +1 -8
- package/src/useFormFor.ts +6 -13
- package/src/useFougereData.ts +1 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@fougere/svelte` — the four primitives, in Svelte, for any host that renders it.
|
|
3
|
-
*
|
|
4
|
-
* There is no `@fougere/sveltekit` beside it, and that is not an omission: SvelteKit
|
|
5
|
-
* serves Web-standard `Request`/`Response` from `+server.ts`, and it hands every
|
|
6
|
-
* `load` function its own `event`, so there is no ambient-request lookup to package.
|
|
7
|
-
* A SvelteKit app mounts `@fougere/app/web` directly, the way the TanStack and React
|
|
8
|
-
* Router demos do. Next needed 124 lines because `next/headers` exists; SvelteKit
|
|
9
|
-
* needs none because it does not.
|
|
10
|
-
*
|
|
11
|
-
* So: one package per UI framework, and a host package only when the host has
|
|
12
|
-
* something that is genuinely its own.
|
|
13
|
-
*/
|
|
1
|
+
/** `@fougere/svelte` — the four primitives, in Svelte, for any host that renders it. */
|
|
14
2
|
export { useQuery, useCommand, type QueryState, type QueryStore, type CommandStore } from './useFougereData.js';
|
|
15
3
|
export { useFormFor, type FormOptions } from './useFormFor.js';
|
|
16
4
|
export { useCurrentUser, hydrateSession, refreshSession } from './useCurrentUser.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAChH,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE7D,YAAY,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACT,WAAW,GACZ,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@fougere/svelte` — the four primitives, in Svelte, for any host that renders it.
|
|
3
|
-
*
|
|
4
|
-
* There is no `@fougere/sveltekit` beside it, and that is not an omission: SvelteKit
|
|
5
|
-
* serves Web-standard `Request`/`Response` from `+server.ts`, and it hands every
|
|
6
|
-
* `load` function its own `event`, so there is no ambient-request lookup to package.
|
|
7
|
-
* A SvelteKit app mounts `@fougere/app/web` directly, the way the TanStack and React
|
|
8
|
-
* Router demos do. Next needed 124 lines because `next/headers` exists; SvelteKit
|
|
9
|
-
* needs none because it does not.
|
|
10
|
-
*
|
|
11
|
-
* So: one package per UI framework, and a host package only when the host has
|
|
12
|
-
* something that is genuinely its own.
|
|
13
|
-
*/
|
|
1
|
+
/** `@fougere/svelte` — the four primitives, in Svelte, for any host that renders it. */
|
|
14
2
|
export { useQuery, useCommand } from './useFougereData.js';
|
|
15
3
|
export { useFormFor } from './useFormFor.js';
|
|
16
4
|
export { useCurrentUser, hydrateSession, refreshSession } from './useCurrentUser.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAuD,MAAM,qBAAqB,CAAC;AAChH,OAAO,EAAE,UAAU,EAAoB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/useCurrentUser.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The session: resolved server-side, read here as a store. `refresh()` re-reads it
|
|
3
|
-
* after a client-side auth change — no page reload, no hand-rolled /api/me.
|
|
4
|
-
*
|
|
5
|
-
* SvelteKit hands a `load` function's data down through the page, so a layout that
|
|
6
|
-
* already resolved the session can `hydrate()` this store and the page arrives
|
|
7
|
-
* knowing its user. Without it, the store fetches once on first read.
|
|
8
|
-
*/
|
|
1
|
+
/** The session. */
|
|
9
2
|
import { type Readable } from 'svelte/store';
|
|
10
3
|
import type { SessionView } from '@fougere/app/client';
|
|
11
4
|
/** Seed the store from what the server already resolved (a `load` function's data). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrentUser.d.ts","sourceRoot":"","sources":["../src/useCurrentUser.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"useCurrentUser.d.ts","sourceRoot":"","sources":["../src/useCurrentUser.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAKvD,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAGtD;AAED,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAIpD;AAED,wBAAgB,cAAc,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAK1D,OAAO,EAAa,QAAQ,CAAC,WAAW,CAAC;IACzC,IAAI;IACJ,QAAQ;IACR,OAAO;EAEV"}
|
package/dist/useCurrentUser.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The session: resolved server-side, read here as a store. `refresh()` re-reads it
|
|
3
|
-
* after a client-side auth change — no page reload, no hand-rolled /api/me.
|
|
4
|
-
*
|
|
5
|
-
* SvelteKit hands a `load` function's data down through the page, so a layout that
|
|
6
|
-
* already resolved the session can `hydrate()` this store and the page arrives
|
|
7
|
-
* knowing its user. Without it, the store fetches once on first read.
|
|
8
|
-
*/
|
|
1
|
+
/** The session. */
|
|
9
2
|
import { writable, derived } from 'svelte/store';
|
|
10
3
|
const session = writable({ user: null });
|
|
11
4
|
let fetched = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrentUser.js","sourceRoot":"","sources":["../src/useCurrentUser.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"useCurrentUser.js","sourceRoot":"","sources":["../src/useCurrentUser.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAiB,MAAM,cAAc,CAAC;AAGhE,MAAM,OAAO,GAAG,QAAQ,CAAc,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AACtD,IAAI,OAAO,GAAG,KAAK,CAAC;AAEpB,uFAAuF;AACvF,MAAM,UAAU,cAAc,CAAC,IAAiB;IAC9C,OAAO,GAAG,IAAI,CAAC;IACf,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAClD,OAAO,GAAG,IAAI,CAAC;IACf,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAgB,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,cAAc;IAC5B,0EAA0E;IAC1E,IAAI,CAAC,OAAO,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,KAAK,cAAc,EAAE,CAAC;IAErE,OAAO;QACL,OAAO,EAAE,OAAgC;QACzC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAiB,CAAC;QAC7E,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC;QAC/D,OAAO,EAAE,cAAc;KACxB,CAAC;AACJ,CAAC"}
|
package/dist/useFormFor.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The form contract — state, validation, submission, error mapping. Never a widget.
|
|
3
|
-
*
|
|
4
|
-
* `values` is a writable store, so a component binds straight into it with
|
|
5
|
-
* `bind:value={$form.values[field.name]}`. That is the Svelte equivalent of Vue's
|
|
6
|
-
* reactive object and of React's `setValue`: the same contract, three ways of
|
|
7
|
-
* holding a value, none of which is a rule.
|
|
8
|
-
*/
|
|
1
|
+
/** The form contract — state, validation, submission, error mapping. */
|
|
9
2
|
import { type Readable, type Writable } from 'svelte/store';
|
|
10
3
|
import { type FormEntity, type FormField } from '@fougere/app/client';
|
|
11
4
|
export interface FormOptions {
|
|
@@ -24,7 +17,7 @@ export declare function useFormFor<T = Record<string, unknown>>(entity: FormEnti
|
|
|
24
17
|
values: Writable<Record<string, unknown>>;
|
|
25
18
|
errors: Writable<Record<string, string>>;
|
|
26
19
|
submit: () => Promise<T | null>;
|
|
27
|
-
|
|
20
|
+
validator: () => boolean;
|
|
28
21
|
valid: Readable<boolean>;
|
|
29
22
|
/** `{ loading, error }` of the underlying command. */
|
|
30
23
|
command: import("./useFougereData.js").CommandStore<T>;
|
package/dist/useFormFor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormFor.d.ts","sourceRoot":"","sources":["../src/useFormFor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"useFormFor.d.ts","sourceRoot":"","sources":["../src/useFormFor.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAA0B,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEpF,OAAO,EAML,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,qBAAqB,CAAC;AAG7B,MAAM,WAAW,WAAW;IAC1B,mDAAmD;IACnD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,wBAAgB,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAE,WAAgB;;IAqCjG;kDAC8C;kBACkC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;;;kBApBlF,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;qBANpB,OAAO;;IAgC3B,sDAAsD;;EAGzD"}
|
package/dist/useFormFor.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The form contract — state, validation, submission, error mapping. Never a widget.
|
|
3
|
-
*
|
|
4
|
-
* `values` is a writable store, so a component binds straight into it with
|
|
5
|
-
* `bind:value={$form.values[field.name]}`. That is the Svelte equivalent of Vue's
|
|
6
|
-
* reactive object and of React's `setValue`: the same contract, three ways of
|
|
7
|
-
* holding a value, none of which is a rule.
|
|
8
|
-
*/
|
|
1
|
+
/** The form contract — state, validation, submission, error mapping. */
|
|
9
2
|
import { writable, derived, get } from 'svelte/store';
|
|
10
3
|
import { validationErrorsOf } from '@fougere/core/contract';
|
|
11
4
|
import { entityKeyOf, errorsByField, formFieldsOf, payloadOf, } from '@fougere/app/client';
|
|
@@ -18,17 +11,17 @@ export function useFormFor(entity, options = {}) {
|
|
|
18
11
|
const values = writable(Object.fromEntries(fields.map((field) => [field.name, options.initial?.[field.name] ?? field.default])));
|
|
19
12
|
const errors = writable({});
|
|
20
13
|
const command = useCommand(entity, options.op ?? 'create');
|
|
21
|
-
/** Local pre-
|
|
22
|
-
function
|
|
14
|
+
/** Local pre-verdict — same rules as the handler, saves a lost round-trip. */
|
|
15
|
+
function validator() {
|
|
23
16
|
const result = entity.validate(payloadOf(get(values)));
|
|
24
17
|
errors.set(result.success ? {} : errorsByField(result.errors));
|
|
25
18
|
return result.success;
|
|
26
19
|
}
|
|
27
20
|
async function submit() {
|
|
28
|
-
if (!
|
|
21
|
+
if (!validator())
|
|
29
22
|
return null;
|
|
30
23
|
try {
|
|
31
|
-
return await command.execute({ params: options.params,
|
|
24
|
+
return await command.execute({ params: options.params, input: payloadOf(get(values)) });
|
|
32
25
|
}
|
|
33
26
|
catch (err) {
|
|
34
27
|
const refusals = validationErrorsOf(err);
|
|
@@ -48,7 +41,7 @@ export function useFormFor(entity, options = {}) {
|
|
|
48
41
|
values,
|
|
49
42
|
errors,
|
|
50
43
|
submit,
|
|
51
|
-
|
|
44
|
+
validator,
|
|
52
45
|
valid,
|
|
53
46
|
/** `{ loading, error }` of the underlying command. */
|
|
54
47
|
command,
|
package/dist/useFormFor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormFor.js","sourceRoot":"","sources":["../src/useFormFor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"useFormFor.js","sourceRoot":"","sources":["../src/useFormFor.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAgC,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,SAAS,GAIV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAWjD,MAAM,UAAU,UAAU,CAA8B,MAAkB,EAAE,OAAO,GAAgB,EAAE;IACnG,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,MAAM,GAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAE5D,8EAA8E;IAC9E,gFAAgF;IAChF,MAAM,MAAM,GAAsC,QAAQ,CACxD,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CACxG,CAAC;IACF,MAAM,MAAM,GAAG,QAAQ,CAAyB,EAAE,CAAC,CAAC;IACpD,MAAM,OAAO,GAAG,UAAU,CAAI,MAAqB,EAAE,OAAO,CA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;QACzG,MAAM;QACN,MAAM;QACN,MAAM;QACN,SAAS;QACT,KAAK;QACL,sDAAsD;QACtD,OAAO;KACR,CAAC;AACJ,CAAC"}
|
package/dist/useFougereData.d.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The couple — useQuery (reads) and useCommand (writes), in Svelte.
|
|
3
|
-
*
|
|
4
|
-
* Stores, not runes, and that is a packaging decision with a reason: a `.svelte.ts`
|
|
5
|
-
* file needs the Svelte compiler to run over it, so a library shipping runes ships
|
|
6
|
-
* SOURCE and forces every consumer's bundler to compile it. `svelte/store` is plain
|
|
7
|
-
* TypeScript, compiles with `tsc` like every other package here, and a store still
|
|
8
|
-
* auto-subscribes with `$query` inside a component. The consumer's ergonomics are
|
|
9
|
-
* the same; the packaging is honest.
|
|
10
|
-
*
|
|
11
|
-
* The name is `useQuery`, not `createQuery`, on purpose — the four primitives are
|
|
12
|
-
* one vocabulary across Nuxt, React and Svelte, and renaming them per ecosystem
|
|
13
|
-
* would make the same gesture read as three different things.
|
|
14
|
-
*/
|
|
1
|
+
/** The couple — useQuery (reads) and useCommand (writes), in Svelte. */
|
|
15
2
|
import { get, type Readable } from 'svelte/store';
|
|
16
3
|
import type { FougereError } from '@fougere/core/contract';
|
|
17
4
|
import { type CallInput, type EntityClass } from '@fougere/app/client';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFougereData.d.ts","sourceRoot":"","sources":["../src/useFougereData.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"useFougereData.d.ts","sourceRoot":"","sources":["../src/useFougereData.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAY,GAAG,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAcL,KAAK,SAAS,EACd,KAAK,WAAW,EACjB,MAAM,qBAAq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(writes), in Svelte.
|
|
3
|
-
*
|
|
4
|
-
* Stores, not runes, and that is a packaging decision with a reason: a `.svelte.ts`
|
|
5
|
-
* file needs the Svelte compiler to run over it, so a library shipping runes ships
|
|
6
|
-
* SOURCE and forces every consumer's bundler to compile it. `svelte/store` is plain
|
|
7
|
-
* TypeScript, compiles with `tsc` like every other package here, and a store still
|
|
8
|
-
* auto-subscribes with `$query` inside a component. The consumer's ergonomics are
|
|
9
|
-
* the same; the packaging is honest.
|
|
10
|
-
*
|
|
11
|
-
* The name is `useQuery`, not `createQuery`, on purpose — the four primitives are
|
|
12
|
-
* one vocabulary across Nuxt, React and Svelte, and renaming them per ecosystem
|
|
13
|
-
* would make the same gesture read as three different things.
|
|
14
|
-
*/
|
|
1
|
+
/** The couple — useQuery (reads) and useCommand (writes), in Svelte. */
|
|
15
2
|
import { writable, get } from 'svelte/store';
|
|
16
3
|
import { asFougereError, callOf, entityKeyOf, fetcher, invocationOf, itemsOf, mountedKeys, onRefetch, pageOf, queryKeyOf, revalidate, sendCall, trackQuery, } from '@fougere/app/client';
|
|
17
4
|
export function useQuery(entity, op, input, opts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFougereData.js","sourceRoot":"","sources":["../src/useFougereData.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"useFougereData.js","sourceRoot":"","sources":["../src/useFougereData.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAiB,MAAM,cAAc,CAAC;AAE5D,OAAO,EACL,cAAc,EACd,MAAM,EACN,WAAW,EACX,OAAO,EACP,YAAY,EACZ,OAAO,EACP,WAAW,EACX,SAAS,EACT,MAAM,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,UAAU,GAGX,MAAM,qBAAqB,CAAC;AAiB7B,MAAM,UAAU,QAAQ,CACtB,MAAmB,EACnB,EAAU,EACV,KAAiB,EACjB,IAA8B;IAE9B,MAA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AK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;gBAC9C,MAAM,OAAO,CAAC;YAChB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fougere/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-alpha.0",
|
|
4
4
|
"description": "Fougere's four primitives as Svelte stores — host-independent.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fougere",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"src"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@fougere/app": "
|
|
34
|
-
"@fougere/core": "0.
|
|
33
|
+
"@fougere/app": "0.7.0-alpha.0",
|
|
34
|
+
"@fougere/core": "0.7.0-alpha.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"svelte": "^5.53.4",
|
|
38
38
|
"vitest": "^4.1.0",
|
|
39
|
-
"@fougere/schema": "0.
|
|
39
|
+
"@fougere/schema": "0.7.0-alpha.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"svelte": "^5.0.0"
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@fougere/svelte` — the four primitives, in Svelte, for any host that renders it.
|
|
3
|
-
*
|
|
4
|
-
* There is no `@fougere/sveltekit` beside it, and that is not an omission: SvelteKit
|
|
5
|
-
* serves Web-standard `Request`/`Response` from `+server.ts`, and it hands every
|
|
6
|
-
* `load` function its own `event`, so there is no ambient-request lookup to package.
|
|
7
|
-
* A SvelteKit app mounts `@fougere/app/web` directly, the way the TanStack and React
|
|
8
|
-
* Router demos do. Next needed 124 lines because `next/headers` exists; SvelteKit
|
|
9
|
-
* needs none because it does not.
|
|
10
|
-
*
|
|
11
|
-
* So: one package per UI framework, and a host package only when the host has
|
|
12
|
-
* something that is genuinely its own.
|
|
13
|
-
*/
|
|
1
|
+
/** `@fougere/svelte` — the four primitives, in Svelte, for any host that renders it. */
|
|
14
2
|
export { useQuery, useCommand, type QueryState, type QueryStore, type CommandStore } from './useFougereData.js';
|
|
15
3
|
export { useFormFor, type FormOptions } from './useFormFor.js';
|
|
16
4
|
export { useCurrentUser, hydrateSession, refreshSession } from './useCurrentUser.js';
|
package/src/useCurrentUser.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The session: resolved server-side, read here as a store. `refresh()` re-reads it
|
|
3
|
-
* after a client-side auth change — no page reload, no hand-rolled /api/me.
|
|
4
|
-
*
|
|
5
|
-
* SvelteKit hands a `load` function's data down through the page, so a layout that
|
|
6
|
-
* already resolved the session can `hydrate()` this store and the page arrives
|
|
7
|
-
* knowing its user. Without it, the store fetches once on first read.
|
|
8
|
-
*/
|
|
1
|
+
/** The session. */
|
|
9
2
|
import { writable, derived, type Readable } from 'svelte/store';
|
|
10
3
|
import type { SessionView } from '@fougere/app/client';
|
|
11
4
|
|
package/src/useFormFor.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The form contract — state, validation, submission, error mapping. Never a widget.
|
|
3
|
-
*
|
|
4
|
-
* `values` is a writable store, so a component binds straight into it with
|
|
5
|
-
* `bind:value={$form.values[field.name]}`. That is the Svelte equivalent of Vue's
|
|
6
|
-
* reactive object and of React's `setValue`: the same contract, three ways of
|
|
7
|
-
* holding a value, none of which is a rule.
|
|
8
|
-
*/
|
|
1
|
+
/** The form contract — state, validation, submission, error mapping. */
|
|
9
2
|
import { writable, derived, get, type Readable, type Writable } from 'svelte/store';
|
|
10
3
|
import { validationErrorsOf } from '@fougere/core/contract';
|
|
11
4
|
import {
|
|
@@ -40,17 +33,17 @@ export function useFormFor<T = Record<string, unknown>>(entity: FormEntity, opti
|
|
|
40
33
|
const errors = writable<Record<string, string>>({});
|
|
41
34
|
const command = useCommand<T>(entity as EntityClass, options.op ?? 'create');
|
|
42
35
|
|
|
43
|
-
/** Local pre-
|
|
44
|
-
function
|
|
36
|
+
/** Local pre-verdict — same rules as the handler, saves a lost round-trip. */
|
|
37
|
+
function validator(): boolean {
|
|
45
38
|
const result = entity.validate(payloadOf(get(values)));
|
|
46
39
|
errors.set(result.success ? {} : errorsByField(result.errors));
|
|
47
40
|
return result.success;
|
|
48
41
|
}
|
|
49
42
|
|
|
50
43
|
async function submit(): Promise<T | null> {
|
|
51
|
-
if (!
|
|
44
|
+
if (!validator()) return null;
|
|
52
45
|
try {
|
|
53
|
-
return await command.execute({ params: options.params,
|
|
46
|
+
return await command.execute({ params: options.params, input: payloadOf(get(values)) });
|
|
54
47
|
} catch (err) {
|
|
55
48
|
const refusals = validationErrorsOf(err);
|
|
56
49
|
if (refusals) {
|
|
@@ -71,7 +64,7 @@ export function useFormFor<T = Record<string, unknown>>(entity: FormEntity, opti
|
|
|
71
64
|
values,
|
|
72
65
|
errors,
|
|
73
66
|
submit,
|
|
74
|
-
|
|
67
|
+
validator,
|
|
75
68
|
valid,
|
|
76
69
|
/** `{ loading, error }` of the underlying command. */
|
|
77
70
|
command,
|
package/src/useFougereData.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The couple — useQuery (reads) and useCommand (writes), in Svelte.
|
|
3
|
-
*
|
|
4
|
-
* Stores, not runes, and that is a packaging decision with a reason: a `.svelte.ts`
|
|
5
|
-
* file needs the Svelte compiler to run over it, so a library shipping runes ships
|
|
6
|
-
* SOURCE and forces every consumer's bundler to compile it. `svelte/store` is plain
|
|
7
|
-
* TypeScript, compiles with `tsc` like every other package here, and a store still
|
|
8
|
-
* auto-subscribes with `$query` inside a component. The consumer's ergonomics are
|
|
9
|
-
* the same; the packaging is honest.
|
|
10
|
-
*
|
|
11
|
-
* The name is `useQuery`, not `createQuery`, on purpose — the four primitives are
|
|
12
|
-
* one vocabulary across Nuxt, React and Svelte, and renaming them per ecosystem
|
|
13
|
-
* would make the same gesture read as three different things.
|
|
14
|
-
*/
|
|
1
|
+
/** The couple — useQuery (reads) and useCommand (writes), in Svelte. */
|
|
15
2
|
import { writable, get, type Readable } from 'svelte/store';
|
|
16
3
|
import type { FougereError } from '@fougere/core/contract';
|
|
17
4
|
import {
|