@fougere/nuxt 0.16.0-alpha.0 → 0.16.2-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/runtime/composables/useFormFor.d.ts +5 -5
- package/dist/runtime/composables/useFormFor.d.ts.map +1 -1
- package/dist/runtime/composables/useFormFor.js +3 -3
- package/dist/runtime/composables/useFormFor.js.map +1 -1
- package/package.json +5 -5
- package/src/runtime/composables/useFormFor.ts +9 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FormEntity, type FormField } from '@fougere/app/client';
|
|
1
|
+
import { type FormEntity, type FormField, type FormErrors, type FormRow, type FormValues } from '@fougere/app/client';
|
|
2
2
|
export interface FormOptions {
|
|
3
3
|
/** Command the submit rides. Default: 'create'. */
|
|
4
4
|
op?: string;
|
|
@@ -7,16 +7,16 @@ export interface FormOptions {
|
|
|
7
7
|
/** Call params designating the target (edit mode: { id }). */
|
|
8
8
|
params?: Record<string, string>;
|
|
9
9
|
}
|
|
10
|
-
export declare function useFormFor<
|
|
10
|
+
export declare function useFormFor<E extends FormEntity>(entity: E, options?: FormOptions): {
|
|
11
11
|
fields: FormField[];
|
|
12
12
|
/**
|
|
13
13
|
* The same fields, keyed by name — a form that lays its inputs out by hand binds one at a time
|
|
14
14
|
* (`v-bind="fieldsByName.email.attrs"`), and still states no rule of its own.
|
|
15
15
|
*/
|
|
16
16
|
fieldsByName: Record<string, FormField>;
|
|
17
|
-
values:
|
|
18
|
-
errors:
|
|
19
|
-
submit: () => Promise<
|
|
17
|
+
values: FormValues<E>;
|
|
18
|
+
errors: FormErrors<E>;
|
|
19
|
+
submit: () => Promise<FormRow<E> | null>;
|
|
20
20
|
loading: import("vue").Ref<boolean, boolean>;
|
|
21
21
|
/** Non-validation failure of the last submit (unreachable host, conflict…). */
|
|
22
22
|
error: import("vue").Ref<import("@fougere/core/contract").FougereError<import("@fougere/core/contract").ErrorCode> | null, import("@fougere/core/contract").FougereError<import("@fougere/core/contract").ErrorCode> | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormFor.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useFormFor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoD,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"useFormFor.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useFormFor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoD,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAExK,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;;IAgDjF;;;OAGG;kBACiE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;YAC3E,UAAU,CAAC,CAAC,CAAC;YACb,UAAU,CAAC,CAAC,CAAC;kBAvBR,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;;IA0BjD,+EAA+E;;;EAIlF"}
|
|
@@ -13,7 +13,7 @@ export function useFormFor(entity, options = {}) {
|
|
|
13
13
|
const values = reactive(Object.fromEntries(fields.map((f) => [f.name, options.initial?.[f.name] ?? f.default])));
|
|
14
14
|
const errors = reactive({});
|
|
15
15
|
// A form is designated by its ENTITY — it is a set of fields — so the facade it submits to is
|
|
16
|
-
// an address with no handler type behind it, and
|
|
16
|
+
// an address with no handler type behind it, and what it answers is the entity's row.
|
|
17
17
|
const command = useCommand(facadeOf(entity), options.op ?? 'create');
|
|
18
18
|
function clearErrors() {
|
|
19
19
|
for (const key of Object.keys(errors))
|
|
@@ -51,8 +51,8 @@ export function useFormFor(entity, options = {}) {
|
|
|
51
51
|
* (`v-bind="fieldsByName.email.attrs"`), and still states no rule of its own.
|
|
52
52
|
*/
|
|
53
53
|
fieldsByName: Object.fromEntries(fields.map((f) => [f.name, f])),
|
|
54
|
-
values,
|
|
55
|
-
errors,
|
|
54
|
+
values: values,
|
|
55
|
+
errors: errors,
|
|
56
56
|
submit,
|
|
57
57
|
loading: command.loading,
|
|
58
58
|
/** Non-validation failure of the last submit (unreachable host, conflict…). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormFor.js","sourceRoot":"","sources":["../../../src/runtime/composables/useFormFor.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"useFormFor.js","sourceRoot":"","sources":["../../../src/runtime/composables/useFormFor.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAmF,MAAM,qBAAqB,CAAC;AAWxK,MAAM,UAAU,UAAU,CAAuB,MAAS,EAAE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AC9B,IAAI,CAAC;YACH,OAAO,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAe,CAAC;QAC7G,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,QAAQ,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;YACzC,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAI,QAAQ,CAAC,CAAC,CAAC;gBAElD,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN;;;WAGG;QACH,YAAY,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAA8B;QAC7F,MAAM,EAAE,MAAuB;QAC/B,MAAM,EAAE,MAAuB;QAC/B,MAAM;QACN,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,+EAA+E;QAC/E,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;KACxD,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fougere/nuxt",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2-alpha.0",
|
|
4
4
|
"description": "The Nuxt module: Fougere's client primitives and server surface.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fougere",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"template"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@fougere/app": "0.16.
|
|
36
|
-
"@fougere/core": "0.16.
|
|
37
|
-
"@fougere/defaults": "0.16.
|
|
35
|
+
"@fougere/app": "0.16.2-alpha.0",
|
|
36
|
+
"@fougere/core": "0.16.2-alpha.0",
|
|
37
|
+
"@fougere/defaults": "0.16.2-alpha.0",
|
|
38
38
|
"@nuxt/kit": "^4.5.1",
|
|
39
39
|
"jiti": "^2.6.1",
|
|
40
|
-
"@fougere/compiler": "0.16.
|
|
40
|
+
"@fougere/compiler": "0.16.2-alpha.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@nuxt/schema": "^4.5.1",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { reactive, computed } from 'vue';
|
|
3
3
|
import { lowerFirst, validationErrorsOf } from '@fougere/core/contract';
|
|
4
4
|
import { useCommand } from './useFougereData.js';
|
|
5
|
-
import { facadeOf, formFieldsOf, payloadOf, errorsByField, type FormEntity, type FormField } from '@fougere/app/client';
|
|
5
|
+
import { facadeOf, formFieldsOf, payloadOf, errorsByField, type FormEntity, type FormField, type FormErrors, type FormRow, type FormValues } from '@fougere/app/client';
|
|
6
6
|
|
|
7
7
|
export interface FormOptions {
|
|
8
8
|
/** Command the submit rides. Default: 'create'. */
|
|
@@ -13,7 +13,7 @@ export interface FormOptions {
|
|
|
13
13
|
params?: Record<string, string>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function useFormFor<
|
|
16
|
+
export function useFormFor<E extends FormEntity>(entity: E, options: FormOptions = {}) {
|
|
17
17
|
const entityKey = lowerFirst(entity.name);
|
|
18
18
|
const fields: FormField[] = formFieldsOf(entity, entityKey);
|
|
19
19
|
|
|
@@ -26,7 +26,7 @@ export function useFormFor<T = Record<string, unknown>>(entity: FormEntity, opti
|
|
|
26
26
|
);
|
|
27
27
|
const errors = reactive<Record<string, string>>({});
|
|
28
28
|
// A form is designated by its ENTITY — it is a set of fields — so the facade it submits to is
|
|
29
|
-
// an address with no handler type behind it, and
|
|
29
|
+
// an address with no handler type behind it, and what it answers is the entity's row.
|
|
30
30
|
const command = useCommand(facadeOf(entity), options.op ?? 'create');
|
|
31
31
|
|
|
32
32
|
function clearErrors() {
|
|
@@ -38,20 +38,20 @@ export function useFormFor<T = Record<string, unknown>>(entity: FormEntity, opti
|
|
|
38
38
|
clearErrors();
|
|
39
39
|
const result = entity.validate(payloadOf(entity, values));
|
|
40
40
|
if (result.success) return true;
|
|
41
|
-
Object.assign(errors, errorsByField(result.errors));
|
|
41
|
+
Object.assign(errors, errorsByField<E>(result.errors));
|
|
42
42
|
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/** Validate locally, then send through the command. */
|
|
47
|
-
async function submit(): Promise<
|
|
47
|
+
async function submit(): Promise<FormRow<E> | null> {
|
|
48
48
|
if (!validator()) return null;
|
|
49
49
|
try {
|
|
50
|
-
return (await command.execute({ params: options.params, input: payloadOf(entity, values) })) as
|
|
50
|
+
return (await command.execute({ params: options.params, input: payloadOf(entity, values) })) as FormRow<E>;
|
|
51
51
|
} catch (err) {
|
|
52
52
|
const refusals = validationErrorsOf(err);
|
|
53
53
|
if (refusals) {
|
|
54
|
-
Object.assign(errors, errorsByField(refusals));
|
|
54
|
+
Object.assign(errors, errorsByField<E>(refusals));
|
|
55
55
|
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
@@ -66,8 +66,8 @@ export function useFormFor<T = Record<string, unknown>>(entity: FormEntity, opti
|
|
|
66
66
|
* (`v-bind="fieldsByName.email.attrs"`), and still states no rule of its own.
|
|
67
67
|
*/
|
|
68
68
|
fieldsByName: Object.fromEntries(fields.map((f) => [f.name, f])) as Record<string, FormField>,
|
|
69
|
-
values
|
|
70
|
-
errors
|
|
69
|
+
values: values as FormValues<E>,
|
|
70
|
+
errors: errors as FormErrors<E>,
|
|
71
71
|
submit,
|
|
72
72
|
loading: command.loading,
|
|
73
73
|
/** Non-validation failure of the last submit (unreachable host, conflict…). */
|