@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
@@ -1 +1 @@
1
- {"version":3,"file":"shims.d.ts","sourceRoot":"","sources":["../../src/plugins/shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAsB1D;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAsBlD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EA2BhD,CAAC;AA2CF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAoOvD"}
1
+ {"version":3,"file":"shims.d.ts","sourceRoot":"","sources":["../../src/plugins/shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAsB1D;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAsBlD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EA0BhD,CAAC;AA2CF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAoOvD"}
@@ -8,8 +8,14 @@
8
8
  * 1. Direct call: action(input) → Promise<ActionResult>
9
9
  * 2. React useActionState: (prevState, formData) => Promise<ActionResult>
10
10
  *
11
+ * Types live in `action-types.ts`, schema handling in `action-schema.ts`, and
12
+ * the schema's declared shape (list fields, sensitive fields) in
13
+ * `schema-introspection.ts`.
14
+ *
11
15
  * See design/08-forms-and-actions.md §"Middleware and Server Actions"
12
16
  */
17
+ import { type SensitiveFieldsOption } from './sensitive-fields.ts';
18
+ import type { ActionBuilder, ActionMiddleware, ActionServerError } from './action-types.ts';
13
19
  /**
14
20
  * Typed error class for server actions. Carries a string code and optional data.
15
21
  * When thrown from middleware or the action body, the action short-circuits and
@@ -23,164 +29,19 @@ export declare class ActionError<TCode extends string = string> extends Error {
23
29
  readonly data: Record<string, unknown> | undefined;
24
30
  constructor(code: TCode, data?: Record<string, unknown>);
25
31
  }
26
- /**
27
- * Standard Schema v1 interface (subset).
28
- * Zod ≥3.24, Valibot ≥1.0, and ArkType all implement this.
29
- * See https://github.com/standard-schema/standard-schema
30
- *
31
- * We use permissive types here to accept all compliant libraries without
32
- * requiring exact structural matches on issues/path shapes.
33
- */
34
- interface StandardSchemaV1<Output = unknown> {
35
- readonly '~standard': {
36
- readonly validate: (value: unknown) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;
37
- };
38
- }
39
- type StandardSchemaResult<Output> = {
40
- value: Output;
41
- issues?: undefined;
42
- } | {
43
- value?: undefined;
44
- issues: ReadonlyArray<StandardSchemaIssue>;
45
- };
46
- interface StandardSchemaIssue {
47
- message: string;
48
- path?: ReadonlyArray<PropertyKey | {
49
- key: PropertyKey;
50
- }>;
51
- }
52
- /**
53
- * Minimal schema interface — compatible with Zod, Valibot, ArkType, etc.
54
- *
55
- * Accepts either:
56
- * - Standard Schema (preferred): any object with `~standard.validate()`
57
- * - Legacy parse interface: objects with `.parse()` / `.safeParse()`
58
- *
59
- * At runtime, Standard Schema is detected via `~standard` property and
60
- * takes priority over the legacy interface.
61
- */
62
- export type ActionSchema<T = unknown> = StandardSchemaV1<T> | LegacyActionSchema<T>;
63
- /** Legacy schema interface with .parse() / .safeParse(). */
64
- interface LegacyActionSchema<T = unknown> {
65
- 'parse'(data: unknown): T;
66
- 'safeParse'?(data: unknown): {
67
- success: true;
68
- data: T;
69
- } | {
70
- success: false;
71
- error: SchemaError;
72
- };
73
- '~standard'?: never;
74
- }
75
- /** Schema validation error shape (for legacy .safeParse()/.parse() interface). */
76
- export interface SchemaError {
77
- issues?: Array<{
78
- path?: Array<string | number>;
79
- message: string;
80
- }>;
81
- flatten?(): {
82
- fieldErrors: Record<string, string[]>;
83
- };
84
- }
85
- /** Flattened validation errors keyed by field name. */
86
- export type ValidationErrors = Record<string, string[]>;
87
- /** Middleware function: returns context to merge into the action body's ctx. */
88
- export type ActionMiddleware<TCtx = Record<string, unknown>> = () => Promise<TCtx> | TCtx;
89
- /** The result type returned to the client. */
90
- export type ActionResult<TData = unknown> = {
91
- data: TData;
92
- validationErrors?: never;
93
- serverError?: never;
94
- submittedValues?: never;
95
- } | {
96
- data?: never;
97
- validationErrors: ValidationErrors;
98
- serverError?: never;
99
- /** Raw input values on validation failure — for repopulating form fields. */
100
- submittedValues?: Record<string, unknown>;
101
- } | {
102
- data?: never;
103
- validationErrors?: never;
104
- serverError: {
105
- code: string;
106
- data?: Record<string, unknown>;
107
- };
108
- /**
109
- * The submitted form, when the input was FormData — for repopulating
110
- * form fields, which React resets after the action (TIM-1573).
111
- */
112
- submittedValues?: Record<string, unknown>;
113
- };
114
- /** Context passed to the action body. */
115
- export interface ActionContext<TCtx, TInput> {
116
- ctx: TCtx;
117
- input: TInput;
118
- }
119
32
  interface ActionClientConfig<TCtx> {
120
33
  middleware?: ActionMiddleware<TCtx> | ActionMiddleware<Record<string, unknown>>[];
121
34
  /** Max file size in bytes. Files exceeding this are rejected with validation errors. */
122
35
  fileSizeLimit?: number;
123
36
  /**
124
- * Override the sensitive-field deny-list for this action client.
125
- * See `SensitiveFieldsOption` in `./sensitive-fields.ts`. Per-action config
37
+ * Override the sensitive-field name deny-list for this action client.
38
+ * See `SensitiveFieldsOption` in `./sensitive-fields.ts`. Per-client config
126
39
  * takes precedence over the global `forms.stripSensitiveFields` option in
127
- * `timber.config.ts`. See design/08-forms-and-actions.md and TIM-816.
40
+ * `timber.config.ts`. Fields the schema marks `.meta({ sensitive: true })`
41
+ * are stripped whatever this says. See design/08-forms-and-actions.md.
128
42
  */
129
43
  stripSensitiveFields?: SensitiveFieldsOption;
130
44
  }
131
- /** Intermediate builder returned by createActionClient(). */
132
- export interface ActionBuilder<TCtx> {
133
- /** Declare the input schema. Validation errors are returned typed. */
134
- schema<TInput>(schema: ActionSchema<TInput>): ActionBuilderWithSchema<TCtx, TInput>;
135
- /** Define the action body without input validation. */
136
- action<TData>(fn: (ctx: ActionContext<TCtx, undefined>) => Promise<TData>): ActionFn<TData, undefined>;
137
- }
138
- /** Builder after .schema() has been called. */
139
- export interface ActionBuilderWithSchema<TCtx, TInput> {
140
- /** Define the action body with validated input. */
141
- action<TData>(fn: (ctx: ActionContext<TCtx, TInput>) => Promise<TData>): ActionFn<TData, TInput>;
142
- }
143
- /**
144
- * The final action function. Callable three ways:
145
- * - Direct: action(input) → Promise<ActionResult<TData>>
146
- * - React useActionState: action(prevState, payload) → Promise<ActionResult<TData>>,
147
- * where payload is the submitted FormData or the value dispatch was called with
148
- * - React <form action={fn}>: action(formData) → void (return value ignored by React)
149
- *
150
- * The third overload exists purely for type compatibility with React's
151
- * `<form action>` prop, which expects `(formData: FormData) => void`.
152
- * At runtime the function still returns Promise<ActionResult>, but React
153
- * discards it. This lets validated actions be passed directly to forms
154
- * without casts.
155
- */
156
- /**
157
- * Map schema output keys to `string | undefined` for form-facing APIs.
158
- * HTML form values are always strings, and fields can be absent.
159
- * Gives autocomplete for field names without lying about value types.
160
- */
161
- export type InputHint<T> = T extends Record<string, unknown> ? {
162
- [K in keyof T]: string | undefined;
163
- } : T;
164
- /**
165
- * ActionFn — the callable returned by `createActionClient().action()`.
166
- *
167
- * Generic order: `<TData, TInput>` — TData first for backward compatibility.
168
- * Previously ActionFn had a single `<TData>` generic, so existing code like
169
- * `ActionFn<MyResult>` must still work with TData in the first position.
170
- * See TIM-797.
171
- */
172
- export type ActionFn<TData = unknown, TInput = unknown> = {
173
- /** <form action={fn}> compatibility — React discards the return value. */
174
- (formData: FormData): void;
175
- /** Direct call: action(input) — optional when TInput is undefined/unknown (no-schema actions). */
176
- (...args: undefined extends TInput ? [input?: TInput] : [input: TInput]): Promise<ActionResult<TData>>;
177
- /**
178
- * React useActionState: action(prevState, payload). The payload is the
179
- * submitted FormData, or whatever the hook's dispatch was called with.
180
- */
181
- (prevState: ActionResult<TData> | null, payload: TInput | FormData): Promise<ActionResult<TData>>;
182
- };
183
- import { type SensitiveFieldsOption } from './sensitive-fields.ts';
184
45
  /**
185
46
  * Wrap unexpected errors into a safe server error result.
186
47
  * ActionError → typed result. Other errors → INTERNAL_ERROR (no leak).
@@ -189,10 +50,7 @@ import { type SensitiveFieldsOption } from './sensitive-fields.ts';
189
50
  * throws is rejected on the client instead (action-handler.ts).
190
51
  */
191
52
  export declare function handleActionError(error: unknown): {
192
- serverError: {
193
- code: string;
194
- data?: Record<string, unknown>;
195
- };
53
+ serverError: ActionServerError;
196
54
  };
197
55
  /**
198
56
  * Create a typed action client with middleware and schema validation.
@@ -215,24 +73,5 @@ export declare function handleActionError(error: unknown): {
215
73
  * ```
216
74
  */
217
75
  export declare function createActionClient<TCtx = Record<string, never>>(config?: ActionClientConfig<TCtx>): ActionBuilder<TCtx>;
218
- /**
219
- * Convenience wrapper for the common case: validate input, run handler.
220
- * No middleware needed.
221
- *
222
- * @example
223
- * ```ts
224
- * 'use server'
225
- * import { validated } from '@timber-js/app/server'
226
- * import { z } from 'zod'
227
- *
228
- * export const createTodo = validated(
229
- * z.object({ title: z.string().min(1) }),
230
- * async (input) => {
231
- * await db.todos.create(input)
232
- * }
233
- * )
234
- * ```
235
- */
236
- export declare function validated<TInput, TData>(schema: ActionSchema<TInput>, handler: (input: TInput) => Promise<TData>): ActionFn<TData, TInput>;
237
76
  export {};
238
77
  //# sourceMappingURL=action-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"action-client.d.ts","sourceRoot":"","sources":["../../src/server/action-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH;;;;;;;GAOG;AACH,qBAAa,WAAW,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,KAAK;IACnE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAEnD,YAAY,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAKtD;CACF;AAID;;;;;;;GAOG;AACH,UAAU,gBAAgB,CAAC,MAAM,GAAG,OAAO;IACzC,QAAQ,CAAC,WAAW,EAAE;QACpB,QAAQ,CAAC,QAAQ,EAAE,CACjB,KAAK,EAAE,OAAO,KACX,oBAAoB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;KAC3E,CAAC;CACH;AAED,KAAK,oBAAoB,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AAQ,KAAK;IACnE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAEnD,YAAY,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAKtD;CACF;AAID,UAAU,kBAAkB,CAAC,IAAI;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IAClF,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,qBAAqB,CAAC;CAC9C;AA0BD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,WAAW,EAAE,iBAAiB,CAAA;CAAE,CAqBpF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC7D,MAAM,GAAE,kBAAkB,CAAC,IAAI,CAAM,GACpC,aAAa,CAAC,IAAI,CAAC,CA2HrB"}
@@ -16,7 +16,6 @@
16
16
  import { type CsrfConfig } from './csrf.ts';
17
17
  import { type RevalidateRenderer } from './actions.ts';
18
18
  import { type BodyLimitsConfig } from './body-limits.ts';
19
- import { type SensitiveFieldsOption } from './sensitive-fields.ts';
20
19
  import type { ReactFormState } from 'react-dom/client';
21
20
  /** Configuration for the action handler. */
22
21
  export interface ActionDispatchConfig {
@@ -26,12 +25,6 @@ export interface ActionDispatchConfig {
26
25
  revalidateRenderer?: RevalidateRenderer;
27
26
  /** Body size limits (from timber.config.ts). */
28
27
  bodyLimits?: BodyLimitsConfig;
29
- /**
30
- * Override the sensitive-field deny-list for the no-JS form POST path.
31
- * Defaults to the global `forms.stripSensitiveFields` from `timber.config.ts`.
32
- * See `SensitiveFieldsOption` in `./sensitive-fields.ts` and TIM-816.
33
- */
34
- sensitiveFields?: SensitiveFieldsOption;
35
28
  }
36
29
  /**
37
30
  * Check if a request is a server action invocation.
@@ -1 +1 @@
1
- {"version":3,"file":"action-handler.d.ts","sourceRoot":"","sources":["../../src/server/action-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAUH,OAAO,EAAuC,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAEjF,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAKtE,OAAO,EAAwC,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAKL,KAAK,qBAAqB,EAC3B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAYvD,4CAA4C;AAC5C,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,kEAAkE;IAClE,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,gDAAgD;IAChD,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B;;;;OAIG;IACH,eAAe,CAAC,EAAE,qBAAqB,CAAC;CACzC;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAarD;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,MAAM,iBAAiB,GACzB;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,cAAc,GAAG,SAAS,CAAC;IACtC,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK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CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,CAAC;AAON;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,QAAQ,GAAG,iBAAiB,GAAG,IAAI,CAAC,CAoF9C"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Action input schemas — the Standard Schema protocol (and the legacy
3
+ * `.parse()` interface) as `createActionClient().schema()` accepts them, the
4
+ * input/output types they carry, and running one against an action's input.
5
+ *
6
+ * See design/08-forms-and-actions.md §"Validation Pattern"
7
+ */
8
+ import type { ValidationErrors } from './action-types.ts';
9
+ /**
10
+ * Standard Schema v1 interface (subset).
11
+ * Zod ≥3.24, Valibot ≥1.0, and ArkType all implement this.
12
+ * See https://github.com/standard-schema/standard-schema
13
+ *
14
+ * `types` is the protocol's type-only carrier: a schema's input type (what a
15
+ * caller passes, before coercion) and output type (what validation produces).
16
+ * We use permissive types for issues and paths to accept all compliant
17
+ * libraries without requiring exact structural matches on their shapes.
18
+ */
19
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
20
+ readonly '~standard': {
21
+ readonly validate: (value: unknown) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;
22
+ readonly types?: {
23
+ readonly input: Input;
24
+ readonly output: Output;
25
+ } | undefined;
26
+ };
27
+ }
28
+ type StandardSchemaResult<Output> = {
29
+ value: Output;
30
+ issues?: undefined;
31
+ } | {
32
+ value?: undefined;
33
+ issues: ReadonlyArray<StandardSchemaIssue>;
34
+ };
35
+ interface StandardSchemaIssue {
36
+ message: string;
37
+ path?: ReadonlyArray<PropertyKey | {
38
+ key: PropertyKey;
39
+ }>;
40
+ }
41
+ /** Check if a schema implements the Standard Schema protocol. */
42
+ export declare function isStandardSchema(schema: unknown): schema is StandardSchemaV1;
43
+ /**
44
+ * Minimal schema interface — compatible with Zod, Valibot, ArkType, etc.
45
+ *
46
+ * Accepts either:
47
+ * - Standard Schema (preferred): any object with `~standard.validate()`
48
+ * - Legacy parse interface: objects with `.parse()` / `.safeParse()`
49
+ *
50
+ * At runtime, Standard Schema is detected via `~standard` property and
51
+ * takes priority over the legacy interface.
52
+ */
53
+ export type ActionSchema<T = unknown> = StandardSchemaV1<unknown, T> | LegacyActionSchema<T>;
54
+ /** Legacy schema interface with .parse() / .safeParse(). */
55
+ interface LegacyActionSchema<T = unknown> {
56
+ 'parse'(data: unknown): T;
57
+ 'safeParse'?(data: unknown): {
58
+ success: true;
59
+ data: T;
60
+ } | {
61
+ success: false;
62
+ error: SchemaError;
63
+ };
64
+ '~standard'?: never;
65
+ }
66
+ /** Schema validation error shape (for legacy .safeParse()/.parse() interface). */
67
+ export interface SchemaError {
68
+ issues?: Array<{
69
+ path?: Array<string | number>;
70
+ message: string;
71
+ }>;
72
+ flatten?(): {
73
+ fieldErrors: Record<string, string[]>;
74
+ };
75
+ }
76
+ /**
77
+ * What a validated action's body receives: the schema's output, after
78
+ * coercion and defaults.
79
+ */
80
+ export type SchemaOutput<S> = S extends {
81
+ readonly '~standard': infer Std;
82
+ } ? DeclaredType<Std, 'output', ValidatedValue<S>> : S extends LegacyActionSchema<infer T> ? T : never;
83
+ /**
84
+ * The value a Standard Schema's `validate` produces on success, for a schema
85
+ * that declares no `types`. Only the success branch has a required `value`.
86
+ */
87
+ type ValidatedValue<S> = S extends {
88
+ readonly '~standard': {
89
+ readonly validate: (value: unknown) => infer R;
90
+ };
91
+ } ? SuccessValue<Awaited<R>> : never;
92
+ /** Distributes over the result union, keeping the members with a value. */
93
+ type SuccessValue<R> = R extends {
94
+ value: infer O;
95
+ } ? O : never;
96
+ /**
97
+ * What a caller passes a validated action: the schema's input, before
98
+ * coercion. A schema that declares no `types` (a hand-written Standard
99
+ * Schema, a legacy `.parse()` schema) has one type for both.
100
+ */
101
+ export type SchemaInput<S> = S extends {
102
+ readonly '~standard': infer Std;
103
+ } ? DeclaredType<Std, 'input', SchemaOutput<S>> : SchemaOutput<S>;
104
+ /**
105
+ * `Std.types[K]` when the schema declares `types` (Zod, Valibot, ArkType do),
106
+ * else `Fallback`. Read by key, because `types` is optional in the protocol.
107
+ */
108
+ type DeclaredType<Std, K extends 'input' | 'output', Fallback> = 'types' extends keyof Std ? NonNullable<Std['types' & keyof Std]> extends {
109
+ readonly [P in K]: infer T;
110
+ } ? T : Fallback : Fallback;
111
+ /** The outcome of running an action's schema over its input. */
112
+ export type SchemaValidation<T> = {
113
+ ok: true;
114
+ value: T;
115
+ } | {
116
+ ok: false;
117
+ validationErrors: ValidationErrors;
118
+ };
119
+ /**
120
+ * Validate `input` with `schema`, through Standard Schema when the schema
121
+ * implements it, and through `.safeParse()` / `.parse()` otherwise. Only
122
+ * synchronous Standard Schema validation is supported.
123
+ */
124
+ export declare function validateWithSchema<T>(schema: ActionSchema<T>, input: unknown): SchemaValidation<T>;
125
+ export {};
126
+ //# sourceMappingURL=action-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-schema.d.ts","sourceRoot":"","sources":["../../src/server/action-schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAI1D;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAC/D,QAAQ,CAAC,WAAW,EAAE;QACpB,QAAQ,CAAC,QAAQ,EAAE,CACjB,KAAK,EAAE,OAAO,KACX,oBAAoB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1E,QAAQ,CAAC,KAAK,CAAC,EAAE;YAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC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,EAAE,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;CAAE,GAC1E,CAAC,GACD,QAAQ,GACV,QAAQ,CAAC;AAIb,gEAAgE;AAChE,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAC1B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACtB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,gBAAgB,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAEtD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,KAAK,EAAE,OAAO,GACb,gBAAgB,CAAC,CAAC,CAAC,CAyBrB"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Types for `createActionClient` actions: what a caller passes, what the
3
+ * action body receives, and the result the client reads.
4
+ *
5
+ * A validated action has two input types. Callers pass the schema's input
6
+ * (`SchemaInput`), the values before coercion: a form's strings, or whatever
7
+ * a direct call hands it. The body receives the schema's output
8
+ * (`SchemaOutput`), after coercion and defaults.
9
+ *
10
+ * See design/08-forms-and-actions.md §"Middleware and Server Actions"
11
+ */
12
+ import type { ActionSchema, SchemaInput, SchemaOutput } from './action-schema.ts';
13
+ /** Recursion budget for `FieldPath`: six levels, then a path ends in `string`. */
14
+ type Depth = [never, 0, 1, 2, 3, 4, 5, 6];
15
+ /**
16
+ * The dot paths of the fields in `T`, as a form names them and a validation
17
+ * error is keyed: `title`, `user.email`, `sets.${number}.name`.
18
+ *
19
+ * An input of unknown shape has `string` paths, so nothing is rejected: an
20
+ * action with no schema (`undefined` input, whose only validation errors are
21
+ * `fileSizeLimit`'s) and a schema that declares no types.
22
+ */
23
+ export type FieldPath<T> = unknown extends T ? string : [T] extends [undefined] ? string : PathsOf<NonNullable<T>, 5>;
24
+ type PathsOf<T, D extends number> = [D] extends [never] ? string : unknown extends T ? never : T extends File | Blob | Date ? never : T extends readonly (infer Item)[] ? `${number}` | `${number}.${PathsOf<NonNullable<Item>, Depth[D]>}` : T extends object ? {
25
+ [K in keyof T & string]-?: K | `${K}.${PathsOf<NonNullable<T[K]>, Depth[D]>}`;
26
+ }[keyof T & string] : never;
27
+ /**
28
+ * Validation errors keyed by field path. `_root` holds errors that belong to
29
+ * the whole input rather than one field.
30
+ */
31
+ export type ValidationErrors<TPath extends string = string> = {
32
+ [K in TPath | '_root']?: string[];
33
+ };
34
+ /** Middleware function: returns context to merge into the action body's ctx. */
35
+ export type ActionMiddleware<TCtx = Record<string, unknown>> = () => Promise<TCtx> | TCtx;
36
+ /** A typed failure: an `ActionError`'s code and data, or `INTERNAL_ERROR`. */
37
+ export interface ActionServerError {
38
+ code: string;
39
+ data?: Record<string, unknown>;
40
+ }
41
+ /**
42
+ * The result returned to the client. `TInput` is the schema's input type,
43
+ * which keys `validationErrors` by the input's field paths.
44
+ */
45
+ export type ActionResult<TData = unknown, TInput = unknown> = {
46
+ data: TData;
47
+ validationErrors?: never;
48
+ serverError?: never;
49
+ submittedValues?: never;
50
+ } | {
51
+ data?: never;
52
+ validationErrors: ValidationErrors<FieldPath<TInput>>;
53
+ serverError?: never;
54
+ /** Raw input values on validation failure — for repopulating form fields. */
55
+ submittedValues?: Record<string, unknown>;
56
+ } | {
57
+ data?: never;
58
+ validationErrors?: never;
59
+ serverError: ActionServerError;
60
+ /**
61
+ * The submitted form, when the input was FormData — for repopulating
62
+ * form fields, which React resets after the action (TIM-1573).
63
+ */
64
+ submittedValues?: Record<string, unknown>;
65
+ };
66
+ /** Context passed to the action body. */
67
+ export interface ActionContext<TCtx, TInput> {
68
+ ctx: TCtx;
69
+ input: TInput;
70
+ }
71
+ /** Intermediate builder returned by createActionClient(). */
72
+ export interface ActionBuilder<TCtx> {
73
+ /** Declare the input schema. Validation errors are returned typed. */
74
+ schema<S extends ActionSchema>(schema: S): ActionBuilderWithSchema<TCtx, SchemaInput<S>, SchemaOutput<S>>;
75
+ /** Define the action body without input validation. */
76
+ action<TData>(fn: (ctx: ActionContext<TCtx, undefined>) => Promise<TData>): ActionFn<TData, undefined>;
77
+ }
78
+ /** Builder after .schema() has been called. */
79
+ export interface ActionBuilderWithSchema<TCtx, TInput, TOutput = TInput> {
80
+ /** Define the action body. It receives the schema's output. */
81
+ action<TData>(fn: (ctx: ActionContext<TCtx, TOutput>) => Promise<TData>): ActionFn<TData, TInput>;
82
+ }
83
+ /**
84
+ * The final action function. Callable three ways:
85
+ * - Direct: action(input) → Promise<ActionResult<TData>>
86
+ * - React useActionState: action(prevState, payload) → Promise<ActionResult<TData>>,
87
+ * where payload is the submitted FormData or the value dispatch was called with
88
+ * - React <form action={fn}>: action(formData) → void (return value ignored by React)
89
+ *
90
+ * `TInput` is what callers pass: the schema's input type. The third overload
91
+ * exists purely for type compatibility with React's `<form action>` prop,
92
+ * which expects `(formData: FormData) => void`. At runtime the function still
93
+ * returns Promise<ActionResult>, but React discards it. This lets validated
94
+ * actions be passed directly to forms without casts.
95
+ */
96
+ export type ActionFn<TData = unknown, TInput = unknown> = {
97
+ /** <form action={fn}> compatibility — React discards the return value. */
98
+ (formData: FormData): void;
99
+ /** Direct call: action(input) — optional when TInput is undefined/unknown (no-schema actions). */
100
+ (...args: undefined extends TInput ? [input?: TInput] : [input: TInput]): Promise<ActionResult<TData, TInput>>;
101
+ /**
102
+ * React useActionState: action(prevState, payload). The payload is the
103
+ * submitted FormData, or whatever the hook's dispatch was called with.
104
+ */
105
+ (prevState: ActionResult<TData, TInput> | null, payload: TInput | FormData): Promise<ActionResult<TData, TInput>>;
106
+ };
107
+ export {};
108
+ //# sourceMappingURL=action-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-types.d.ts","sourceRoot":"","sources":["../../src/server/action-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIlF,kFAAkF;AAClF,KAAK,KAA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AC,CAAC,CAAC;IAClE,uDAAuD;IACvD,MAAM,CAAC,KAAK,EACV,EAAE,EAAE,CAAC,GAAG,EAAE,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,GAC1D,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;CAC/B;AAED,+CAA+C;AAC/C,MAAM,WAAW,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM;IACrE,+DAA+D;IAC/D,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;CACnG;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,IAAI;IACxD,0EAA0E;IAC1E,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3B,kGAAkG;IAClG,CACE,GAAG,IAAI,EAAE,SAAS,SAAS,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,GACrE,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IACxC;;;OAGG;IACH,CACE,SAAS,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,EAC7C,OAAO,EAAE,MAAM,GAAG,QAAQ,GACzB,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;CACzC,CAAC"}
@@ -24,6 +24,13 @@
24
24
  * - **Empty Files → undefined**: File inputs with no selection become `undefined`
25
25
  * - **Strips `$ACTION_*` fields**: React's internal hidden fields are excluded
26
26
  * - **Drops `__proto__` paths and names deeper than 32 segments**
27
+ *
28
+ * A field's shape follows its count: a name sent once is a scalar, several
29
+ * times an array, never at all absent. A `createActionClient` action with a
30
+ * schema then gives every field the schema declares as a list one shape
31
+ * (`normalizeListFields` in `schema-introspection.ts`). A raw call, and a raw
32
+ * `'use server'` action that calls this itself, keep the count-dependent
33
+ * shape.
27
34
  */
28
35
  export declare function parseFormData(formData: FormData): Record<string, unknown>;
29
36
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"form-data.d.ts","sourceRoot":"","sources":["../../src/server/form-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA2BzE;AAgID;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,MAAM;IACjB;;;;;;;;;;;OAWG;IACH,IAAI,QAAQ,OAAO,GAAG,MAAM,GAAG,SAAS;IAMxC;;;;;;OAMG;IACH,MAAM,QAAQ,OAAO,GAAG,MAAM,GAAG,SAAS;IAS1C;;;;;OAKG;IACH,QAAQ,QAAQ,OAAO,GAAG,OAAO;IAOjC;;;;;OAKG;IACH,IAAI,QAAQ,OAAO,GAAG,OAAO;IAU7B;;;;;;;;OAQG;IACH,IAAI,QAAQ,OAAO,GAAG,IAAI,GAAG,SAAS;IAgCtC;;;;;;;;;;;;;;OAcG;IACH,IAAI,WAAW;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,SAAS;CAmB9F,CAAC"}
1
+ {"version":3,"file":"form-data.d.ts","sourceRoot":"","sources":["../../src/server/form-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA2BzE;AAgID;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,MAAM;IACjB;;;;;;;;;;;OAWG;IACH,IAAI,QAAQ,OAAO,GAAG,MAAM,GAAG,SAAS;IAMxC;;;;;;OAMG;IACH,MAAM,QAAQ,OAAO,GAAG,MAAM,GAAG,SAAS;IAS1C;;;;;OAKG;IACH,QAAQ,QAAQ,OAAO,GAAG,OAAO;IAOjC;;;;;OAKG;IACH,IAAI,QAAQ,OAAO,GAAG,OAAO;IAU7B;;;;;;;;OAQG;IACH,IAAI,QAAQ,OAAO,GAAG,IAAI,GAAG,SAAS;IAgCtC;;;;;;;;;;;;;;OAcG;IACH,IAAI,WAAW;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,SAAS;CAmB9F,CAAC"}
@@ -7,8 +7,9 @@ export type { ReadonlyHeaders } from './request-context.ts';
7
7
  export { getCookieJar } from './cookie-context.ts';
8
8
  export type { RequestCookies, CookieOptions, SetCookieOptions } from './cookie-context.ts';
9
9
  export { deny, redirect, redirectExternal, RedirectType, waitUntil, type DenyOptions, type RedirectOptions, } from './primitives.ts';
10
- export { createActionClient, ActionError, validated } from './action-client.ts';
11
- export type { ActionResult, ActionFn, ActionBuilder, ActionBuilderWithSchema, ActionContext, ActionMiddleware, ActionSchema, ValidationErrors, } from './action-client.ts';
10
+ export { createActionClient, ActionError } from './action-client.ts';
11
+ export type { ActionResult, ActionFn, ActionBuilder, ActionBuilderWithSchema, ActionContext, ActionMiddleware, ActionServerError, FieldPath, ValidationErrors, } from './action-types.ts';
12
+ export type { ActionSchema, SchemaInput, SchemaOutput } from './action-schema.ts';
12
13
  export { coerce, parseFormData } from './form-data.ts';
13
14
  export { revalidatePath, revalidateTag } from './actions.ts';
14
15
  export { getTraceId, getSpanId, withS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