@analogjs/router 3.0.0-alpha.3 → 3.0.0-alpha.30
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/content/package.json +4 -0
- package/fesm2022/analogjs-router-content.mjs +63 -0
- package/fesm2022/analogjs-router-content.mjs.map +1 -0
- package/fesm2022/analogjs-router-server-actions.mjs +309 -1
- package/fesm2022/analogjs-router-server-actions.mjs.map +1 -0
- package/fesm2022/analogjs-router-server.mjs +2 -2
- package/fesm2022/analogjs-router-server.mjs.map +1 -0
- package/fesm2022/analogjs-router-tanstack-query-server.mjs +22 -0
- package/fesm2022/analogjs-router-tanstack-query-server.mjs.map +1 -0
- package/fesm2022/analogjs-router-tanstack-query.mjs +39 -0
- package/fesm2022/analogjs-router-tanstack-query.mjs.map +1 -0
- package/fesm2022/analogjs-router-tokens.mjs.map +1 -0
- package/fesm2022/analogjs-router.mjs +560 -62
- package/fesm2022/analogjs-router.mjs.map +1 -0
- package/fesm2022/debug.page.mjs +53 -31
- package/fesm2022/debug.page.mjs.map +1 -0
- package/fesm2022/provide-analog-query.mjs +23 -0
- package/fesm2022/provide-analog-query.mjs.map +1 -0
- package/fesm2022/route-files.mjs +362 -0
- package/fesm2022/route-files.mjs.map +1 -0
- package/fesm2022/routes.mjs +5 -278
- package/fesm2022/routes.mjs.map +1 -0
- package/package.json +71 -25
- package/tanstack-query/package.json +4 -0
- package/tanstack-query/server/package.json +4 -0
- package/types/content/src/index.d.ts +4 -0
- package/types/content/src/lib/debug/routes.d.ts +10 -0
- package/types/{src → content/src}/lib/markdown-helpers.d.ts +1 -1
- package/types/content/src/lib/routes.d.ts +8 -0
- package/types/content/src/lib/with-content-routes.d.ts +2 -0
- package/types/server/actions/src/define-action.d.ts +54 -0
- package/types/server/actions/src/define-api-route.d.ts +57 -0
- package/types/server/actions/src/define-page-load.d.ts +55 -0
- package/types/server/actions/src/define-server-route.d.ts +68 -0
- package/types/server/actions/src/index.d.ts +9 -1
- package/types/server/actions/src/parse-request-data.d.ts +9 -0
- package/types/server/actions/src/validate.d.ts +8 -0
- package/types/server/src/provide-server-context.d.ts +1 -1
- package/types/server/src/render.d.ts +1 -1
- package/types/server/src/server-component-render.d.ts +1 -1
- package/types/src/index.d.ts +16 -5
- package/types/src/lib/cache-key.d.ts +1 -1
- package/types/src/lib/cookie-interceptor.d.ts +1 -1
- package/types/src/lib/debug/debug.page.d.ts +4 -2
- package/types/src/lib/define-route.d.ts +6 -1
- package/types/src/lib/endpoints.d.ts +1 -1
- package/types/src/lib/experimental.d.ts +140 -0
- package/types/src/lib/form-action.directive.d.ts +12 -5
- package/types/src/lib/inject-load.d.ts +5 -2
- package/types/src/lib/inject-navigate.d.ts +23 -0
- package/types/src/lib/inject-route-context.d.ts +32 -0
- package/types/src/lib/inject-typed-params.d.ts +63 -0
- package/types/src/lib/json-ld.d.ts +32 -0
- package/types/src/lib/meta-tags.d.ts +3 -1
- package/types/src/lib/models.d.ts +3 -0
- package/types/src/lib/provide-file-router-base.d.ts +4 -0
- package/types/src/lib/provide-file-router.d.ts +2 -8
- package/types/src/lib/route-builder.d.ts +5 -0
- package/types/src/lib/route-files.d.ts +18 -0
- package/types/src/lib/route-path.d.ts +124 -0
- package/types/src/lib/route-types.d.ts +2 -1
- package/types/src/lib/routes.d.ts +2 -10
- package/types/src/lib/validation-errors.d.ts +7 -0
- package/types/tanstack-query/server/src/index.d.ts +1 -0
- package/types/tanstack-query/src/index.d.ts +2 -0
- package/types/tanstack-query/src/provide-analog-query.d.ts +4 -0
- package/types/tanstack-query/src/provide-server-analog-query.d.ts +2 -0
- package/types/tanstack-query/src/server-query.d.ts +16 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed route path utilities for Analog.
|
|
3
|
+
*
|
|
4
|
+
* This module provides:
|
|
5
|
+
* - The `AnalogRouteTable` base interface (augmented by generated code)
|
|
6
|
+
* - The `AnalogRoutePath` union type
|
|
7
|
+
* - The `routePath()` URL builder function
|
|
8
|
+
*
|
|
9
|
+
* No Angular dependencies — can be used in any context.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Base interface for the typed route table.
|
|
13
|
+
*
|
|
14
|
+
* This interface is augmented by generated code in `src/routeTree.gen.ts`.
|
|
15
|
+
* When no routes are generated, it is empty and `AnalogRoutePath` falls
|
|
16
|
+
* back to `string`.
|
|
17
|
+
*/
|
|
18
|
+
export interface AnalogRouteTable {
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Union of all valid route paths.
|
|
22
|
+
*
|
|
23
|
+
* When routes are generated, this is a string literal union.
|
|
24
|
+
* When no routes are generated, this falls back to `string`.
|
|
25
|
+
*/
|
|
26
|
+
export type AnalogRoutePath = keyof AnalogRouteTable extends never ? string : Extract<keyof AnalogRouteTable, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Options for building a route URL.
|
|
29
|
+
*/
|
|
30
|
+
export interface RoutePathOptionsBase {
|
|
31
|
+
params?: Record<string, string | string[] | undefined>;
|
|
32
|
+
query?: Record<string, string | string[] | undefined>;
|
|
33
|
+
hash?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Extracts the validated output type for route params.
|
|
37
|
+
*
|
|
38
|
+
* When a route exports `routeParamsSchema`, this resolves to the schema's
|
|
39
|
+
* output type (e.g., `{ id: number }` after coercion).
|
|
40
|
+
* When no schema exists, this is the same as the navigation param type.
|
|
41
|
+
*/
|
|
42
|
+
export type RouteParamsOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
|
|
43
|
+
paramsOutput: infer O;
|
|
44
|
+
} ? O : AnalogRouteTable[P] extends {
|
|
45
|
+
params: infer Params;
|
|
46
|
+
} ? Params : Record<string, unknown> : Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* Extracts the validated output type for route query params.
|
|
49
|
+
*/
|
|
50
|
+
export type RouteQueryOutput<P extends string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
|
|
51
|
+
queryOutput: infer O;
|
|
52
|
+
} ? O : Record<string, string | string[] | undefined> : Record<string, string | string[] | undefined>;
|
|
53
|
+
type RequiredRouteParamKeys<Params> = Params extends Record<string, never> ? never : {
|
|
54
|
+
[K in keyof Params]-?: Record<string, never> extends Pick<Params, K> ? never : K;
|
|
55
|
+
}[keyof Params];
|
|
56
|
+
type HasRequiredRouteParams<Params> = [RequiredRouteParamKeys<Params>] extends [
|
|
57
|
+
never
|
|
58
|
+
] ? false : true;
|
|
59
|
+
/**
|
|
60
|
+
* Typed options that infer params from the route table when available.
|
|
61
|
+
*/
|
|
62
|
+
export type RoutePathOptions<P extends string = string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
|
|
63
|
+
params: infer Params;
|
|
64
|
+
} ? Params extends Record<string, never> ? {
|
|
65
|
+
query?: RouteQueryOutput<P>;
|
|
66
|
+
hash?: string;
|
|
67
|
+
} : HasRequiredRouteParams<Params> extends true ? {
|
|
68
|
+
params: Params;
|
|
69
|
+
query?: RouteQueryOutput<P>;
|
|
70
|
+
hash?: string;
|
|
71
|
+
} : {
|
|
72
|
+
params?: Params;
|
|
73
|
+
query?: RouteQueryOutput<P>;
|
|
74
|
+
hash?: string;
|
|
75
|
+
} : RoutePathOptionsBase : RoutePathOptionsBase;
|
|
76
|
+
/**
|
|
77
|
+
* Conditional args: require options when the route has params.
|
|
78
|
+
*/
|
|
79
|
+
export type RoutePathArgs<P extends string = string> = P extends keyof AnalogRouteTable ? AnalogRouteTable[P] extends {
|
|
80
|
+
params: infer Params;
|
|
81
|
+
} ? Params extends Record<string, never> ? [options?: RoutePathOptions<P>] : HasRequiredRouteParams<Params> extends true ? [options: RoutePathOptions<P>] : [options?: RoutePathOptions<P>] : [options?: RoutePathOptionsBase] : [options?: RoutePathOptionsBase];
|
|
82
|
+
/**
|
|
83
|
+
* Result of `routePath()` — contains properties that map directly
|
|
84
|
+
* to Angular's `[routerLink]`, `[queryParams]`, and `[fragment]` inputs.
|
|
85
|
+
*/
|
|
86
|
+
export interface RouteLinkResult {
|
|
87
|
+
path: string;
|
|
88
|
+
queryParams: Record<string, string | string[]> | null;
|
|
89
|
+
fragment: string | undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Builds a typed route link object from a route path pattern and options.
|
|
93
|
+
*
|
|
94
|
+
* The returned object separates path, query params, and fragment for
|
|
95
|
+
* direct use with Angular's routerLink directive inputs.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* routePath('/about')
|
|
99
|
+
* // → { path: '/about', queryParams: null, fragment: undefined }
|
|
100
|
+
*
|
|
101
|
+
* routePath('/users/[id]', { params: { id: '42' } })
|
|
102
|
+
* // → { path: '/users/42', queryParams: null, fragment: undefined }
|
|
103
|
+
*
|
|
104
|
+
* routePath('/users/[id]', { params: { id: '42' }, query: { tab: 'settings' }, hash: 'bio' })
|
|
105
|
+
* // → { path: '/users/42', queryParams: { tab: 'settings' }, fragment: 'bio' }
|
|
106
|
+
*
|
|
107
|
+
* @example Template usage
|
|
108
|
+
* ```html
|
|
109
|
+
* @let link = routePath('/users/[id]', { params: { id: userId } });
|
|
110
|
+
* <a [routerLink]="link.path" [queryParams]="link.queryParams" [fragment]="link.fragment">
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function routePath<P extends AnalogRoutePath>(path: P, ...args: RoutePathArgs<P>): RouteLinkResult;
|
|
114
|
+
/**
|
|
115
|
+
* Internal: builds a `RouteLinkResult` from path and options.
|
|
116
|
+
* Exported for direct use in tests (avoids generic constraints).
|
|
117
|
+
*/
|
|
118
|
+
export declare function buildRouteLink(path: string, options?: RoutePathOptionsBase): RouteLinkResult;
|
|
119
|
+
/**
|
|
120
|
+
* Internal URL builder. Separated from `routePath` so it can be
|
|
121
|
+
* used without generic constraints (e.g., in `injectNavigate`).
|
|
122
|
+
*/
|
|
123
|
+
export declare function buildUrl(path: string, options?: RoutePathOptionsBase): string;
|
|
124
|
+
export {};
|
|
@@ -8,4 +8,5 @@ export type PageServerLoad = {
|
|
|
8
8
|
fetch: $Fetch;
|
|
9
9
|
event: H3Event;
|
|
10
10
|
};
|
|
11
|
-
export type LoadResult<A extends (pageServerLoad: PageServerLoad) => Promise<
|
|
11
|
+
export type LoadResult<A extends (pageServerLoad: PageServerLoad) => Promise<unknown>> = Awaited<ReturnType<A>>;
|
|
12
|
+
export type LoadDataResult<A extends (pageServerLoad: PageServerLoad) => Promise<unknown>> = Exclude<LoadResult<A>, Response>;
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import type { Route } from '@angular/router';
|
|
2
|
-
import type
|
|
3
|
-
/**
|
|
4
|
-
* This variable reference is replaced with a glob of all page routes.
|
|
5
|
-
*/
|
|
6
|
-
export declare const ANALOG_ROUTE_FILES: {};
|
|
7
|
-
/**
|
|
8
|
-
* This variable reference is replaced with a glob of all content routes.
|
|
9
|
-
*/
|
|
10
|
-
export declare const ANALOG_CONTENT_ROUTE_FILES: {};
|
|
11
|
-
export type Files = Record<string, () => Promise<RouteExport | string>>;
|
|
2
|
+
import { type Files } from './route-files';
|
|
12
3
|
/**
|
|
13
4
|
* A function used to parse list of files and create configuration of routes.
|
|
14
5
|
*
|
|
@@ -16,4 +7,5 @@ export type Files = Record<string, () => Promise<RouteExport | string>>;
|
|
|
16
7
|
* @returns Array of routes
|
|
17
8
|
*/
|
|
18
9
|
export declare function createRoutes(files: Files, debug?: boolean): Route[];
|
|
10
|
+
export { ANALOG_ROUTE_FILES } from './route-files';
|
|
19
11
|
export declare const routes: Route[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
export type ValidationFieldErrors = Record<string, string[]>;
|
|
3
|
+
export declare function issuePathToFieldName(path: ReadonlyArray<string | number | symbol | {
|
|
4
|
+
key: string | number | symbol;
|
|
5
|
+
}>): string;
|
|
6
|
+
export declare function issuesToFieldErrors(issues: ReadonlyArray<StandardSchemaV1.Issue>): ValidationFieldErrors;
|
|
7
|
+
export declare function issuesToFormErrors(issues: ReadonlyArray<StandardSchemaV1.Issue>): string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { provideServerAnalogQuery } from '../../src/provide-server-analog-query';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EnvironmentProviders, StateKey } from '@angular/core';
|
|
2
|
+
import type { DehydratedState } from '@tanstack/angular-query-experimental';
|
|
3
|
+
export declare const ANALOG_QUERY_STATE_KEY: StateKey<DehydratedState>;
|
|
4
|
+
export declare function provideAnalogQuery(): EnvironmentProviders;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HttpClient } from '@angular/common/http';
|
|
2
|
+
import type { CreateQueryOptions, CreateMutationOptions, CreateInfiniteQueryOptions, DefaultError, InfiniteData, QueryKey } from '@tanstack/angular-query-experimental';
|
|
3
|
+
import type { ServerRouteHandler, InferRouteQuery, InferRouteBody, InferRouteResult } from '../../server/actions/src/index.js';
|
|
4
|
+
export declare function serverQueryOptions<TRoute extends ServerRouteHandler<any, any, any>, TError = DefaultError, TData = InferRouteResult<TRoute>, TQueryKey extends QueryKey = QueryKey>(http: HttpClient, url: string, options: {
|
|
5
|
+
queryKey: TQueryKey;
|
|
6
|
+
query?: InferRouteQuery<TRoute>;
|
|
7
|
+
} & Omit<CreateQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey>, 'queryKey' | 'queryFn'>): CreateQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey>;
|
|
8
|
+
export 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>;
|
|
9
|
+
export 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: {
|
|
10
|
+
queryKey: TQueryKey;
|
|
11
|
+
query: (context: {
|
|
12
|
+
pageParam: TPageParam;
|
|
13
|
+
}) => InferRouteQuery<TRoute>;
|
|
14
|
+
initialPageParam: TPageParam;
|
|
15
|
+
getNextPageParam: (lastPage: InferRouteResult<TRoute>, allPages: InferRouteResult<TRoute>[]) => TPageParam | undefined | null;
|
|
16
|
+
} & Omit<CreateInfiniteQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey, TPageParam>, 'queryKey' | 'queryFn' | 'initialPageParam' | 'getNextPageParam'>): CreateInfiniteQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey, TPageParam>;
|