@analogjs/router 2.7.3-beta.2 → 2.8.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/analogjs-router-server-actions.mjs +289 -1
- package/fesm2022/analogjs-router-server-actions.mjs.map +1 -1
- package/fesm2022/analogjs-router-tanstack-query-server.mjs +90 -0
- package/fesm2022/analogjs-router-tanstack-query-server.mjs.map +1 -0
- package/fesm2022/analogjs-router-tanstack-query.mjs +142 -0
- package/fesm2022/analogjs-router-tanstack-query.mjs.map +1 -0
- package/fesm2022/analogjs-router.mjs +227 -3
- package/fesm2022/analogjs-router.mjs.map +1 -1
- package/package.json +17 -3
- package/types/analogjs-router-server-actions.d.ts +167 -2
- package/types/analogjs-router-tanstack-query-server.d.ts +70 -0
- package/types/analogjs-router-tanstack-query.d.ts +33 -0
- package/types/analogjs-router.d.ts +180 -17
|
@@ -12,5 +12,170 @@ 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
|
-
|
|
16
|
-
|
|
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$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;
|
|
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']>;
|
|
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$1<TQuery, undefined>, InferSchema$1<TBody, undefined>, TResult>;
|
|
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>>;
|
|
126
|
+
req: H3Event['node']['req'];
|
|
127
|
+
res: H3Event['node']['res'];
|
|
128
|
+
fetch: $Fetch;
|
|
129
|
+
event: H3Event;
|
|
130
|
+
}
|
|
131
|
+
interface DefinePageLoadOptions<TParamsSchema extends OptionalSchema = undefined, TQuerySchema extends OptionalSchema = 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 = undefined, TQuerySchema extends OptionalSchema = 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
|
+
export { StandardSchemaV1, definePageLoad, defineServerRoute, fail, json, redirect, validateWithSchema };
|
|
181
|
+
export type { 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,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
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';
|
|
@@ -171,10 +171,10 @@ declare function requestContextInterceptor(req: HttpRequest<unknown>, next: Http
|
|
|
171
171
|
declare function injectRouteEndpointURL(route: ActivatedRouteSnapshot): URL;
|
|
172
172
|
|
|
173
173
|
declare class FormAction {
|
|
174
|
-
action:
|
|
175
|
-
onSuccess:
|
|
176
|
-
onError:
|
|
177
|
-
state:
|
|
174
|
+
action: i0.InputSignal<string>;
|
|
175
|
+
onSuccess: i0.OutputEmitterRef<unknown>;
|
|
176
|
+
onError: i0.OutputEmitterRef<unknown>;
|
|
177
|
+
state: i0.OutputEmitterRef<"error" | "navigate" | "redirect" | "submitting" | "success">;
|
|
178
178
|
private router;
|
|
179
179
|
private route;
|
|
180
180
|
private path;
|
|
@@ -183,8 +183,8 @@ declare class FormAction {
|
|
|
183
183
|
private _handlePost;
|
|
184
184
|
private _getPath;
|
|
185
185
|
private _isJSON;
|
|
186
|
-
static ɵfac:
|
|
187
|
-
static ɵdir:
|
|
186
|
+
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>;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
type DebugRoute = {
|
|
@@ -206,8 +206,8 @@ declare class DebugRoutesComponent {
|
|
|
206
206
|
debugRoutes: (_angular_router.Route & DebugRoute)[];
|
|
207
207
|
ngOnInit(): void;
|
|
208
208
|
traverseRoutes(routes: DebugRoute[], parent?: string): void;
|
|
209
|
-
static ɵfac:
|
|
210
|
-
static ɵcmp:
|
|
209
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DebugRoutesComponent, never>;
|
|
210
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<DebugRoutesComponent, "analogjs-debug-routes-page", never, {}, {}, never, never, true, never>;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
declare namespace __debug_page {
|
|
@@ -224,7 +224,7 @@ declare namespace __debug_page {
|
|
|
224
224
|
declare function withDebugRoutes(): {
|
|
225
225
|
ɵkind: number;
|
|
226
226
|
ɵproviders: {
|
|
227
|
-
provide:
|
|
227
|
+
provide: i0.InjectionToken<_angular_router.Route[][]>;
|
|
228
228
|
useValue: {
|
|
229
229
|
path: string;
|
|
230
230
|
loadComponent: () => Promise<typeof __debug_page>;
|
|
@@ -305,11 +305,11 @@ declare class ServerFnClient {
|
|
|
305
305
|
get isServer(): boolean;
|
|
306
306
|
call<In, Out>(fn: ServerFn<In, Out>, input: In): Promise<Out>;
|
|
307
307
|
/** Key a read's value for TransferState hydration (fn id + input). */
|
|
308
|
-
stateKey<Out>(fn: ServerFn<unknown, Out>, input: unknown):
|
|
308
|
+
stateKey<Out>(fn: ServerFn<unknown, Out>, input: unknown): i0.StateKey<Out>;
|
|
309
309
|
readSeed<Out>(fn: ServerFn<unknown, Out>, input: unknown): Out | undefined;
|
|
310
310
|
writeSeed<Out>(fn: ServerFn<unknown, Out>, input: unknown, value: Out): void;
|
|
311
|
-
static ɵfac:
|
|
312
|
-
static ɵprov:
|
|
311
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ServerFnClient, never>;
|
|
312
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ServerFnClient>;
|
|
313
313
|
}
|
|
314
314
|
/** No-op provider hook; ServerFnClient is `providedIn: 'root'`. */
|
|
315
315
|
declare function provideServerFnClient(): readonly [];
|
|
@@ -377,5 +377,168 @@ declare function createServerFnRef<In, Out>(config: ServerFnRefConfig): ServerFn
|
|
|
377
377
|
type ServerFnDispatcher = <In, Out>(fn: ServerFn<In, Out>, input: In, injector: Injector) => Promise<Out>;
|
|
378
378
|
declare const SERVER_FN_DISPATCHER: InjectionToken<ServerFnDispatcher>;
|
|
379
379
|
|
|
380
|
-
|
|
381
|
-
|
|
380
|
+
/**
|
|
381
|
+
* Typed route path utilities for Analog.
|
|
382
|
+
*
|
|
383
|
+
* This module provides:
|
|
384
|
+
* - The `AnalogRouteTable` base interface (augmented by generated code)
|
|
385
|
+
* - The `AnalogRoutePath` union type
|
|
386
|
+
* - The `toRoute()` URL builder function
|
|
387
|
+
*
|
|
388
|
+
* Link construction does not require an injection context.
|
|
389
|
+
*/
|
|
390
|
+
/**
|
|
391
|
+
* Base interface for the typed route table.
|
|
392
|
+
*
|
|
393
|
+
* This interface is augmented by generated code in `src/routeTree.gen.d.ts`.
|
|
394
|
+
* Without the generated declaration, typed helpers reject route paths.
|
|
395
|
+
*/
|
|
396
|
+
interface AnalogRouteTable {
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Union of all valid route paths.
|
|
400
|
+
*
|
|
401
|
+
* When routes are generated, this is a string literal union.
|
|
402
|
+
* Without the generated declaration, this is `never`.
|
|
403
|
+
*/
|
|
404
|
+
type AnalogRoutePath = Extract<keyof AnalogRouteTable, string>;
|
|
405
|
+
/**
|
|
406
|
+
* Options for building a route URL.
|
|
407
|
+
*/
|
|
408
|
+
interface RoutePathOptionsBase {
|
|
409
|
+
params?: Record<string, string | number | (string | number)[] | undefined>;
|
|
410
|
+
query?: Record<string, string | string[] | undefined>;
|
|
411
|
+
hash?: string;
|
|
412
|
+
}
|
|
413
|
+
/** Raw parameter types from the generated route table. */
|
|
414
|
+
type RouteParamsOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
|
|
415
|
+
params: infer Params;
|
|
416
|
+
} ? Params : Record<string, unknown> : Record<string, unknown>;
|
|
417
|
+
/**
|
|
418
|
+
* Extracts the raw output type for route query params.
|
|
419
|
+
*/
|
|
420
|
+
type RouteQueryOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
|
|
421
|
+
query: infer O;
|
|
422
|
+
} ? O : Record<string, string | string[] | undefined> : Record<string, string | string[] | undefined>;
|
|
423
|
+
type RequiredRouteParamKeys<Params> = Params extends Record<string, never> ? never : {
|
|
424
|
+
[K in keyof Params]-?: Record<string, never> extends Pick<Params, K> ? never : K;
|
|
425
|
+
}[keyof Params];
|
|
426
|
+
type HasRequiredRouteParams<Params> = [RequiredRouteParamKeys<Params>] extends [
|
|
427
|
+
never
|
|
428
|
+
] ? false : true;
|
|
429
|
+
type RouteParamsInput<Params> = {
|
|
430
|
+
[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];
|
|
431
|
+
};
|
|
432
|
+
/**
|
|
433
|
+
* Typed options that infer params from the route table when available.
|
|
434
|
+
*/
|
|
435
|
+
type RoutePathOptions<P extends string = string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
|
|
436
|
+
params: infer Params;
|
|
437
|
+
} ? Params extends Record<string, never> ? {
|
|
438
|
+
params?: never;
|
|
439
|
+
query?: RouteQueryOutput<P>;
|
|
440
|
+
hash?: string;
|
|
441
|
+
} : HasRequiredRouteParams<Params> extends true ? {
|
|
442
|
+
params: RouteParamsInput<Params>;
|
|
443
|
+
query?: RouteQueryOutput<P>;
|
|
444
|
+
hash?: string;
|
|
445
|
+
} : {
|
|
446
|
+
params?: RouteParamsInput<Params>;
|
|
447
|
+
query?: RouteQueryOutput<P>;
|
|
448
|
+
hash?: string;
|
|
449
|
+
} : RoutePathOptionsBase : RoutePathOptionsBase;
|
|
450
|
+
/**
|
|
451
|
+
* Conditional args: require options when the route has params.
|
|
452
|
+
*/
|
|
453
|
+
type RoutePathArgs<P extends string = string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
|
|
454
|
+
params: infer Params;
|
|
455
|
+
} ? Params extends Record<string, never> ? [options?: RoutePathOptions<P>] : HasRequiredRouteParams<Params> extends true ? [options: RoutePathOptions<P>] : [options?: RoutePathOptions<P>] : [options?: RoutePathOptionsBase] : [options?: RoutePathOptionsBase];
|
|
456
|
+
/**
|
|
457
|
+
* Result of `toRoute()` — contains properties that map directly
|
|
458
|
+
* to Angular's `[routerLink]`, `[queryParams]`, and `[fragment]` inputs.
|
|
459
|
+
*/
|
|
460
|
+
interface RouteLinkResult {
|
|
461
|
+
path: string[];
|
|
462
|
+
queryParams: Record<string, string | string[]> | null;
|
|
463
|
+
fragment: string | undefined;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Builds a typed route link object from a route path pattern and options.
|
|
467
|
+
*
|
|
468
|
+
* The returned object separates path, query params, and fragment for
|
|
469
|
+
* direct use with Angular's routerLink directive inputs.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* toRoute('/about')
|
|
473
|
+
* // → { path: ['/', 'about'], queryParams: null, fragment: undefined }
|
|
474
|
+
*
|
|
475
|
+
* toRoute('/users/[id]', { params: { id: '42' } })
|
|
476
|
+
* // → { path: ['/', 'users', '42'], queryParams: null, fragment: undefined }
|
|
477
|
+
*
|
|
478
|
+
* toRoute('/users/[id]', { params: { id: '42' }, query: { tab: 'settings' }, hash: 'bio' })
|
|
479
|
+
* // → { path: ['/', 'users', '42'], queryParams: { tab: 'settings' }, fragment: 'bio' }
|
|
480
|
+
*
|
|
481
|
+
* @example Template usage
|
|
482
|
+
* Compute the link in the component:
|
|
483
|
+
* ```ts
|
|
484
|
+
* readonly link = toRoute('/users/[id]', { params: { id: '42' } });
|
|
485
|
+
* ```
|
|
486
|
+
*
|
|
487
|
+
* ```html
|
|
488
|
+
* <a [routerLink]="link.path" [queryParams]="link.queryParams" [fragment]="link.fragment">
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
declare function toRoute<P extends AnalogRoutePath>(path: P, ...args: RoutePathArgs<P>): RouteLinkResult;
|
|
492
|
+
|
|
493
|
+
type LinkToDestination = {
|
|
494
|
+
[P in AnalogRoutePath]: {
|
|
495
|
+
path: P;
|
|
496
|
+
} & RoutePathOptions<P>;
|
|
497
|
+
}[AnalogRoutePath];
|
|
498
|
+
type StaticRoutePath = {
|
|
499
|
+
[P in AnalogRoutePath]: RouteParamsOutput<P> extends Record<string, never> ? P : never;
|
|
500
|
+
}[AnalogRoutePath];
|
|
501
|
+
declare class LinkTo implements OnChanges {
|
|
502
|
+
readonly linkTo: InputSignal<StaticRoutePath | LinkToDestination | null | undefined>;
|
|
503
|
+
private readonly routerLink;
|
|
504
|
+
ngOnChanges(): void;
|
|
505
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LinkTo, never>;
|
|
506
|
+
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: {}; }]>;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
type NavigateWithExtrasArgs<P extends AnalogRoutePath> = [
|
|
510
|
+
] extends RoutePathArgs<P> ? [extras: NavigationBehaviorOptions] | [
|
|
511
|
+
options: RoutePathArgs<P>[0] | undefined,
|
|
512
|
+
extras: NavigationBehaviorOptions
|
|
513
|
+
] : [options: RoutePathArgs<P>[0], extras: NavigationBehaviorOptions];
|
|
514
|
+
type TypedNavigate = {
|
|
515
|
+
<P extends AnalogRoutePath>(path: P, ...args: RoutePathArgs<P>): Promise<boolean>;
|
|
516
|
+
<P extends AnalogRoutePath>(path: P, ...args: NavigateWithExtrasArgs<P>): Promise<boolean>;
|
|
517
|
+
};
|
|
518
|
+
/**
|
|
519
|
+
* Injects a typed navigate function.
|
|
520
|
+
*
|
|
521
|
+
* @example
|
|
522
|
+
* ```ts
|
|
523
|
+
* const navigate = injectNavigate();
|
|
524
|
+
*
|
|
525
|
+
* navigate('/users/[id]', { params: { id: '42' } }); // ✅
|
|
526
|
+
* navigate('/users/[id]', { params: { id: 42 } }); // ✅
|
|
527
|
+
*
|
|
528
|
+
* // With navigation extras
|
|
529
|
+
* navigate('/users/[id]', { params: { id: '42' } }, { replaceUrl: true });
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
declare function injectNavigate(): TypedNavigate;
|
|
533
|
+
|
|
534
|
+
/** Read raw route params; catch-all segments are returned as arrays. */
|
|
535
|
+
declare function injectParams<P extends AnalogRoutePath>(_from: P, options?: {
|
|
536
|
+
injector?: Injector;
|
|
537
|
+
}): Signal<RouteParamsOutput<P>>;
|
|
538
|
+
/** Read raw query params as a signal. No schema coercion is performed. */
|
|
539
|
+
declare function injectQuery<P extends AnalogRoutePath>(_from: P, options?: {
|
|
540
|
+
injector?: Injector;
|
|
541
|
+
}): Signal<RouteQueryOutput<P>>;
|
|
542
|
+
|
|
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 };
|