@analogjs/router 2.8.0-beta.1 → 2.8.0-beta.10

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.
@@ -64,14 +64,14 @@ interface ServerRouteHandler<TQuery = unknown, TBody = unknown, TResult = unknow
64
64
  type InferRouteQuery<T> = T extends ServerRouteHandler<infer Q, any, any> ? Q : never;
65
65
  type InferRouteBody<T> = T extends ServerRouteHandler<any, infer B, any> ? B : never;
66
66
  type InferRouteResult<T> = T extends ServerRouteHandler<any, any, infer R> ? Exclude<R, Response> : never;
67
- type OptionalSchema$1 = StandardSchemaV1 | undefined;
68
- type InferSchema$1<TSchema extends OptionalSchema$1, TFallback = unknown> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
69
- type ResolveDataSchema<TInput extends OptionalSchema$1, TQuery extends OptionalSchema$1, TBody extends OptionalSchema$1> = TInput extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TInput> : TQuery extends StandardSchemaV1 ? TBody extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TQuery> | StandardSchemaV1.InferOutput<TBody> : StandardSchemaV1.InferOutput<TQuery> : TBody extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TBody> : unknown;
67
+ type OptionalSchema$3 = StandardSchemaV1 | undefined;
68
+ type InferSchema$3<TSchema extends OptionalSchema$3, TFallback = unknown> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
69
+ type ResolveDataSchema$1<TInput extends OptionalSchema$3, TQuery extends OptionalSchema$3, TBody extends OptionalSchema$3> = TInput extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TInput> : TQuery extends StandardSchemaV1 ? TBody extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TQuery> | StandardSchemaV1.InferOutput<TBody> : StandardSchemaV1.InferOutput<TQuery> : TBody extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TBody> : unknown;
70
70
  interface DefineServerRouteContext<TInput extends StandardSchemaV1 | undefined = undefined, TQuery extends StandardSchemaV1 | undefined = undefined, TBody extends StandardSchemaV1 | undefined = undefined, TParams extends StandardSchemaV1 | undefined = undefined> {
71
- data: ResolveDataSchema<TInput, TQuery, TBody>;
72
- query: InferSchema$1<TQuery, undefined>;
73
- body: InferSchema$1<TBody, undefined>;
74
- params: InferSchema$1<TParams, H3Event['context']['params']>;
71
+ data: ResolveDataSchema$1<TInput, TQuery, TBody>;
72
+ query: InferSchema$3<TQuery, undefined>;
73
+ body: InferSchema$3<TBody, undefined>;
74
+ params: InferSchema$3<TParams, H3Event['context']['params']>;
75
75
  event: H3Event;
76
76
  }
77
77
  interface DefineServerRouteOptions<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TQuery extends StandardSchemaV1 | undefined = undefined, TBody extends StandardSchemaV1 | undefined = undefined, TParams extends StandardSchemaV1 | undefined = undefined, TResult extends DefineServerRouteResult = DefineServerRouteResult> {
@@ -116,19 +116,19 @@ interface DefineServerRouteOptions<TInput extends StandardSchemaV1 | undefined =
116
116
  * });
117
117
  * ```
118
118
  */
119
- declare function defineServerRoute<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TQuery extends StandardSchemaV1 | undefined = undefined, TBody extends StandardSchemaV1 | undefined = undefined, TParams extends StandardSchemaV1 | undefined = undefined, TResult extends DefineServerRouteResult = DefineServerRouteResult>(options: DefineServerRouteOptions<TInput, TOutput, TQuery, TBody, TParams, TResult>): ServerRouteHandler<InferSchema$1<TQuery, undefined>, InferSchema$1<TBody, undefined>, TResult>;
119
+ declare function defineServerRoute<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TQuery extends StandardSchemaV1 | undefined = undefined, TBody extends StandardSchemaV1 | undefined = undefined, TParams extends StandardSchemaV1 | undefined = undefined, TResult extends DefineServerRouteResult = DefineServerRouteResult>(options: DefineServerRouteOptions<TInput, TOutput, TQuery, TBody, TParams, TResult>): ServerRouteHandler<InferSchema$3<TQuery, undefined>, InferSchema$3<TBody, undefined>, TResult>;
120
120
 
121
- type OptionalSchema = StandardSchemaV1 | undefined;
122
- type InferSchema<TSchema extends OptionalSchema, TFallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
123
- interface PageLoadContext<TParamsSchema extends OptionalSchema = undefined, TQuerySchema extends OptionalSchema = undefined> {
124
- params: InferSchema<TParamsSchema, H3EventContext['params']>;
125
- query: InferSchema<TQuerySchema, Record<string, string | string[] | undefined>>;
121
+ type OptionalSchema$2 = StandardSchemaV1 | undefined;
122
+ type InferSchema$2<TSchema extends OptionalSchema$2, TFallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
123
+ interface PageLoadContext<TParamsSchema extends OptionalSchema$2 = undefined, TQuerySchema extends OptionalSchema$2 = undefined> {
124
+ params: InferSchema$2<TParamsSchema, H3EventContext['params']>;
125
+ query: InferSchema$2<TQuerySchema, Record<string, string | string[] | undefined>>;
126
126
  req: H3Event['node']['req'];
127
127
  res: H3Event['node']['res'];
128
128
  fetch: $Fetch;
129
129
  event: H3Event;
130
130
  }
131
- interface DefinePageLoadOptions<TParamsSchema extends OptionalSchema = undefined, TQuerySchema extends OptionalSchema = undefined, TResult = unknown> {
131
+ interface DefinePageLoadOptions<TParamsSchema extends OptionalSchema$2 = undefined, TQuerySchema extends OptionalSchema$2 = undefined, TResult = unknown> {
132
132
  params?: TParamsSchema;
133
133
  query?: TQuerySchema;
134
134
  handler: (context: PageLoadContext<TParamsSchema, TQuerySchema>) => Promise<TResult> | TResult;
@@ -161,7 +161,7 @@ interface DefinePageLoadOptions<TParamsSchema extends OptionalSchema = undefined
161
161
  * });
162
162
  * ```
163
163
  */
164
- declare function definePageLoad<TParamsSchema extends OptionalSchema = undefined, TQuerySchema extends OptionalSchema = undefined, TResult = unknown>(options: DefinePageLoadOptions<TParamsSchema, TQuerySchema, TResult>): (ctx: {
164
+ declare function definePageLoad<TParamsSchema extends OptionalSchema$2 = undefined, TQuerySchema extends OptionalSchema$2 = undefined, TResult = unknown>(options: DefinePageLoadOptions<TParamsSchema, TQuerySchema, TResult>): (ctx: {
165
165
  params: H3EventContext['params'];
166
166
  req: H3Event['node']['req'];
167
167
  res: H3Event['node']['res'];
@@ -177,5 +177,103 @@ declare function definePageLoad<TParamsSchema extends OptionalSchema = undefined
177
177
  */
178
178
  declare function validateWithSchema<T extends StandardSchemaV1>(schema: T, data: unknown): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<T>>>;
179
179
 
180
- export { StandardSchemaV1, definePageLoad, defineServerRoute, fail, json, redirect, validateWithSchema };
181
- export type { DefinePageLoadOptions, DefineServerRouteContext, DefineServerRouteOptions, DefineServerRouteResult, InferRouteBody, InferRouteQuery, InferRouteResult, PageLoadContext, PageServerAction, ServerRouteHandler };
180
+ type OptionalSchema$1 = StandardSchemaV1 | undefined;
181
+ type InferSchema$1<TSchema extends OptionalSchema$1, TFallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
182
+ interface DefineActionContext<TSchema extends OptionalSchema$1 = undefined, TParamsSchema extends OptionalSchema$1 = undefined> {
183
+ data: InferSchema$1<TSchema, Record<string, unknown>>;
184
+ params: InferSchema$1<TParamsSchema, H3EventContext['params']>;
185
+ req: PageServerAction['req'];
186
+ res: PageServerAction['res'];
187
+ fetch: PageServerAction['fetch'];
188
+ event: PageServerAction['event'];
189
+ }
190
+ interface DefineActionOptions<TSchema extends OptionalSchema$1 = undefined, TParamsSchema extends OptionalSchema$1 = undefined> {
191
+ schema?: TSchema;
192
+ params?: TParamsSchema;
193
+ handler: (context: DefineActionContext<TSchema, TParamsSchema>) => Promise<Response> | Response;
194
+ }
195
+ /**
196
+ * Creates a server action handler with Standard Schema input validation.
197
+ *
198
+ * Parses the request body (JSON or FormData) and validates it against the
199
+ * provided schema before invoking the handler. On validation failure,
200
+ * returns `fail(422, issues)` with `StandardSchemaV1.Issue[]`.
201
+ * Repeated form fields are preserved as arrays instead of being collapsed
202
+ * to the last value.
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * import { defineAction, json } from '@analogjs/router/server/actions';
207
+ * import * as v from 'valibot';
208
+ *
209
+ * const Schema = v.object({
210
+ * email: v.pipe(v.string(), v.email()),
211
+ * });
212
+ *
213
+ * export const action = defineAction({
214
+ * schema: Schema,
215
+ * handler: async ({ data }) => {
216
+ * // data is typed as { email: string }
217
+ * return json({ ok: true });
218
+ * },
219
+ * });
220
+ * ```
221
+ */
222
+ declare function defineAction<TSchema extends OptionalSchema$1 = undefined, TParamsSchema extends OptionalSchema$1 = undefined>(options: DefineActionOptions<TSchema, TParamsSchema>): (ctx: PageServerAction) => Promise<Response>;
223
+
224
+ type DefineApiRouteResult = Response | unknown;
225
+ type OptionalSchema = StandardSchemaV1 | undefined;
226
+ type InferSchema<TSchema extends OptionalSchema, TFallback = unknown> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
227
+ type ResolveDataSchema<TInput extends OptionalSchema, TQuery extends OptionalSchema, TBody extends OptionalSchema> = TInput extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TInput> : TQuery extends StandardSchemaV1 ? TBody extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TQuery> | StandardSchemaV1.InferOutput<TBody> : StandardSchemaV1.InferOutput<TQuery> : TBody extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TBody> : unknown;
228
+ interface DefineApiRouteContext<TInput extends StandardSchemaV1 | undefined = undefined, TQuery extends StandardSchemaV1 | undefined = undefined, TBody extends StandardSchemaV1 | undefined = undefined, TParams extends StandardSchemaV1 | undefined = undefined> {
229
+ data: ResolveDataSchema<TInput, TQuery, TBody>;
230
+ query: InferSchema<TQuery, undefined>;
231
+ body: InferSchema<TBody, undefined>;
232
+ params: InferSchema<TParams, H3Event['context']['params']>;
233
+ event: H3Event;
234
+ }
235
+ interface DefineApiRouteOptions<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TQuery extends StandardSchemaV1 | undefined = undefined, TBody extends StandardSchemaV1 | undefined = undefined, TParams extends StandardSchemaV1 | undefined = undefined, TResult extends DefineApiRouteResult = DefineApiRouteResult> {
236
+ input?: TInput;
237
+ query?: TQuery;
238
+ body?: TBody;
239
+ params?: TParams;
240
+ output?: TOutput;
241
+ handler: (context: DefineApiRouteContext<TInput, TQuery, TBody, TParams>) => Promise<TResult> | TResult;
242
+ }
243
+ /**
244
+ * Creates an h3-compatible event handler with Standard Schema validation.
245
+ *
246
+ * - `input` schema validates the request body (POST/PUT/PATCH) or query
247
+ * params (GET). Returns 422 with `StandardSchemaV1.Issue[]` on failure.
248
+ * - `output` schema validates the response in development and tests only. Logs a warning on mismatch.
249
+ * - Plain return values are serialized with `json(...)`; raw `Response`
250
+ * objects are returned unchanged.
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * import { defineApiRoute } from '@analogjs/router/server/actions';
255
+ * import * as v from 'valibot';
256
+ *
257
+ * const Input = v.object({
258
+ * name: v.pipe(v.string(), v.minLength(1)),
259
+ * email: v.pipe(v.string(), v.email()),
260
+ * });
261
+ * const Output = v.object({
262
+ * id: v.string(),
263
+ * name: v.string(),
264
+ * });
265
+ *
266
+ * export default defineApiRoute({
267
+ * input: Input,
268
+ * output: Output,
269
+ * handler: async ({ data }) => {
270
+ * const user = await db.users.create(data);
271
+ * return user;
272
+ * },
273
+ * });
274
+ * ```
275
+ */
276
+ declare function defineApiRoute<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TQuery extends StandardSchemaV1 | undefined = undefined, TBody extends StandardSchemaV1 | undefined = undefined, TParams extends StandardSchemaV1 | undefined = undefined, TResult extends DefineApiRouteResult = DefineApiRouteResult>(options: DefineApiRouteOptions<TInput, TOutput, TQuery, TBody, TParams, TResult>): (event: H3Event) => Promise<Response>;
277
+
278
+ export { StandardSchemaV1, defineAction, defineApiRoute, definePageLoad, defineServerRoute, fail, json, redirect, validateWithSchema };
279
+ export type { DefineActionContext, DefineActionOptions, DefineApiRouteContext, DefineApiRouteOptions, DefineApiRouteResult, DefinePageLoadOptions, DefineServerRouteContext, DefineServerRouteOptions, DefineServerRouteResult, InferRouteBody, InferRouteQuery, InferRouteResult, PageLoadContext, PageServerAction, ServerRouteHandler };
@@ -8,6 +8,7 @@ import * as rxjs from 'rxjs';
8
8
  import { Observable } from 'rxjs';
9
9
  import * as _angular_common_http from '@angular/common/http';
10
10
  import { HttpRequest, HttpHandlerFn } from '@angular/common/http';
11
+ import { StandardSchemaV1 as StandardSchemaV1$1 } from '@analogjs/router/server/actions';
11
12
 
12
13
  type RouteOmitted = 'component' | 'loadComponent' | 'loadChildren' | 'path' | 'pathMatch';
13
14
  type RestrictedRoute = Omit<Route, RouteOmitted>;
@@ -170,23 +171,39 @@ declare function requestContextInterceptor(req: HttpRequest<unknown>, next: Http
170
171
 
171
172
  declare function injectRouteEndpointURL(route: ActivatedRouteSnapshot): URL;
172
173
 
174
+ type FormActionState = 'submitting' | 'error' | 'redirect' | 'success' | 'navigate';
173
175
  declare class FormAction {
174
176
  action: i0.InputSignal<string>;
177
+ enhanceForm: i0.InputSignalWithTransform<boolean, unknown>;
175
178
  onSuccess: i0.OutputEmitterRef<unknown>;
176
179
  onError: i0.OutputEmitterRef<unknown>;
177
- state: i0.OutputEmitterRef<"error" | "navigate" | "redirect" | "submitting" | "success">;
180
+ state: i0.OutputEmitterRef<FormActionState>;
181
+ private currentState;
182
+ private injector;
178
183
  private router;
179
184
  private route;
180
185
  private path;
186
+ constructor();
181
187
  submitted($event: any): void;
182
188
  private _handleGet;
183
189
  private _handlePost;
184
190
  private _getPath;
191
+ private _handleEnhancedGet;
192
+ private _handleEnhancedPost;
193
+ private _emitState;
194
+ private _navigateTo;
185
195
  private _isJSON;
186
196
  static ɵfac: i0.ɵɵFactoryDeclaration<FormAction, never>;
187
- static ɵdir: i0.ɵɵDirectiveDeclaration<FormAction, "form[action],form[method]", never, { "action": { "alias": "action"; "required": false; "isSignal": true; }; }, { "onSuccess": "onSuccess"; "onError": "onError"; "state": "state"; }, never, never, true, never>;
197
+ static ɵdir: i0.ɵɵDirectiveDeclaration<FormAction, "form[action],form[method],form[enhanceForm]", never, { "action": { "alias": "action"; "required": false; "isSignal": true; }; "enhanceForm": { "alias": "enhanceForm"; "required": false; "isSignal": true; }; }, { "onSuccess": "onSuccess"; "onError": "onError"; "state": "state"; }, never, never, true, never>;
188
198
  }
189
199
 
200
+ type ValidationFieldErrors = Record<string, string[]>;
201
+ declare function issuePathToFieldName(path: ReadonlyArray<string | number | symbol | {
202
+ key: string | number | symbol;
203
+ }>): string;
204
+ declare function issuesToFieldErrors(issues: ReadonlyArray<StandardSchemaV1$1.Issue>): ValidationFieldErrors;
205
+ declare function issuesToFormErrors(issues: ReadonlyArray<StandardSchemaV1$1.Issue>): string[];
206
+
190
207
  type DebugRoute = {
191
208
  path: string;
192
209
  filename: string;
@@ -540,5 +557,5 @@ declare function injectQuery<P extends AnalogRoutePath>(_from: P, options?: {
540
557
  injector?: Injector;
541
558
  }): Signal<RouteQueryOutput<P>>;
542
559
 
543
- export { FormAction, LinkTo, SERVER_FN_DISPATCHER, ServerFnClient, createRoutes, createServerFnRef, defineRouteMeta, getLoadResolver, injectActivatedRoute, injectDebugRoutes, injectLoad, injectNavigate, injectParams, injectQuery, injectRouteEndpointURL, injectRouter, injectServerFn, injectServerFnMutation, provideFileRouter, provideServerFnClient, requestContextInterceptor, routes, toRoute, withDebugRoutes, withExtraRoutes };
544
- export type { AnalogRoutePath, AnalogRouteTable, Files, LoadResult, MetaTag, PageServerLoad, RouteExport, RouteMeta, RoutePathOptions, ServerFn, ServerFnConfig, ServerFnContext, ServerFnDef, ServerFnDispatcher, ServerFnHandler, ServerFnMethod, ServerFnRefConfig, StandardSchemaV1 };
560
+ export { FormAction, LinkTo, SERVER_FN_DISPATCHER, ServerFnClient, createRoutes, createServerFnRef, defineRouteMeta, getLoadResolver, injectActivatedRoute, injectDebugRoutes, injectLoad, injectNavigate, injectParams, injectQuery, injectRouteEndpointURL, injectRouter, injectServerFn, injectServerFnMutation, issuePathToFieldName, issuesToFieldErrors, issuesToFormErrors, provideFileRouter, provideServerFnClient, requestContextInterceptor, routes, toRoute, withDebugRoutes, withExtraRoutes };
561
+ export type { AnalogRoutePath, AnalogRouteTable, Files, FormActionState, LoadResult, MetaTag, PageServerLoad, RouteExport, RouteMeta, RoutePathOptions, ServerFn, ServerFnConfig, ServerFnContext, ServerFnDef, ServerFnDispatcher, ServerFnHandler, ServerFnMethod, ServerFnRefConfig, StandardSchemaV1, ValidationFieldErrors };