@fougere/svelte 0.16.2-alpha.0 → 0.16.3-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/useFormFor.d.ts +4 -4
- package/dist/useFormFor.d.ts.map +1 -1
- package/dist/useFormFor.js +6 -11
- package/dist/useFormFor.js.map +1 -1
- package/dist/useFougereData/CommandStore.d.ts +2 -1
- package/dist/useFougereData/CommandStore.d.ts.map +1 -1
- package/dist/useFougereData/CommandStore.js +1 -1
- package/dist/useFougereData/CommandStore.js.map +1 -1
- package/package.json +4 -4
- package/src/useFormFor.ts +8 -12
- package/src/useFougereData/CommandStore.ts +5 -3
- package/template/scaffold.json +2 -1
package/dist/useFormFor.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The form contract — state, validation, submission, error mapping. */
|
|
2
2
|
import { type Readable, type Writable } from 'svelte/store';
|
|
3
|
-
import { type FormEntity, type FormField, type FormRow } from '@fougere/app/client';
|
|
3
|
+
import { type FormEntity, type FormField, type FormFieldName, type FormRow } from '@fougere/app/client';
|
|
4
4
|
export interface FormOptions {
|
|
5
5
|
/** Command the submit rides. Default: 'create'. */
|
|
6
6
|
op?: string;
|
|
@@ -10,12 +10,12 @@ export interface FormOptions {
|
|
|
10
10
|
params?: Record<string, string>;
|
|
11
11
|
}
|
|
12
12
|
export declare function useFormFor<E extends FormEntity>(entity: E, options?: FormOptions): {
|
|
13
|
-
fields: FormField[];
|
|
13
|
+
fields: FormField<FormFieldName<E>>[];
|
|
14
14
|
/** The same fields, keyed by name — spread `fieldsByName.email.attrs` on an input
|
|
15
15
|
* and the page states no rule of its own. */
|
|
16
|
-
fieldsByName: Record<
|
|
16
|
+
fieldsByName: Partial<Record<FormFieldName<E>, FormField<FormFieldName<E>>>>;
|
|
17
17
|
values: Writable<Partial<FormRow<E>>>;
|
|
18
|
-
errors: Writable<Partial<Record<
|
|
18
|
+
errors: Writable<Partial<Record<FormFieldName<E>, string>>>;
|
|
19
19
|
submit: () => Promise<FormRow<E> | null>;
|
|
20
20
|
validator: () => boolean;
|
|
21
21
|
valid: Readable<boolean>;
|
package/dist/useFormFor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,EAEf,KAAK,SAAS,EACd,KAAK,OAAO,EAEb,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,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,GAAE,WAAgB;;
|
|
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,EAEf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,OAAO,EAEb,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,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,GAAE,WAAgB;;IAoCjF;kDAC8C;kBACkC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;kBAhBvH,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;qBAP7B,OAAO;;IA6B3B,sDAAsD;;EAGzD"}
|
package/dist/useFormFor.js
CHANGED
|
@@ -22,17 +22,12 @@ export function useFormFor(entity, options = {}) {
|
|
|
22
22
|
async function submit() {
|
|
23
23
|
if (!validator())
|
|
24
24
|
return null;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
errors.set(errorsByField(refusals));
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
25
|
+
const answer = await command.execute({ params: options.params, input: payloadOf(entity, get(values)) });
|
|
26
|
+
const failure = get(command).error;
|
|
27
|
+
const refusals = failure && validationErrorsOf(failure);
|
|
28
|
+
if (refusals)
|
|
29
|
+
errors.set(errorsByField(refusals));
|
|
30
|
+
return answer;
|
|
36
31
|
}
|
|
37
32
|
const valid = derived(errors, ($errors) => Object.keys($errors).length === 0);
|
|
38
33
|
return {
|
package/dist/useFormFor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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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|
5
5
|
loading: boolean;
|
|
6
6
|
error: FougereError<Refused> | null;
|
|
7
7
|
}> {
|
|
8
|
-
|
|
8
|
+
/** The answer, or `null` when the call was refused — the refusal is in `error`, and nothing is thrown. */
|
|
9
|
+
execute(input?: CallInput): Promise<T | null>;
|
|
9
10
|
}
|
|
10
11
|
export declare function useCommand<Handler, Address extends string, Op extends keyof Handler & string>(facade: FacadeName<Handler, Address>, op: Op): CommandStore<Answer<Handler, Op>, Refused<Address, Op>>;
|
|
11
12
|
/** Read a store's current value without subscribing — used by `useFormFor`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandStore.d.ts","sourceRoot":"","sources":["../../src/useFougereData/CommandStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,GAAG,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAA+F,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE9L,MAAM,WAAW,YAAY,CAAC,CAAC,EAAE,OAAO,SAAS,SAAS,GAAG,SAAS,CACpE,SAAQ,QAAQ,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;CAAE,CAAC;IAC3E,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"CommandStore.d.ts","sourceRoot":"","sources":["../../src/useFougereData/CommandStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,GAAG,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAA+F,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE9L,MAAM,WAAW,YAAY,CAAC,CAAC,EAAE,OAAO,SAAS,SAAS,GAAG,SAAS,CACpE,SAAQ,QAAQ,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;CAAE,CAAC;IAC3E,0GAA0G;IAC1G,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;CAC/C;AAED,wBAAgB,UAAU,CACxB,OAAO,EACP,OAAO,SAAS,MAAM,EACtB,EAAE,SAAS,MAAM,OAAO,GAAG,MAAM,EACjC,MAAM,EAAE,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAuBvG;AAED,+EAA+E;AAC/E,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandStore.js","sourceRoot":"","sources":["../../src/useFougereData/CommandStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAiB,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAA8D,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"CommandStore.js","sourceRoot":"","sources":["../../src/useFougereData/CommandStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAiB,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,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ANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fougere/svelte",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3-alpha.0",
|
|
4
4
|
"description": "Fougere's four primitives as Svelte stores — host-independent.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fougere",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
"template"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@fougere/app": "0.16.
|
|
35
|
-
"@fougere/core": "0.16.
|
|
34
|
+
"@fougere/app": "0.16.3-alpha.0",
|
|
35
|
+
"@fougere/core": "0.16.3-alpha.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"svelte": "^5.53.4",
|
|
39
39
|
"vitest": "^4.1.0",
|
|
40
|
-
"@fougere/schema": "0.16.
|
|
40
|
+
"@fougere/schema": "0.16.3-alpha.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"svelte": "^5.0.0"
|
package/src/useFormFor.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type FormEntity,
|
|
11
11
|
type FormErrors,
|
|
12
12
|
type FormField,
|
|
13
|
+
type FormFieldName,
|
|
13
14
|
type FormRow,
|
|
14
15
|
type FormValues,
|
|
15
16
|
} from '@fougere/app/client';
|
|
@@ -26,7 +27,7 @@ export interface FormOptions {
|
|
|
26
27
|
|
|
27
28
|
export function useFormFor<E extends FormEntity>(entity: E, options: FormOptions = {}) {
|
|
28
29
|
const entityKey = entityKeyOf(entity);
|
|
29
|
-
const fields
|
|
30
|
+
const fields = formFieldsOf(entity, entityKey);
|
|
30
31
|
|
|
31
32
|
// `initial` wins over the declared default: editing a row shows the row. On a
|
|
32
33
|
// create form there is none, so the field opens on what is about to be written.
|
|
@@ -48,17 +49,12 @@ export function useFormFor<E extends FormEntity>(entity: E, options: FormOptions
|
|
|
48
49
|
|
|
49
50
|
async function submit(): Promise<FormRow<E> | null> {
|
|
50
51
|
if (!validator()) return null;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (refusals) {
|
|
56
|
-
errors.set(errorsByField<E>(refusals));
|
|
52
|
+
const answer = await command.execute({ params: options.params, input: payloadOf(entity, get(values)) });
|
|
53
|
+
const failure = get(command).error;
|
|
54
|
+
const refusals = failure && validationErrorsOf(failure);
|
|
55
|
+
if (refusals) errors.set(errorsByField<E>(refusals));
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
throw err;
|
|
61
|
-
}
|
|
57
|
+
return answer as FormRow<E> | null;
|
|
62
58
|
}
|
|
63
59
|
|
|
64
60
|
const valid: Readable<boolean> = derived(errors, ($errors) => Object.keys($errors).length === 0);
|
|
@@ -67,7 +63,7 @@ export function useFormFor<E extends FormEntity>(entity: E, options: FormOptions
|
|
|
67
63
|
fields,
|
|
68
64
|
/** The same fields, keyed by name — spread `fieldsByName.email.attrs` on an input
|
|
69
65
|
* and the page states no rule of its own. */
|
|
70
|
-
fieldsByName: Object.fromEntries(fields.map((field) => [field.name, field])) as Record<
|
|
66
|
+
fieldsByName: Object.fromEntries(fields.map((field) => [field.name, field])) as Partial<Record<FormFieldName<E>, FormField<FormFieldName<E>>>>,
|
|
71
67
|
values,
|
|
72
68
|
errors,
|
|
73
69
|
submit,
|
|
@@ -4,7 +4,8 @@ import { asFougereError, callOf, addressOf, fetcher, invocationOf, mountedKeys,
|
|
|
4
4
|
|
|
5
5
|
export interface CommandStore<T, Refused extends ErrorCode = ErrorCode>
|
|
6
6
|
extends Readable<{ loading: boolean; error: FougereError<Refused> | null }> {
|
|
7
|
-
|
|
7
|
+
/** The answer, or `null` when the call was refused — the refusal is in `error`, and nothing is thrown. */
|
|
8
|
+
execute(input?: CallInput): Promise<T | null>;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export function useCommand<
|
|
@@ -17,7 +18,7 @@ export function useCommand<
|
|
|
17
18
|
|
|
18
19
|
return {
|
|
19
20
|
subscribe: store.subscribe,
|
|
20
|
-
async execute(input?: CallInput): Promise<Answer<Handler, Op
|
|
21
|
+
async execute(input?: CallInput): Promise<Answer<Handler, Op> | null> {
|
|
21
22
|
store.set({ loading: true, error: null });
|
|
22
23
|
try {
|
|
23
24
|
const result = (await sendCall(fetcher, callOf(facade, op), invocationOf(input))) as Answer<Handler, Op>;
|
|
@@ -29,7 +30,8 @@ export function useCommand<
|
|
|
29
30
|
} catch (err) {
|
|
30
31
|
const failure = asFougereError(err, entityKey, op);
|
|
31
32
|
store.set({ loading: false, error: failure });
|
|
32
|
-
|
|
33
|
+
|
|
34
|
+
return null;
|
|
33
35
|
}
|
|
34
36
|
},
|
|
35
37
|
};
|