@timber-js/app 0.2.0-alpha.218 → 0.2.0-alpha.219

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 (58) hide show
  1. package/agent-skill.md +5 -5
  2. package/dist/_chunks/{actions-CUh3cClk.js → actions-BwkmAYXq.js} +8 -1
  3. package/dist/_chunks/{actions-CUh3cClk.js.map → actions-BwkmAYXq.js.map} +1 -1
  4. package/dist/client/form.d.ts +34 -37
  5. package/dist/client/form.d.ts.map +1 -1
  6. package/dist/client/index.d.ts +3 -3
  7. package/dist/client/index.d.ts.map +1 -1
  8. package/dist/client/index.js +40 -75
  9. package/dist/client/index.js.map +1 -1
  10. package/dist/client/{use-form-field.d.ts → use-field-state.d.ts} +10 -7
  11. package/dist/client/use-field-state.d.ts.map +1 -0
  12. package/dist/config-types.d.ts +15 -18
  13. package/dist/config-types.d.ts.map +1 -1
  14. package/dist/index.js +0 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/plugins/shims.d.ts.map +1 -1
  17. package/dist/server/action-client.d.ts +11 -172
  18. package/dist/server/action-client.d.ts.map +1 -1
  19. package/dist/server/action-handler.d.ts +0 -7
  20. package/dist/server/action-handler.d.ts.map +1 -1
  21. package/dist/server/action-schema.d.ts +126 -0
  22. package/dist/server/action-schema.d.ts.map +1 -0
  23. package/dist/server/action-types.d.ts +108 -0
  24. package/dist/server/action-types.d.ts.map +1 -0
  25. package/dist/server/form-data.d.ts +7 -0
  26. package/dist/server/form-data.d.ts.map +1 -1
  27. package/dist/server/index.d.ts +3 -2
  28. package/dist/server/index.d.ts.map +1 -1
  29. package/dist/server/index.js +511 -148
  30. package/dist/server/index.js.map +1 -1
  31. package/dist/server/internal.js +1 -1
  32. package/dist/server/rsc-entry/action-dispatcher.d.ts +0 -3
  33. package/dist/server/rsc-entry/action-dispatcher.d.ts.map +1 -1
  34. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  35. package/dist/server/schema-introspection.d.ts +68 -0
  36. package/dist/server/schema-introspection.d.ts.map +1 -0
  37. package/dist/server/sensitive-fields.d.ts +40 -26
  38. package/dist/server/sensitive-fields.d.ts.map +1 -1
  39. package/docs/api/31-api-client.mdx +19 -18
  40. package/docs/api/34-api-config.mdx +1 -1
  41. package/docs/learn/08-forms-and-actions.mdx +57 -23
  42. package/package.json +1 -1
  43. package/src/client/form.tsx +57 -108
  44. package/src/client/index.ts +3 -3
  45. package/src/client/{use-form-field.ts → use-field-state.ts} +20 -8
  46. package/src/config-types.ts +15 -18
  47. package/src/plugins/shims.ts +0 -1
  48. package/src/server/action-client.ts +82 -307
  49. package/src/server/action-handler.ts +1 -42
  50. package/src/server/action-schema.ts +203 -0
  51. package/src/server/action-types.ts +145 -0
  52. package/src/server/form-data.ts +7 -0
  53. package/src/server/index.ts +5 -3
  54. package/src/server/rsc-entry/action-dispatcher.ts +0 -4
  55. package/src/server/rsc-entry/index.ts +1 -2
  56. package/src/server/schema-introspection.ts +393 -0
  57. package/src/server/sensitive-fields.ts +115 -58
  58. package/dist/client/use-form-field.d.ts.map +0 -1
@@ -3,55 +3,52 @@
3
3
  *
4
4
  * Forms use React's own `useActionState`: an action built with
5
5
  * `createActionClient` already has the `(prevState, payload)` signature it
6
- * calls, and the result is typed from it. `parseFormErrors` reads the errors
7
- * out of that result.
6
+ * calls, and the result is typed from it. An imperative call (a delete
7
+ * button) uses the same hook: `startTransition(() => dispatch(input))`.
8
+ * `readFormErrors` reads the errors out of that result.
8
9
  *
9
- * See design/08-forms-and-actions.md §"Client-Side Form Mechanics"
10
+ * See design/08-forms-and-actions.md §"Form Errors via readFormErrors"
10
11
  */
11
- import type { ActionFn, ActionResult, InputHint } from '../server/action-client.ts';
12
- /**
13
- * Hook for calling a server action imperatively (not via a form).
14
- * Returns [execute, isPending] where execute accepts the input directly.
15
- *
16
- * @example
17
- * ```tsx
18
- * const [deleteTodo, isPending] = useFormAction(deleteTodoAction)
19
- * <button onClick={() => deleteTodo({ id: todo.id })} disabled={isPending}>
20
- * Delete
21
- * </button>
22
- * ```
23
- */
24
- export declare function useFormAction<TData = unknown, TInput = unknown>(action: ActionFn<TData, TInput> | ((input: TInput) => Promise<ActionResult<TData>>)): [
25
- (...args: undefined extends TInput ? [input?: InputHint<TInput>] : [input: InputHint<TInput>]) => Promise<ActionResult<TData>>,
26
- boolean
27
- ];
28
- /** What `parseFormErrors` reads out of an action result. */
29
- export interface FormErrorsResult {
30
- /** Per-field validation errors keyed by field name. */
31
- fieldErrors: Record<string, string[]>;
32
- /** Form-level errors (from `_root` key). */
33
- formErrors: string[];
34
- /** Server error if the action threw an ActionError. */
35
- serverError: {
36
- code: string;
37
- data?: Record<string, unknown>;
38
- } | null;
12
+ import type { ActionServerError } from '../server/action-types.ts';
13
+ /** What `readFormErrors` reads out of an action result. */
14
+ export interface FormErrors<TPath extends string = string> {
15
+ /** The first validation error for a field, or null. Paths are dot paths: `sets.0.name`. */
16
+ field(name: TPath): string | null;
17
+ /** Form-level validation errors (the `_root` key). */
18
+ form: readonly string[];
19
+ /** The server error, if the action threw (an `ActionError`, or `INTERNAL_ERROR`). */
20
+ server: ActionServerError | null;
39
21
  /** Whether any errors are present. */
40
22
  hasErrors: boolean;
41
- /** Get the first error message for a field, or null. */
42
- getFieldError: (field: string) => string | null;
43
23
  }
24
+ /** The shape `readFormErrors` reads: any `ActionResult`. */
25
+ interface ResultWithErrors {
26
+ validationErrors?: {
27
+ [path: string]: string[] | undefined;
28
+ };
29
+ serverError?: ActionServerError;
30
+ }
31
+ /**
32
+ * The field paths of a result's validation errors, from its schema's input.
33
+ * Distributes over the result union: only the validation-failure member has
34
+ * a non-`never` `validationErrors`.
35
+ */
36
+ type ErrorPaths<R> = R extends {
37
+ validationErrors?: infer V;
38
+ } ? [NonNullable<V>] extends [never] ? never : Exclude<keyof NonNullable<V>, '_root'> & string : never;
44
39
  /**
45
40
  * Read the errors out of an action result — the state `useActionState`
46
41
  * returns. `_root` validation errors are form-level; every other key is a
47
- * field.
42
+ * field. Field names are typed from the action's schema input, so a
43
+ * misspelled path is a type error.
48
44
  *
49
45
  * @example
50
46
  * ```tsx
51
47
  * const [result, action, isPending] = useActionState(createTodo, null)
52
- * const errors = parseFormErrors(result)
53
- * errors.getFieldError('title') // first message for the field, or null
48
+ * const errors = readFormErrors(result)
49
+ * errors.field('title') // first message for the field, or null
54
50
  * ```
55
51
  */
56
- export declare function parseFormErrors<TData>(result: ActionResult<TData> | null | undefined): FormErrorsResult;
52
+ export declare function readFormErrors<R extends ResultWithErrors>(result: R | null | undefined): FormErrors<ErrorPaths<R>>;
53
+ export {};
57
54
  //# sourceMappingURL=form.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/client/form.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,SAAS,EAEV,MAAM,4BAA4B,CAAC;AAIpC;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,EAC7D,MAAM,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,GAClF;IACD,CACE,GAAG,IAAI,EAAE,SAAS,SAAS,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,KACzF,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO;CACR,CAuBA;AAID,4DAA4D;AAC5D,MAAM,WAAW,gBAAgB;IAC/B,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACtC,4CAA4C;IAC5C,UAAU,EAAE,MAAM,EAAE,CA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AAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC9B,KAAK,GACL,OAAO,CAAC,MAAM,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,MAAM,GACjD,KAAK,CAAC;AAWV;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,gBAAgB,EACvD,MAAM,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,GAC3B,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAkB3B"}
@@ -13,9 +13,9 @@ export type { NavigationTransitionType } from './router-types.ts';
13
13
  export { usePathname } from './use-pathname.ts';
14
14
  export { replaceUrl } from './shallow-url.ts';
15
15
  export { useSelectedLayoutSegment, useSelectedLayoutSegments, } from './use-selected-layout-segment.ts';
16
- export { parseFormErrors, useFormAction } from './form.tsx';
17
- export { useFormField } from './use-form-field.ts';
18
- export type { FormErrorsResult } from './form.tsx';
16
+ export { readFormErrors } from './form.tsx';
17
+ export { useFieldState } from './use-field-state.ts';
18
+ export type { FormErrors } from './form.tsx';
19
19
  export { useSegmentParams } from './use-segment-params.ts';
20
20
  export { useQueryStates } from './use-query-states.ts';
21
21
  export type { ClientCookieOptions, CookieSetter } from './use-cookie.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACnG,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA4CxF,MAAM,WAAW,YAAY;CAG5B;AACD,OAAO,E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MAAM,WAAW,YAAY;CAG5B;AACD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACxE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1E,YAAY,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAK7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAY3D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIvD,YAAY,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
@@ -8,7 +8,7 @@ import { t as getSsrData } from "../_chunks/ssr-data-nA3I70_n.js";
8
8
  import { t as getLinkCodec } from "../_chunks/codec-registry-oOUxugz3.js";
9
9
  import { i as useNavigationContext, n as useSegmentContext } from "../_chunks/segment-context-xtPUGfdq.js";
10
10
  import { n as useQueryStates } from "../_chunks/use-query-states-I3JMng6J.js";
11
- import React, { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, useTransition } from "react";
11
+ import React, { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
12
12
  import { jsx } from "react/jsx-runtime";
13
13
  //#region src/client/use-link-status.ts
14
14
  /**
@@ -574,87 +574,45 @@ function useSelectedLayoutSegments(parallelRouteKey) {
574
574
  }
575
575
  //#endregion
576
576
  //#region src/client/form.tsx
577
- /**
578
- * Client-side form utilities for server actions.
579
- *
580
- * Forms use React's own `useActionState`: an action built with
581
- * `createActionClient` already has the `(prevState, payload)` signature it
582
- * calls, and the result is typed from it. `parseFormErrors` reads the errors
583
- * out of that result.
584
- *
585
- * See design/08-forms-and-actions.md §"Client-Side Form Mechanics"
586
- */
587
- /**
588
- * Hook for calling a server action imperatively (not via a form).
589
- * Returns [execute, isPending] where execute accepts the input directly.
590
- *
591
- * @example
592
- * ```tsx
593
- * const [deleteTodo, isPending] = useFormAction(deleteTodoAction)
594
- * <button onClick={() => deleteTodo({ id: todo.id })} disabled={isPending}>
595
- * Delete
596
- * </button>
597
- * ```
598
- */
599
- function useFormAction(action) {
600
- const [isPending, startTransition] = useTransition();
601
- const execute = (input) => {
602
- return new Promise((resolve, reject) => {
603
- startTransition(async () => {
604
- try {
605
- resolve(await action(input));
606
- } catch (error) {
607
- reject(error);
608
- }
609
- });
610
- });
611
- };
612
- return [execute, isPending];
613
- }
577
+ var EMPTY = Object.freeze({
578
+ field: () => null,
579
+ form: Object.freeze([]),
580
+ server: null,
581
+ hasErrors: false
582
+ });
614
583
  /**
615
584
  * Read the errors out of an action result — the state `useActionState`
616
585
  * returns. `_root` validation errors are form-level; every other key is a
617
- * field.
586
+ * field. Field names are typed from the action's schema input, so a
587
+ * misspelled path is a type error.
618
588
  *
619
589
  * @example
620
590
  * ```tsx
621
591
  * const [result, action, isPending] = useActionState(createTodo, null)
622
- * const errors = parseFormErrors(result)
623
- * errors.getFieldError('title') // first message for the field, or null
592
+ * const errors = readFormErrors(result)
593
+ * errors.field('title') // first message for the field, or null
624
594
  * ```
625
595
  */
626
- function parseFormErrors(result) {
627
- const empty = {
628
- fieldErrors: {},
629
- formErrors: [],
630
- serverError: null,
631
- hasErrors: false,
632
- getFieldError: () => null
633
- };
634
- if (!result) return empty;
635
- const validationErrors = result.validationErrors;
636
- const serverError = result.serverError;
637
- if (!validationErrors && !serverError) return empty;
638
- const fieldErrors = {};
639
- const formErrors = [];
640
- if (validationErrors) for (const [key, messages] of Object.entries(validationErrors)) if (key === "_root") formErrors.push(...messages);
641
- else fieldErrors[key] = messages;
642
- const hasErrors = Object.keys(fieldErrors).length > 0 || formErrors.length > 0 || serverError != null;
596
+ function readFormErrors(result) {
597
+ if (!result) return EMPTY;
598
+ const validationErrors = result.validationErrors ?? {};
599
+ const server = result.serverError ?? null;
600
+ const form = validationErrors._root ?? [];
601
+ const hasErrors = server !== null || Object.values(validationErrors).some((messages) => messages?.length);
602
+ if (!hasErrors) return EMPTY;
643
603
  return {
644
- fieldErrors,
645
- formErrors,
646
- serverError: serverError ?? null,
647
- hasErrors,
648
- getFieldError(field) {
649
- const errs = fieldErrors[field];
650
- return errs && errs.length > 0 ? errs[0] : null;
651
- }
604
+ field(name) {
605
+ return validationErrors[name]?.[0] ?? null;
606
+ },
607
+ form,
608
+ server,
609
+ hasErrors
652
610
  };
653
611
  }
654
612
  //#endregion
655
- //#region src/client/use-form-field.ts
613
+ //#region src/client/use-field-state.ts
656
614
  /**
657
- * useFormField — state for a form field that needs JavaScript (a combobox, a
615
+ * useFieldState — state for a form field that needs JavaScript (a combobox, a
658
616
  * chip list, a row list), made to behave like a native uncontrolled input.
659
617
  *
660
618
  * React resets a form after its action settles, so a native field with a
@@ -670,8 +628,11 @@ function parseFormErrors(result) {
670
628
  * State for a field that follows its form's reset.
671
629
  *
672
630
  * Returns `[value, setValue, ref]`. Attach `ref` to any element inside the
673
- * `<form>`, and render the value into the form data yourself (usually a
674
- * hidden input). `value` is `defaultValue` until `setValue` is called, and is
631
+ * `<form>`, or to the `<form>` itself (the hook subscribes to
632
+ * `closest('form')`, which includes the element), and render the value into
633
+ * the form data yourself (usually hidden inputs). With the ref on the form,
634
+ * the hook can live above it and hold the whole draft as one object, for a
635
+ * live preview beside the form. `value` is `defaultValue` until `setValue` is called, and is
675
636
  * `defaultValue` again after the form resets, unless the form cancels its
676
637
  * `reset` event. An edit dispatches a bubbling `change` event from the `ref`
677
638
  * element after it commits, so a native `change` listener on the form sees it
@@ -682,14 +643,14 @@ function parseFormErrors(result) {
682
643
  * @example
683
644
  * ```tsx
684
645
  * // draft: the form's defaults, read from result?.submittedValues ?? pageData
685
- * const [tags, setTags, ref] = useFormField(draft.tags);
646
+ * const [tags, setTags, ref] = useFieldState(draft.tags);
686
647
  * <div ref={ref}>
687
- * <input type="hidden" name="tags" value={tags.join(',')} />
648
+ * {tags.map((tag) => <input key={tag} type="hidden" name="tags" value={tag} />)}
688
649
  * <TagPicker value={tags} onChange={setTags} />
689
650
  * </div>
690
651
  * ```
691
652
  */
692
- function useFormField(defaultValue) {
653
+ function useFieldState(defaultValue) {
693
654
  const [edit, setEdit] = useState(null);
694
655
  const value = edit ? edit.value : defaultValue;
695
656
  const defaultRef = useRef(defaultValue);
@@ -719,8 +680,12 @@ function useFormField(defaultValue) {
719
680
  if (!form) return;
720
681
  const onReset = (event) => {
721
682
  pendingResets.current.push(event);
722
- queueMicrotask(() => {
683
+ const apply = () => {
723
684
  if (takeResets()) setEdit(null);
685
+ };
686
+ queueMicrotask(() => {
687
+ if (event.eventPhase === Event.NONE) apply();
688
+ else setTimeout(apply, 0);
724
689
  });
725
690
  };
726
691
  form.addEventListener("reset", onReset);
@@ -829,6 +794,6 @@ function useSegmentParams(segmentPath) {
829
794
  return resolveSegmentParams(paramsContext.params, paramsContext.slotParams, segmentPath);
830
795
  }
831
796
  //#endregion
832
- export { Link, LinkStatusContext, buildLinkProps, interpolateParams, mergePreservedSearchParams, parseFormErrors, replaceUrl, resolveHref, useFormAction, useFormField, useLinkStatus, usePathname, usePendingNavigation, useQueryStates, useRouter, useSegmentParams, useSelectedLayoutSegment, useSelectedLayoutSegments, validateNavigationHref as validateLinkHref };
797
+ export { Link, LinkStatusContext, buildLinkProps, interpolateParams, mergePreservedSearchParams, readFormErrors, replaceUrl, resolveHref, useFieldState, useLinkStatus, usePathname, usePendingNavigation, useQueryStates, useRouter, useSegmentParams, useSelectedLayoutSegment, useSelectedLayoutSegments, validateNavigationHref as validateLinkHref };
833
798
 
834
799
  //# sourceMappingURL=index.js.map