@analogjs/router 2.7.5 → 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.
@@ -12,5 +12,268 @@ declare function fail<T = object>(status: number, errors: T): Response;
12
12
  declare function json<T = object>(data: T, config?: ResponseInit): Response;
13
13
  declare function redirect(url: string, config?: number | ResponseInit): Response;
14
14
 
15
- export { fail, json, redirect };
16
- export type { PageServerAction };
15
+ /**
16
+ * The Standard Schema interface, inlined from the spec at
17
+ * https://standardschema.dev so no runtime dependency is required.
18
+ */
19
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
20
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
21
+ }
22
+ declare namespace StandardSchemaV1 {
23
+ interface Props<Input = unknown, Output = Input> {
24
+ readonly version: 1;
25
+ readonly vendor: string;
26
+ readonly validate: (value: unknown, options?: Options | undefined) => Result<Output> | Promise<Result<Output>>;
27
+ readonly types?: Types<Input, Output> | undefined;
28
+ }
29
+ type Result<Output> = SuccessResult<Output> | FailureResult;
30
+ interface SuccessResult<Output> {
31
+ readonly value: Output;
32
+ readonly issues?: undefined;
33
+ }
34
+ interface FailureResult {
35
+ readonly issues: ReadonlyArray<Issue>;
36
+ }
37
+ interface Issue {
38
+ readonly message: string;
39
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
40
+ }
41
+ interface PathSegment {
42
+ readonly key: PropertyKey;
43
+ }
44
+ interface Options {
45
+ readonly libraryOptions?: Record<string, unknown> | undefined;
46
+ }
47
+ interface Types<Input = unknown, Output = Input> {
48
+ readonly input: Input;
49
+ readonly output: Output;
50
+ }
51
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
52
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
53
+ }
54
+
55
+ type DefineServerRouteResult = Response | unknown;
56
+ interface ServerRouteHandler<TQuery = unknown, TBody = unknown, TResult = unknown> {
57
+ (event: H3Event): Promise<Response>;
58
+ readonly _types: {
59
+ readonly query: TQuery;
60
+ readonly body: TBody;
61
+ readonly result: TResult;
62
+ };
63
+ }
64
+ type InferRouteQuery<T> = T extends ServerRouteHandler<infer Q, any, any> ? Q : never;
65
+ type InferRouteBody<T> = T extends ServerRouteHandler<any, infer B, any> ? B : never;
66
+ type InferRouteResult<T> = T extends ServerRouteHandler<any, any, infer R> ? Exclude<R, Response> : never;
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
+ 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$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
+ event: H3Event;
76
+ }
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> {
78
+ input?: TInput;
79
+ query?: TQuery;
80
+ body?: TBody;
81
+ params?: TParams;
82
+ output?: TOutput;
83
+ handler: (context: DefineServerRouteContext<TInput, TQuery, TBody, TParams>) => Promise<TResult> | TResult;
84
+ }
85
+ /**
86
+ * Creates an h3-compatible event handler with Standard Schema validation.
87
+ *
88
+ * - `input` schema validates the request body (POST/PUT/PATCH) or query
89
+ * params (GET). Returns 422 with `StandardSchemaV1.Issue[]` on failure.
90
+ * - `output` schema validates the response in development only (stripped
91
+ * in production for zero overhead). Logs a warning on mismatch.
92
+ * - Plain return values are serialized with `json(...)`; raw `Response`
93
+ * objects are returned unchanged.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * import { defineServerRoute } from '@analogjs/router/server/actions';
98
+ * import * as v from 'valibot';
99
+ *
100
+ * const Input = v.object({
101
+ * name: v.pipe(v.string(), v.minLength(1)),
102
+ * email: v.pipe(v.string(), v.email()),
103
+ * });
104
+ * const Output = v.object({
105
+ * id: v.string(),
106
+ * name: v.string(),
107
+ * });
108
+ *
109
+ * export default defineServerRoute({
110
+ * input: Input,
111
+ * output: Output,
112
+ * handler: async ({ data }) => {
113
+ * const user = await db.users.create(data);
114
+ * return user;
115
+ * },
116
+ * });
117
+ * ```
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$3<TQuery, undefined>, InferSchema$3<TBody, undefined>, TResult>;
120
+
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
+ req: H3Event['node']['req'];
127
+ res: H3Event['node']['res'];
128
+ fetch: $Fetch;
129
+ event: H3Event;
130
+ }
131
+ interface DefinePageLoadOptions<TParamsSchema extends OptionalSchema$2 = undefined, TQuerySchema extends OptionalSchema$2 = undefined, TResult = unknown> {
132
+ params?: TParamsSchema;
133
+ query?: TQuerySchema;
134
+ handler: (context: PageLoadContext<TParamsSchema, TQuerySchema>) => Promise<TResult> | TResult;
135
+ }
136
+ /**
137
+ * Creates a typed page server load function with optional
138
+ * Standard Schema validation for route params and query.
139
+ *
140
+ * Follows the same validation pattern as `defineServerRoute`:
141
+ * validates before invoking the handler and returns
142
+ * `fail(422, issues)` on validation failure.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * // src/app/pages/users/[id].server.ts
147
+ * import { definePageLoad } from '@analogjs/router/server/actions';
148
+ * import * as v from 'valibot';
149
+ *
150
+ * export const routeParamsSchema = v.object({
151
+ * id: v.pipe(v.string(), v.regex(/^\d+$/)),
152
+ * });
153
+ *
154
+ * export const load = definePageLoad({
155
+ * params: routeParamsSchema,
156
+ * handler: async ({ params, fetch }) => {
157
+ * // params.id is typed as string (validated)
158
+ * const user = await fetch(`/api/users/${params.id}`);
159
+ * return user;
160
+ * },
161
+ * });
162
+ * ```
163
+ */
164
+ declare function definePageLoad<TParamsSchema extends OptionalSchema$2 = undefined, TQuerySchema extends OptionalSchema$2 = undefined, TResult = unknown>(options: DefinePageLoadOptions<TParamsSchema, TQuerySchema, TResult>): (ctx: {
165
+ params: H3EventContext['params'];
166
+ req: H3Event['node']['req'];
167
+ res: H3Event['node']['res'];
168
+ fetch: $Fetch;
169
+ event: H3Event;
170
+ }) => Promise<TResult | Response>;
171
+
172
+ /**
173
+ * Validates unknown input against a Standard Schema.
174
+ *
175
+ * Handles both sync and async `validate` implementations — the Standard
176
+ * Schema spec allows either return shape.
177
+ */
178
+ declare function validateWithSchema<T extends StandardSchemaV1>(schema: T, data: unknown): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<T>>>;
179
+
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 };
@@ -0,0 +1,70 @@
1
+ import { EnvironmentProviders } from '@angular/core';
2
+ import { QueryClient, DehydratedState } from '@tanstack/angular-query-experimental';
3
+ import { H3EventContext, H3Event } from 'h3';
4
+ import { $Fetch } from 'nitropack';
5
+ import { StandardSchemaV1, PageLoadContext } from '@analogjs/router/server/actions';
6
+ export { ANALOG_QUERIES_KEY } from '@analogjs/router/tanstack-query';
7
+
8
+ declare function provideServerAnalogQuery(): EnvironmentProviders;
9
+
10
+ type OptionalSchema = StandardSchemaV1 | undefined;
11
+ interface PageLoadQueriesResult<TData> {
12
+ __analogQueries: DehydratedState;
13
+ data: TData;
14
+ }
15
+ interface DefinePageLoadQueriesOptions<TParamsSchema extends OptionalSchema, TQuerySchema extends OptionalSchema, TData> {
16
+ params?: TParamsSchema;
17
+ query?: TQuerySchema;
18
+ /**
19
+ * Optional QueryClient factory. Defaults to `new QueryClient()`.
20
+ * Override to set `defaultOptions` (e.g. `queries: { staleTime: Infinity }`).
21
+ */
22
+ client?: () => QueryClient;
23
+ /**
24
+ * Handler receives the standard PageLoadContext plus a per-request
25
+ * QueryClient. Use `client.prefetchQuery` / `ensureQueryData` /
26
+ * `prefetchInfiniteQuery` to warm the cache; the dehydrated client
27
+ * is returned as `__analogQueries` on the load result. Anything you
28
+ * return from the handler becomes `data` on the same result.
29
+ */
30
+ handler: (ctx: PageLoadContext<TParamsSchema, TQuerySchema> & {
31
+ client: QueryClient;
32
+ }) => Promise<TData> | TData;
33
+ }
34
+ /**
35
+ * Page load helper that prefetches TanStack Query queries inside the
36
+ * `.server.ts` handler and ships the dehydrated cache alongside any
37
+ * additional data. The router-side hydrator in `provideAnalogQuery()`
38
+ * merges the dehydrated payload into the active `QueryClient` on
39
+ * `ResolveEnd`, so components reading the same query options see a
40
+ * warm cache on first render.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * // src/app/pages/posts.server.ts
45
+ * import { definePageLoadQueries } from '@analogjs/router/tanstack-query/server';
46
+ * import { queryOptions } from '@tanstack/angular-query-experimental';
47
+ *
48
+ * export const postsQuery = queryOptions({
49
+ * queryKey: ['posts'],
50
+ * queryFn: async ({ signal }) =>
51
+ * fetch('https://api.example.com/posts', { signal }).then((r) => r.json()),
52
+ * });
53
+ *
54
+ * export const load = definePageLoadQueries({
55
+ * handler: async ({ client }) => {
56
+ * await client.prefetchQuery(postsQuery);
57
+ * },
58
+ * });
59
+ * ```
60
+ */
61
+ declare function definePageLoadQueries<TParamsSchema extends OptionalSchema = undefined, TQuerySchema extends OptionalSchema = undefined, TData = void>(options: DefinePageLoadQueriesOptions<TParamsSchema, TQuerySchema, TData>): (ctx: {
62
+ params: H3EventContext['params'];
63
+ req: H3Event['node']['req'];
64
+ res: H3Event['node']['res'];
65
+ fetch: $Fetch;
66
+ event: H3Event;
67
+ }) => Promise<PageLoadQueriesResult<TData> | Response>;
68
+
69
+ export { definePageLoadQueries, provideServerAnalogQuery };
70
+ export type { DefinePageLoadQueriesOptions, PageLoadQueriesResult };
@@ -0,0 +1,33 @@
1
+ import { StateKey, EnvironmentProviders } from '@angular/core';
2
+ import { DehydratedState, DefaultError, InfiniteData, QueryKey, CreateInfiniteQueryOptions, CreateMutationOptions, CreateQueryOptions } from '@tanstack/angular-query-experimental';
3
+ import { HttpClient } from '@angular/common/http';
4
+ import { ServerRouteHandler, InferRouteResult, InferRouteQuery, InferRouteBody } from '@analogjs/router/server/actions';
5
+
6
+ /**
7
+ * Route-data key under `ActivatedRoute.data['load']` that holds the
8
+ * `DehydratedState` produced by `definePageLoadQueries`. The Router-
9
+ * events hydrator in `provideAnalogQuery()` looks for this key on
10
+ * `ResolveEnd` and merges the dehydrated payload into the active
11
+ * `QueryClient`, so component-issued queries hit a warm cache on
12
+ * first render.
13
+ */
14
+ declare const ANALOG_QUERIES_KEY: '__analogQueries';
15
+
16
+ declare const ANALOG_QUERY_STATE_KEY: StateKey<DehydratedState>;
17
+ declare function provideAnalogQuery(): EnvironmentProviders;
18
+
19
+ declare function serverQueryOptions<TRoute extends ServerRouteHandler<any, any, any>, TError = DefaultError, TData = InferRouteResult<TRoute>, TQueryKey extends QueryKey = QueryKey>(http: HttpClient, url: string, options: {
20
+ queryKey: TQueryKey;
21
+ query?: InferRouteQuery<TRoute>;
22
+ } & Omit<CreateQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey>, 'queryKey' | 'queryFn'>): CreateQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey>;
23
+ declare function serverMutationOptions<TRoute extends ServerRouteHandler<any, any, any>, TError = DefaultError, TOnMutateResult = unknown>(http: HttpClient, url: string, options?: Omit<CreateMutationOptions<InferRouteResult<TRoute>, TError, InferRouteBody<TRoute>, TOnMutateResult>, 'mutationFn'>): CreateMutationOptions<InferRouteResult<TRoute>, TError, InferRouteBody<TRoute>, TOnMutateResult>;
24
+ declare function serverInfiniteQueryOptions<TRoute extends ServerRouteHandler<any, any, any>, TError = DefaultError, TData = InfiniteData<InferRouteResult<TRoute>>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(http: HttpClient, url: string, options: {
25
+ queryKey: TQueryKey;
26
+ query: (context: {
27
+ pageParam: TPageParam;
28
+ }) => InferRouteQuery<TRoute>;
29
+ initialPageParam: TPageParam;
30
+ getNextPageParam: (lastPage: InferRouteResult<TRoute>, allPages: InferRouteResult<TRoute>[]) => TPageParam | undefined | null;
31
+ } & Omit<CreateInfiniteQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey, TPageParam>, 'queryKey' | 'queryFn' | 'initialPageParam' | 'getNextPageParam'>): CreateInfiniteQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey, TPageParam>;
32
+
33
+ export { ANALOG_QUERIES_KEY, ANALOG_QUERY_STATE_KEY, provideAnalogQuery, serverInfiniteQueryOptions, serverMutationOptions, serverQueryOptions };
@@ -1,13 +1,14 @@
1
- import * as _angular_core from '@angular/core';
2
- import { Type, EnvironmentProviders, Injector, ResourceRef, InjectionToken } from '@angular/core';
1
+ import * as i0 from '@angular/core';
2
+ import { Type, EnvironmentProviders, Injector, ResourceRef, InjectionToken, OnChanges, InputSignal, Signal } from '@angular/core';
3
3
  import * as _angular_router from '@angular/router';
4
- import { Route, ActivatedRoute, Router, CanActivateFn, DeprecatedGuard, CanActivateChildFn, CanDeactivateFn, CanMatchFn, ResolveFn, RouterFeatures, Routes, ActivatedRouteSnapshot } from '@angular/router';
4
+ import { Route, ActivatedRoute, Router, CanActivateFn, DeprecatedGuard, CanActivateChildFn, CanDeactivateFn, CanMatchFn, ResolveFn, RouterFeatures, Routes, ActivatedRouteSnapshot, NavigationBehaviorOptions } from '@angular/router';
5
5
  import { H3EventContext, H3Event } from 'h3';
6
6
  import { $Fetch } from 'nitropack';
7
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
- action: _angular_core.InputSignal<string>;
175
- onSuccess: _angular_core.OutputEmitterRef<unknown>;
176
- onError: _angular_core.OutputEmitterRef<unknown>;
177
- state: _angular_core.OutputEmitterRef<"error" | "navigate" | "redirect" | "submitting" | "success">;
176
+ action: i0.InputSignal<string>;
177
+ enhanceForm: i0.InputSignalWithTransform<boolean, unknown>;
178
+ onSuccess: i0.OutputEmitterRef<unknown>;
179
+ onError: i0.OutputEmitterRef<unknown>;
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
- static ɵfac: _angular_core.ɵɵFactoryDeclaration<FormAction, never>;
187
- static ɵdir: _angular_core.ɵɵDirectiveDeclaration<FormAction, "form[action],form[method]", never, { "action": { "alias": "action"; "required": false; "isSignal": true; }; }, { "onSuccess": "onSuccess"; "onError": "onError"; "state": "state"; }, never, never, true, never>;
196
+ static ɵfac: i0.ɵɵFactoryDeclaration<FormAction, 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;
@@ -206,8 +223,8 @@ declare class DebugRoutesComponent {
206
223
  debugRoutes: (_angular_router.Route & DebugRoute)[];
207
224
  ngOnInit(): void;
208
225
  traverseRoutes(routes: DebugRoute[], parent?: string): void;
209
- static ɵfac: _angular_core.ɵɵFactoryDeclaration<DebugRoutesComponent, never>;
210
- static ɵcmp: _angular_core.ɵɵComponentDeclaration<DebugRoutesComponent, "analogjs-debug-routes-page", never, {}, {}, never, never, true, never>;
226
+ static ɵfac: i0.ɵɵFactoryDeclaration<DebugRoutesComponent, never>;
227
+ static ɵcmp: i0.ɵɵComponentDeclaration<DebugRoutesComponent, "analogjs-debug-routes-page", never, {}, {}, never, never, true, never>;
211
228
  }
212
229
 
213
230
  declare namespace __debug_page {
@@ -224,7 +241,7 @@ declare namespace __debug_page {
224
241
  declare function withDebugRoutes(): {
225
242
  ɵkind: number;
226
243
  ɵproviders: {
227
- provide: _angular_core.InjectionToken<_angular_router.Route[][]>;
244
+ provide: i0.InjectionToken<_angular_router.Route[][]>;
228
245
  useValue: {
229
246
  path: string;
230
247
  loadComponent: () => Promise<typeof __debug_page>;
@@ -305,11 +322,11 @@ declare class ServerFnClient {
305
322
  get isServer(): boolean;
306
323
  call<In, Out>(fn: ServerFn<In, Out>, input: In): Promise<Out>;
307
324
  /** Key a read's value for TransferState hydration (fn id + input). */
308
- stateKey<Out>(fn: ServerFn<unknown, Out>, input: unknown): _angular_core.StateKey<Out>;
325
+ stateKey<Out>(fn: ServerFn<unknown, Out>, input: unknown): i0.StateKey<Out>;
309
326
  readSeed<Out>(fn: ServerFn<unknown, Out>, input: unknown): Out | undefined;
310
327
  writeSeed<Out>(fn: ServerFn<unknown, Out>, input: unknown, value: Out): void;
311
- static ɵfac: _angular_core.ɵɵFactoryDeclaration<ServerFnClient, never>;
312
- static ɵprov: _angular_core.ɵɵInjectableDeclaration<ServerFnClient>;
328
+ static ɵfac: i0.ɵɵFactoryDeclaration<ServerFnClient, never>;
329
+ static ɵprov: i0.ɵɵInjectableDeclaration<ServerFnClient>;
313
330
  }
314
331
  /** No-op provider hook; ServerFnClient is `providedIn: 'root'`. */
315
332
  declare function provideServerFnClient(): readonly [];
@@ -377,5 +394,168 @@ declare function createServerFnRef<In, Out>(config: ServerFnRefConfig): ServerFn
377
394
  type ServerFnDispatcher = <In, Out>(fn: ServerFn<In, Out>, input: In, injector: Injector) => Promise<Out>;
378
395
  declare const SERVER_FN_DISPATCHER: InjectionToken<ServerFnDispatcher>;
379
396
 
380
- export { FormAction, SERVER_FN_DISPATCHER, ServerFnClient, createRoutes, createServerFnRef, defineRouteMeta, getLoadResolver, injectActivatedRoute, injectDebugRoutes, injectLoad, injectRouteEndpointURL, injectRouter, injectServerFn, injectServerFnMutation, provideFileRouter, provideServerFnClient, requestContextInterceptor, routes, withDebugRoutes, withExtraRoutes };
381
- export type { Files, LoadResult, MetaTag, PageServerLoad, RouteExport, RouteMeta, ServerFn, ServerFnConfig, ServerFnContext, ServerFnDef, ServerFnDispatcher, ServerFnHandler, ServerFnMethod, ServerFnRefConfig, StandardSchemaV1 };
397
+ /**
398
+ * Typed route path utilities for Analog.
399
+ *
400
+ * This module provides:
401
+ * - The `AnalogRouteTable` base interface (augmented by generated code)
402
+ * - The `AnalogRoutePath` union type
403
+ * - The `toRoute()` URL builder function
404
+ *
405
+ * Link construction does not require an injection context.
406
+ */
407
+ /**
408
+ * Base interface for the typed route table.
409
+ *
410
+ * This interface is augmented by generated code in `src/routeTree.gen.d.ts`.
411
+ * Without the generated declaration, typed helpers reject route paths.
412
+ */
413
+ interface AnalogRouteTable {
414
+ }
415
+ /**
416
+ * Union of all valid route paths.
417
+ *
418
+ * When routes are generated, this is a string literal union.
419
+ * Without the generated declaration, this is `never`.
420
+ */
421
+ type AnalogRoutePath = Extract<keyof AnalogRouteTable, string>;
422
+ /**
423
+ * Options for building a route URL.
424
+ */
425
+ interface RoutePathOptionsBase {
426
+ params?: Record<string, string | number | (string | number)[] | undefined>;
427
+ query?: Record<string, string | string[] | undefined>;
428
+ hash?: string;
429
+ }
430
+ /** Raw parameter types from the generated route table. */
431
+ type RouteParamsOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
432
+ params: infer Params;
433
+ } ? Params : Record<string, unknown> : Record<string, unknown>;
434
+ /**
435
+ * Extracts the raw output type for route query params.
436
+ */
437
+ type RouteQueryOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
438
+ query: infer O;
439
+ } ? O : Record<string, string | string[] | undefined> : Record<string, string | string[] | undefined>;
440
+ type RequiredRouteParamKeys<Params> = Params extends Record<string, never> ? never : {
441
+ [K in keyof Params]-?: Record<string, never> extends Pick<Params, K> ? never : K;
442
+ }[keyof Params];
443
+ type HasRequiredRouteParams<Params> = [RequiredRouteParamKeys<Params>] extends [
444
+ never
445
+ ] ? false : true;
446
+ type RouteParamsInput<Params> = {
447
+ [K in keyof Params]: Exclude<Params[K], undefined> extends string[] ? undefined extends Params[K] ? (string | number)[] : [string | number, ...(string | number)[]] : Exclude<Params[K], undefined> extends string ? string | number : Params[K];
448
+ };
449
+ /**
450
+ * Typed options that infer params from the route table when available.
451
+ */
452
+ type RoutePathOptions<P extends string = string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
453
+ params: infer Params;
454
+ } ? Params extends Record<string, never> ? {
455
+ params?: never;
456
+ query?: RouteQueryOutput<P>;
457
+ hash?: string;
458
+ } : HasRequiredRouteParams<Params> extends true ? {
459
+ params: RouteParamsInput<Params>;
460
+ query?: RouteQueryOutput<P>;
461
+ hash?: string;
462
+ } : {
463
+ params?: RouteParamsInput<Params>;
464
+ query?: RouteQueryOutput<P>;
465
+ hash?: string;
466
+ } : RoutePathOptionsBase : RoutePathOptionsBase;
467
+ /**
468
+ * Conditional args: require options when the route has params.
469
+ */
470
+ type RoutePathArgs<P extends string = string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
471
+ params: infer Params;
472
+ } ? Params extends Record<string, never> ? [options?: RoutePathOptions<P>] : HasRequiredRouteParams<Params> extends true ? [options: RoutePathOptions<P>] : [options?: RoutePathOptions<P>] : [options?: RoutePathOptionsBase] : [options?: RoutePathOptionsBase];
473
+ /**
474
+ * Result of `toRoute()` — contains properties that map directly
475
+ * to Angular's `[routerLink]`, `[queryParams]`, and `[fragment]` inputs.
476
+ */
477
+ interface RouteLinkResult {
478
+ path: string[];
479
+ queryParams: Record<string, string | string[]> | null;
480
+ fragment: string | undefined;
481
+ }
482
+ /**
483
+ * Builds a typed route link object from a route path pattern and options.
484
+ *
485
+ * The returned object separates path, query params, and fragment for
486
+ * direct use with Angular's routerLink directive inputs.
487
+ *
488
+ * @example
489
+ * toRoute('/about')
490
+ * // → { path: ['/', 'about'], queryParams: null, fragment: undefined }
491
+ *
492
+ * toRoute('/users/[id]', { params: { id: '42' } })
493
+ * // → { path: ['/', 'users', '42'], queryParams: null, fragment: undefined }
494
+ *
495
+ * toRoute('/users/[id]', { params: { id: '42' }, query: { tab: 'settings' }, hash: 'bio' })
496
+ * // → { path: ['/', 'users', '42'], queryParams: { tab: 'settings' }, fragment: 'bio' }
497
+ *
498
+ * @example Template usage
499
+ * Compute the link in the component:
500
+ * ```ts
501
+ * readonly link = toRoute('/users/[id]', { params: { id: '42' } });
502
+ * ```
503
+ *
504
+ * ```html
505
+ * <a [routerLink]="link.path" [queryParams]="link.queryParams" [fragment]="link.fragment">
506
+ * ```
507
+ */
508
+ declare function toRoute<P extends AnalogRoutePath>(path: P, ...args: RoutePathArgs<P>): RouteLinkResult;
509
+
510
+ type LinkToDestination = {
511
+ [P in AnalogRoutePath]: {
512
+ path: P;
513
+ } & RoutePathOptions<P>;
514
+ }[AnalogRoutePath];
515
+ type StaticRoutePath = {
516
+ [P in AnalogRoutePath]: RouteParamsOutput<P> extends Record<string, never> ? P : never;
517
+ }[AnalogRoutePath];
518
+ declare class LinkTo implements OnChanges {
519
+ readonly linkTo: InputSignal<StaticRoutePath | LinkToDestination | null | undefined>;
520
+ private readonly routerLink;
521
+ ngOnChanges(): void;
522
+ static ɵfac: i0.ɵɵFactoryDeclaration<LinkTo, never>;
523
+ static ɵdir: i0.ɵɵDirectiveDeclaration<LinkTo, "[linkTo]", never, { "linkTo": { "alias": "linkTo"; "required": true; "isSignal": true; }; }, {}, never, never, true, [{ directive: typeof _angular_router.RouterLink; inputs: { "target": "target"; "queryParamsHandling": "queryParamsHandling"; "preserveFragment": "preserveFragment"; "skipLocationChange": "skipLocationChange"; "replaceUrl": "replaceUrl"; "state": "state"; }; outputs: {}; }]>;
524
+ }
525
+
526
+ type NavigateWithExtrasArgs<P extends AnalogRoutePath> = [
527
+ ] extends RoutePathArgs<P> ? [extras: NavigationBehaviorOptions] | [
528
+ options: RoutePathArgs<P>[0] | undefined,
529
+ extras: NavigationBehaviorOptions
530
+ ] : [options: RoutePathArgs<P>[0], extras: NavigationBehaviorOptions];
531
+ type TypedNavigate = {
532
+ <P extends AnalogRoutePath>(path: P, ...args: RoutePathArgs<P>): Promise<boolean>;
533
+ <P extends AnalogRoutePath>(path: P, ...args: NavigateWithExtrasArgs<P>): Promise<boolean>;
534
+ };
535
+ /**
536
+ * Injects a typed navigate function.
537
+ *
538
+ * @example
539
+ * ```ts
540
+ * const navigate = injectNavigate();
541
+ *
542
+ * navigate('/users/[id]', { params: { id: '42' } }); // ✅
543
+ * navigate('/users/[id]', { params: { id: 42 } }); // ✅
544
+ *
545
+ * // With navigation extras
546
+ * navigate('/users/[id]', { params: { id: '42' } }, { replaceUrl: true });
547
+ * ```
548
+ */
549
+ declare function injectNavigate(): TypedNavigate;
550
+
551
+ /** Read raw route params; catch-all segments are returned as arrays. */
552
+ declare function injectParams<P extends AnalogRoutePath>(_from: P, options?: {
553
+ injector?: Injector;
554
+ }): Signal<RouteParamsOutput<P>>;
555
+ /** Read raw query params as a signal. No schema coercion is performed. */
556
+ declare function injectQuery<P extends AnalogRoutePath>(_from: P, options?: {
557
+ injector?: Injector;
558
+ }): Signal<RouteQueryOutput<P>>;
559
+
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 };