@analogjs/router 3.0.0-alpha.2 → 3.0.0-alpha.21
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 +327 -31
- package/fesm2022/analogjs-router-server-actions.mjs.map +1 -1
- package/fesm2022/analogjs-router-server.mjs +151 -199
- package/fesm2022/analogjs-router-server.mjs.map +1 -1
- 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 +15 -18
- package/fesm2022/analogjs-router-tokens.mjs.map +1 -1
- package/fesm2022/analogjs-router.mjs +960 -815
- package/fesm2022/analogjs-router.mjs.map +1 -1
- package/fesm2022/debug.page.mjs +135 -0
- 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 +345 -0
- package/fesm2022/route-files.mjs.map +1 -0
- package/fesm2022/routes.mjs +28 -0
- package/fesm2022/routes.mjs.map +1 -0
- package/package.json +67 -27
- package/server/actions/package.json +4 -0
- package/server/package.json +4 -0
- package/tanstack-query/package.json +4 -0
- package/tanstack-query/server/package.json +4 -0
- package/tokens/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/content/src/lib/markdown-helpers.d.ts +2 -0
- 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/actions.d.ts +13 -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 -0
- 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/index.d.ts +4 -0
- package/types/server/src/provide-server-context.d.ts +11 -0
- package/types/server/src/render.d.ts +12 -0
- package/types/server/src/server-component-render.d.ts +4 -0
- package/types/server/src/tokens.d.ts +7 -0
- package/types/src/index.d.ts +27 -0
- package/types/src/lib/cache-key.d.ts +3 -0
- package/types/src/lib/constants.d.ts +2 -0
- package/types/src/lib/cookie-interceptor.d.ts +4 -0
- package/types/src/lib/debug/debug.page.d.ts +20 -0
- package/types/src/lib/debug/index.d.ts +10 -0
- package/types/src/lib/debug/routes.d.ts +10 -0
- package/types/src/lib/define-route.d.ts +51 -0
- package/types/src/lib/endpoints.d.ts +5 -0
- package/types/src/lib/experimental.d.ts +140 -0
- package/types/src/lib/form-action.directive.d.ts +25 -0
- package/types/src/lib/get-load-resolver.d.ts +8 -0
- package/types/src/lib/inject-load.d.ts +9 -0
- 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-route-endpoint-url.d.ts +2 -0
- package/types/src/lib/inject-typed-params.d.ts +63 -0
- package/types/src/lib/json-ld.d.ts +31 -0
- package/types/src/lib/meta-tags.d.ts +33 -0
- package/types/src/lib/models.d.ts +32 -0
- package/types/src/lib/provide-file-router-base.d.ts +4 -0
- package/types/src/lib/provide-file-router.d.ts +12 -0
- package/types/src/lib/request-context.d.ts +13 -0
- package/types/src/lib/route-builder.d.ts +5 -0
- package/types/src/lib/route-config.d.ts +2 -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 +12 -0
- package/types/src/lib/routes.d.ts +11 -0
- package/types/src/lib/server.component.d.ts +33 -0
- 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
- package/types/tokens/src/index.d.ts +23 -0
- package/fesm2022/analogjs-router-debug.page-jzggTA45.mjs +0 -91
- package/fesm2022/analogjs-router-debug.page-jzggTA45.mjs.map +0 -1
- package/types/analogjs-router-server-actions.d.ts +0 -17
- package/types/analogjs-router-server.d.ts +0 -29
- package/types/analogjs-router-tokens.d.ts +0 -27
- package/types/analogjs-router.d.ts +0 -269
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import type { H3Event, H3EventContext } from 'nitro/h3';
|
|
3
|
+
import type { $Fetch } from 'nitro/types';
|
|
4
|
+
type NodeContext = NonNullable<H3Event['node']>;
|
|
5
|
+
type OptionalSchema = StandardSchemaV1 | undefined;
|
|
6
|
+
type InferSchema<TSchema extends OptionalSchema, TFallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
|
|
7
|
+
export interface DefineActionContext<TSchema extends OptionalSchema = undefined, TParamsSchema extends OptionalSchema = undefined> {
|
|
8
|
+
data: InferSchema<TSchema, Record<string, unknown>>;
|
|
9
|
+
params: InferSchema<TParamsSchema, H3EventContext['params']>;
|
|
10
|
+
req: NodeContext['req'];
|
|
11
|
+
res: NonNullable<NodeContext['res']>;
|
|
12
|
+
fetch: $Fetch;
|
|
13
|
+
event: H3Event;
|
|
14
|
+
}
|
|
15
|
+
export interface DefineActionOptions<TSchema extends OptionalSchema = undefined, TParamsSchema extends OptionalSchema = undefined> {
|
|
16
|
+
schema?: TSchema;
|
|
17
|
+
params?: TParamsSchema;
|
|
18
|
+
handler: (context: DefineActionContext<TSchema, TParamsSchema>) => Promise<Response> | Response;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a server action handler with Standard Schema input validation.
|
|
22
|
+
*
|
|
23
|
+
* Parses the request body (JSON or FormData) and validates it against the
|
|
24
|
+
* provided schema before invoking the handler. On validation failure,
|
|
25
|
+
* returns `fail(422, issues)` with `StandardSchemaV1.Issue[]`.
|
|
26
|
+
* Repeated form fields are preserved as arrays instead of being collapsed
|
|
27
|
+
* to the last value.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { defineAction, json } from '@analogjs/router/server/actions';
|
|
32
|
+
* import * as v from 'valibot';
|
|
33
|
+
*
|
|
34
|
+
* const Schema = v.object({
|
|
35
|
+
* email: v.pipe(v.string(), v.email()),
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* export const action = defineAction({
|
|
39
|
+
* schema: Schema,
|
|
40
|
+
* handler: async ({ data }) => {
|
|
41
|
+
* // data is typed as { email: string }
|
|
42
|
+
* return json({ ok: true });
|
|
43
|
+
* },
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function defineAction<TSchema extends OptionalSchema = undefined, TParamsSchema extends OptionalSchema = undefined>(options: DefineActionOptions<TSchema, TParamsSchema>): (ctx: {
|
|
48
|
+
params: H3EventContext["params"];
|
|
49
|
+
req: NodeContext["req"];
|
|
50
|
+
res: NonNullable<NodeContext["res"]>;
|
|
51
|
+
fetch: $Fetch;
|
|
52
|
+
event: H3Event;
|
|
53
|
+
}) => Promise<Response>;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import type { H3Event } from 'nitro/h3';
|
|
3
|
+
export type DefineApiRouteResult = Response | unknown;
|
|
4
|
+
type OptionalSchema = StandardSchemaV1 | undefined;
|
|
5
|
+
type InferSchema<TSchema extends OptionalSchema, TFallback = unknown> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
|
|
6
|
+
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;
|
|
7
|
+
export interface DefineApiRouteContext<TInput extends StandardSchemaV1 | undefined = undefined, TQuery extends StandardSchemaV1 | undefined = undefined, TBody extends StandardSchemaV1 | undefined = undefined, TParams extends StandardSchemaV1 | undefined = undefined> {
|
|
8
|
+
data: ResolveDataSchema<TInput, TQuery, TBody>;
|
|
9
|
+
query: InferSchema<TQuery, undefined>;
|
|
10
|
+
body: InferSchema<TBody, undefined>;
|
|
11
|
+
params: InferSchema<TParams, H3Event['context']['params']>;
|
|
12
|
+
event: H3Event;
|
|
13
|
+
}
|
|
14
|
+
export 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> {
|
|
15
|
+
input?: TInput;
|
|
16
|
+
query?: TQuery;
|
|
17
|
+
body?: TBody;
|
|
18
|
+
params?: TParams;
|
|
19
|
+
output?: TOutput;
|
|
20
|
+
handler: (context: DefineApiRouteContext<TInput, TQuery, TBody, TParams>) => Promise<TResult> | TResult;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates an h3-compatible event handler with Standard Schema validation.
|
|
24
|
+
*
|
|
25
|
+
* - `input` schema validates the request body (POST/PUT/PATCH) or query
|
|
26
|
+
* params (GET). Returns 422 with `StandardSchemaV1.Issue[]` on failure.
|
|
27
|
+
* - `output` schema validates the response in development only (stripped
|
|
28
|
+
* in production for zero overhead). Logs a warning on mismatch.
|
|
29
|
+
* - Plain return values are serialized with `json(...)`; raw `Response`
|
|
30
|
+
* objects are returned unchanged.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { defineApiRoute } from '@analogjs/router/server/actions';
|
|
35
|
+
* import * as v from 'valibot';
|
|
36
|
+
*
|
|
37
|
+
* const Input = v.object({
|
|
38
|
+
* name: v.pipe(v.string(), v.minLength(1)),
|
|
39
|
+
* email: v.pipe(v.string(), v.email()),
|
|
40
|
+
* });
|
|
41
|
+
* const Output = v.object({
|
|
42
|
+
* id: v.string(),
|
|
43
|
+
* name: v.string(),
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* export default defineApiRoute({
|
|
47
|
+
* input: Input,
|
|
48
|
+
* output: Output,
|
|
49
|
+
* handler: async ({ data }) => {
|
|
50
|
+
* const user = await db.users.create(data);
|
|
51
|
+
* return user;
|
|
52
|
+
* },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export 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>;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import type { H3Event, H3EventContext } from 'nitro/h3';
|
|
3
|
+
import type { $Fetch } from 'nitro/types';
|
|
4
|
+
type NodeContext = NonNullable<H3Event['node']>;
|
|
5
|
+
type OptionalSchema = StandardSchemaV1 | undefined;
|
|
6
|
+
type InferSchema<TSchema extends OptionalSchema, TFallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
|
|
7
|
+
export interface PageLoadContext<TParamsSchema extends OptionalSchema = undefined, TQuerySchema extends OptionalSchema = undefined> {
|
|
8
|
+
params: InferSchema<TParamsSchema, H3EventContext['params']>;
|
|
9
|
+
query: InferSchema<TQuerySchema, Record<string, string | string[] | undefined>>;
|
|
10
|
+
req: NodeContext['req'];
|
|
11
|
+
res: NonNullable<NodeContext['res']>;
|
|
12
|
+
fetch: $Fetch;
|
|
13
|
+
event: H3Event;
|
|
14
|
+
}
|
|
15
|
+
export interface DefinePageLoadOptions<TParamsSchema extends OptionalSchema = undefined, TQuerySchema extends OptionalSchema = undefined, TResult = unknown> {
|
|
16
|
+
params?: TParamsSchema;
|
|
17
|
+
query?: TQuerySchema;
|
|
18
|
+
handler: (context: PageLoadContext<TParamsSchema, TQuerySchema>) => Promise<TResult> | TResult;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a typed page server load function with optional
|
|
22
|
+
* Standard Schema validation for route params and query.
|
|
23
|
+
*
|
|
24
|
+
* Follows the same validation patterns as `defineAction` and
|
|
25
|
+
* `defineServerRoute`: validates before invoking the handler,
|
|
26
|
+
* returns `fail(422, issues)` on validation failure.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // src/app/pages/users/[id].server.ts
|
|
31
|
+
* import { definePageLoad } from '@analogjs/router/server/actions';
|
|
32
|
+
* import * as v from 'valibot';
|
|
33
|
+
*
|
|
34
|
+
* export const routeParamsSchema = v.object({
|
|
35
|
+
* id: v.pipe(v.string(), v.regex(/^\d+$/)),
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* export const load = definePageLoad({
|
|
39
|
+
* params: routeParamsSchema,
|
|
40
|
+
* handler: async ({ params, fetch }) => {
|
|
41
|
+
* // params.id is typed as string (validated)
|
|
42
|
+
* const user = await fetch(`/api/users/${params.id}`);
|
|
43
|
+
* return user;
|
|
44
|
+
* },
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function definePageLoad<TParamsSchema extends OptionalSchema = undefined, TQuerySchema extends OptionalSchema = undefined, TResult = unknown>(options: DefinePageLoadOptions<TParamsSchema, TQuerySchema, TResult>): (ctx: {
|
|
49
|
+
params: H3EventContext['params'];
|
|
50
|
+
req: NodeContext['req'];
|
|
51
|
+
res: NonNullable<NodeContext['res']>;
|
|
52
|
+
fetch: $Fetch;
|
|
53
|
+
event: H3Event;
|
|
54
|
+
}) => Promise<TResult | Response>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import type { H3Event } from 'nitro/h3';
|
|
3
|
+
export type DefineServerRouteResult = Response | unknown;
|
|
4
|
+
export interface ServerRouteHandler<TQuery = unknown, TBody = unknown, TResult = unknown> {
|
|
5
|
+
(event: H3Event): Promise<Response>;
|
|
6
|
+
readonly _types: {
|
|
7
|
+
readonly query: TQuery;
|
|
8
|
+
readonly body: TBody;
|
|
9
|
+
readonly result: TResult;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export type InferRouteQuery<T> = T extends ServerRouteHandler<infer Q, any, any> ? Q : never;
|
|
13
|
+
export type InferRouteBody<T> = T extends ServerRouteHandler<any, infer B, any> ? B : never;
|
|
14
|
+
export type InferRouteResult<T> = T extends ServerRouteHandler<any, any, infer R> ? Exclude<R, Response> : never;
|
|
15
|
+
type OptionalSchema = StandardSchemaV1 | undefined;
|
|
16
|
+
type InferSchema<TSchema extends OptionalSchema, TFallback = unknown> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
|
|
17
|
+
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;
|
|
18
|
+
export interface DefineServerRouteContext<TInput extends StandardSchemaV1 | undefined = undefined, TQuery extends StandardSchemaV1 | undefined = undefined, TBody extends StandardSchemaV1 | undefined = undefined, TParams extends StandardSchemaV1 | undefined = undefined> {
|
|
19
|
+
data: ResolveDataSchema<TInput, TQuery, TBody>;
|
|
20
|
+
query: InferSchema<TQuery, undefined>;
|
|
21
|
+
body: InferSchema<TBody, undefined>;
|
|
22
|
+
params: InferSchema<TParams, H3Event['context']['params']>;
|
|
23
|
+
event: H3Event;
|
|
24
|
+
}
|
|
25
|
+
export 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> {
|
|
26
|
+
input?: TInput;
|
|
27
|
+
query?: TQuery;
|
|
28
|
+
body?: TBody;
|
|
29
|
+
params?: TParams;
|
|
30
|
+
output?: TOutput;
|
|
31
|
+
handler: (context: DefineServerRouteContext<TInput, TQuery, TBody, TParams>) => Promise<TResult> | TResult;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates an h3-compatible event handler with Standard Schema validation.
|
|
35
|
+
*
|
|
36
|
+
* - `input` schema validates the request body (POST/PUT/PATCH) or query
|
|
37
|
+
* params (GET). Returns 422 with `StandardSchemaV1.Issue[]` on failure.
|
|
38
|
+
* - `output` schema validates the response in development only (stripped
|
|
39
|
+
* in production for zero overhead). Logs a warning on mismatch.
|
|
40
|
+
* - Plain return values are serialized with `json(...)`; raw `Response`
|
|
41
|
+
* objects are returned unchanged.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { defineServerRoute } from '@analogjs/router/server/actions';
|
|
46
|
+
* import * as v from 'valibot';
|
|
47
|
+
*
|
|
48
|
+
* const Input = v.object({
|
|
49
|
+
* name: v.pipe(v.string(), v.minLength(1)),
|
|
50
|
+
* email: v.pipe(v.string(), v.email()),
|
|
51
|
+
* });
|
|
52
|
+
* const Output = v.object({
|
|
53
|
+
* id: v.string(),
|
|
54
|
+
* name: v.string(),
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* export default defineServerRoute({
|
|
58
|
+
* input: Input,
|
|
59
|
+
* output: Output,
|
|
60
|
+
* handler: async ({ data }) => {
|
|
61
|
+
* const user = await db.users.create(data);
|
|
62
|
+
* return user;
|
|
63
|
+
* },
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export 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<TQuery, undefined>, InferSchema<TBody, undefined>, TResult>;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { PageServerAction } from './actions';
|
|
2
|
+
export { json, redirect, fail } from './actions';
|
|
3
|
+
export { defineAction } from './define-action';
|
|
4
|
+
export type { DefineActionContext, DefineActionOptions } from './define-action';
|
|
5
|
+
export { defineServerRoute } from './define-server-route';
|
|
6
|
+
export type { DefineServerRouteContext, DefineServerRouteOptions, DefineServerRouteResult, ServerRouteHandler, InferRouteQuery, InferRouteBody, InferRouteResult, } from './define-server-route';
|
|
7
|
+
export { definePageLoad } from './define-page-load';
|
|
8
|
+
export type { PageLoadContext, DefinePageLoadOptions, } from './define-page-load';
|
|
9
|
+
export { validateWithSchema } from './validate';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type RequestEntryValue = string | File;
|
|
2
|
+
type ParsedRequestValue = RequestEntryValue | RequestEntryValue[];
|
|
3
|
+
export declare function parseSearchParams(searchParams: URLSearchParams): Record<string, ParsedRequestValue>;
|
|
4
|
+
export declare function parseFormData(formData: FormData): Record<string, ParsedRequestValue>;
|
|
5
|
+
export declare function parseRequestData(event: {
|
|
6
|
+
method: string;
|
|
7
|
+
headers: Headers;
|
|
8
|
+
}): Promise<unknown>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
/**
|
|
3
|
+
* Validates unknown input against a Standard Schema.
|
|
4
|
+
*
|
|
5
|
+
* Handles both sync and async `validate` implementations — the Standard
|
|
6
|
+
* Schema spec allows either return shape.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateWithSchema<T extends StandardSchemaV1>(schema: T, data: unknown): Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<T>>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { StaticProvider } from '@angular/core';
|
|
2
|
+
import { ServerInternalFetch, ServerRequest, ServerResponse } from '@analogjs/router/tokens';
|
|
3
|
+
export declare function provideServerContext({ req, res, fetch, }: {
|
|
4
|
+
req: ServerRequest;
|
|
5
|
+
res: ServerResponse;
|
|
6
|
+
fetch?: ServerInternalFetch;
|
|
7
|
+
}): StaticProvider[];
|
|
8
|
+
export declare function getBaseUrl(req: ServerRequest): string;
|
|
9
|
+
export declare function getRequestProtocol(req: ServerRequest, opts?: {
|
|
10
|
+
xForwardedProto?: boolean;
|
|
11
|
+
}): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ApplicationConfig, Provider, Type } from '@angular/core';
|
|
2
|
+
import type { ServerContext } from '@analogjs/router/tokens';
|
|
3
|
+
/**
|
|
4
|
+
* Returns a function that accepts the navigation URL,
|
|
5
|
+
* the root HTML, and server context.
|
|
6
|
+
*
|
|
7
|
+
* @param rootComponent
|
|
8
|
+
* @param config
|
|
9
|
+
* @param platformProviders
|
|
10
|
+
* @returns Promise<string | Reponse>
|
|
11
|
+
*/
|
|
12
|
+
export declare function render(rootComponent: Type<unknown>, config: ApplicationConfig, platformProviders?: Provider[]): (url: string, document: string, serverContext: ServerContext) => Promise<string | Response>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ApplicationConfig } from '@angular/core';
|
|
2
|
+
import { ServerContext } from '@analogjs/router/tokens';
|
|
3
|
+
export declare function serverComponentRequest(serverContext: ServerContext): string | undefined;
|
|
4
|
+
export declare function renderServerComponent(url: string, serverContext: ServerContext, config?: ApplicationConfig): Promise<Response>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InjectionToken, Provider } from '@angular/core';
|
|
2
|
+
export declare const STATIC_PROPS: InjectionToken<Record<string, any>>;
|
|
3
|
+
export declare function provideStaticProps<T = Record<string, any>>(props: T): Provider;
|
|
4
|
+
export declare function injectStaticProps(): Record<string, any>;
|
|
5
|
+
export declare function injectStaticOutputs<T>(): {
|
|
6
|
+
set(data: T): void;
|
|
7
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type { RouteExport } from './lib/models';
|
|
2
|
+
export type { Files } from './lib/route-files';
|
|
3
|
+
export { routes, createRoutes } from './lib/routes';
|
|
4
|
+
export { defineRouteMeta, injectActivatedRoute, injectRouter, } from './lib/define-route';
|
|
5
|
+
export type { RouteMeta } from './lib/models';
|
|
6
|
+
export { provideFileRouter, withExtraRoutes } from './lib/provide-file-router';
|
|
7
|
+
export type { MetaTag } from './lib/meta-tags';
|
|
8
|
+
export type { PageServerLoad, LoadResult, LoadDataResult, } from './lib/route-types';
|
|
9
|
+
export { injectLoad, injectLoadData } from './lib/inject-load';
|
|
10
|
+
export { getLoadResolver } from './lib/get-load-resolver';
|
|
11
|
+
export { requestContextInterceptor } from './lib/request-context';
|
|
12
|
+
export { injectRouteEndpointURL } from './lib/inject-route-endpoint-url';
|
|
13
|
+
export { FormAction } from './lib/form-action.directive';
|
|
14
|
+
export type { FormActionState } from './lib/form-action.directive';
|
|
15
|
+
export { injectDebugRoutes } from './lib/debug/routes';
|
|
16
|
+
export { withDebugRoutes } from './lib/debug';
|
|
17
|
+
export { ServerOnly } from './lib/server.component';
|
|
18
|
+
export type { AnalogJsonLdDocument } from './lib/json-ld';
|
|
19
|
+
export { issuesToFieldErrors, issuesToFormErrors, issuePathToFieldName, } from './lib/validation-errors';
|
|
20
|
+
export type { ValidationFieldErrors } from './lib/validation-errors';
|
|
21
|
+
export type { AnalogRouteTable, AnalogRoutePath, RoutePathOptions, RoutePathArgs, RoutePathOptionsBase, RouteParamsOutput, RouteQueryOutput, RouteLinkResult, } from './lib/route-path';
|
|
22
|
+
export { routePath } from './lib/route-path';
|
|
23
|
+
export { injectNavigate } from './lib/inject-navigate';
|
|
24
|
+
export { withTypedRouter, withRouteContext, withLoaderCaching, EXPERIMENTAL_TYPED_ROUTER, EXPERIMENTAL_ROUTE_CONTEXT, EXPERIMENTAL_LOADER_CACHE, } from './lib/experimental';
|
|
25
|
+
export type { TypedRouterOptions, LoaderCacheOptions, } from './lib/experimental';
|
|
26
|
+
export { injectParams, injectQuery } from './lib/inject-typed-params';
|
|
27
|
+
export { injectRouteContext } from './lib/inject-route-context';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { HttpHandlerFn, HttpRequest, HttpEvent } from '@angular/common/http';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { ServerRequest } from '@analogjs/router/tokens';
|
|
4
|
+
export declare function cookieInterceptor(req: HttpRequest<unknown>, next: HttpHandlerFn, location?: object, serverRequest?: ServerRequest | null): Observable<HttpEvent<unknown>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OnInit } from '@angular/core';
|
|
2
|
+
import { DebugRoute } from './routes';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
type CollectedRoute = {
|
|
5
|
+
path: string;
|
|
6
|
+
filename: string;
|
|
7
|
+
file: string;
|
|
8
|
+
isLayout: boolean;
|
|
9
|
+
source: 'page' | 'content';
|
|
10
|
+
};
|
|
11
|
+
export default class DebugRoutesComponent implements OnInit {
|
|
12
|
+
collectedRoutes: CollectedRoute[];
|
|
13
|
+
private debugRoutes;
|
|
14
|
+
private extraSources;
|
|
15
|
+
ngOnInit(): void;
|
|
16
|
+
traverseRoutes(routes: DebugRoute[], parent?: string, source?: 'page' | 'content'): void;
|
|
17
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DebugRoutesComponent, never>;
|
|
18
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<DebugRoutesComponent, "analogjs-debug-routes-page", never, {}, {}, never, never, true, never>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EnvironmentProviders, Provider } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* Provides routes that provide additional
|
|
4
|
+
* pages for displaying and debugging
|
|
5
|
+
* routes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function withDebugRoutes(): {
|
|
8
|
+
ɵkind: number;
|
|
9
|
+
ɵproviders: (Provider | EnvironmentProviders)[];
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { Route } from '@angular/router';
|
|
3
|
+
export declare const DEBUG_ROUTES: InjectionToken<(Route & DebugRoute)[]>;
|
|
4
|
+
export type DebugRoute = {
|
|
5
|
+
path: string;
|
|
6
|
+
filename: string;
|
|
7
|
+
isLayout: boolean;
|
|
8
|
+
children?: DebugRoute[];
|
|
9
|
+
};
|
|
10
|
+
export declare function injectDebugRoutes(): (Route & DebugRoute)[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Route as NgRoute, Router } from '@angular/router';
|
|
2
|
+
import { ActivatedRoute } from '@angular/router';
|
|
3
|
+
import { AnalogJsonLdDocument } from './json-ld';
|
|
4
|
+
import { MetaTag } from './meta-tags';
|
|
5
|
+
type RouteOmitted = 'component' | 'loadComponent' | 'loadChildren' | 'path' | 'pathMatch';
|
|
6
|
+
type RestrictedRoute = Omit<NgRoute, RouteOmitted> & {
|
|
7
|
+
meta?: MetaTag[];
|
|
8
|
+
jsonLd?: AnalogJsonLdDocument;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `RouteMeta` type instead.
|
|
12
|
+
* For more info see: https://github.com/analogjs/analog/issues/223
|
|
13
|
+
*
|
|
14
|
+
* Defines additional route config metadata. This
|
|
15
|
+
* object is merged into the route config with
|
|
16
|
+
* the predefined file-based route.
|
|
17
|
+
*
|
|
18
|
+
* @usageNotes
|
|
19
|
+
*
|
|
20
|
+
* ```
|
|
21
|
+
* import { Component } from '@angular/core';
|
|
22
|
+
* import { defineRouteMeta } from '@analogjs/router';
|
|
23
|
+
*
|
|
24
|
+
* export const routeMeta = defineRouteMeta({
|
|
25
|
+
* title: 'Welcome'
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* @Component({
|
|
29
|
+
* template: `Home`,
|
|
30
|
+
* standalone: true,
|
|
31
|
+
* })
|
|
32
|
+
* export default class HomeComponent {}
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param route
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export declare const defineRouteMeta: (route: RestrictedRoute) => RestrictedRoute;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the instance of Angular Router
|
|
41
|
+
*
|
|
42
|
+
* @returns The router
|
|
43
|
+
*/
|
|
44
|
+
export declare const injectRouter: () => Router;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the instance of the Activate Route for the component
|
|
47
|
+
*
|
|
48
|
+
* @returns The activated route
|
|
49
|
+
*/
|
|
50
|
+
export declare const injectActivatedRoute: () => ActivatedRoute;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import type { RouterFeatures } from '@angular/router';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for experimental typed router features.
|
|
5
|
+
*
|
|
6
|
+
* Inspired by TanStack Router's type-safe navigation system where
|
|
7
|
+
* routes are registered globally and all navigation/hooks are typed
|
|
8
|
+
* against the route tree.
|
|
9
|
+
*
|
|
10
|
+
* @experimental
|
|
11
|
+
*/
|
|
12
|
+
export interface TypedRouterOptions {
|
|
13
|
+
/**
|
|
14
|
+
* When true, logs warnings in development when navigating to
|
|
15
|
+
* routes with params that don't match the generated route table.
|
|
16
|
+
*
|
|
17
|
+
* Similar to TanStack Router's strict mode where `useParams()`
|
|
18
|
+
* without a `from` constraint returns a union of all possible params.
|
|
19
|
+
*
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
strictRouteParams?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for experimental loader caching.
|
|
26
|
+
*
|
|
27
|
+
* Inspired by TanStack Router's built-in data caching where route
|
|
28
|
+
* loaders automatically cache results and support stale-while-revalidate.
|
|
29
|
+
*
|
|
30
|
+
* @experimental
|
|
31
|
+
*/
|
|
32
|
+
export interface LoaderCacheOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Time in milliseconds before loader data is considered stale.
|
|
35
|
+
* While data is fresh, navigating back to the route uses cached
|
|
36
|
+
* data without re-invoking the server load function.
|
|
37
|
+
*
|
|
38
|
+
* Mirrors TanStack Router's `defaultStaleTime` option on `createRouter()`.
|
|
39
|
+
*
|
|
40
|
+
* @default 0 (always re-fetch)
|
|
41
|
+
*/
|
|
42
|
+
defaultStaleTime?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Time in milliseconds to retain unused loader data in cache
|
|
45
|
+
* after leaving a route. After this period the cached entry is
|
|
46
|
+
* garbage-collected.
|
|
47
|
+
*
|
|
48
|
+
* Mirrors TanStack Router's `defaultGcTime` (default 30 min).
|
|
49
|
+
*
|
|
50
|
+
* @default 300_000 (5 minutes)
|
|
51
|
+
*/
|
|
52
|
+
defaultGcTime?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Delay in milliseconds before showing a pending/loading indicator
|
|
55
|
+
* during route transitions. Prevents flash-of-loading-state for
|
|
56
|
+
* fast navigations.
|
|
57
|
+
*
|
|
58
|
+
* Mirrors TanStack Router's `defaultPendingMs`.
|
|
59
|
+
*
|
|
60
|
+
* @default 0 (show immediately)
|
|
61
|
+
*/
|
|
62
|
+
defaultPendingMs?: number;
|
|
63
|
+
}
|
|
64
|
+
/** @experimental */
|
|
65
|
+
export declare const EXPERIMENTAL_TYPED_ROUTER: InjectionToken<TypedRouterOptions>;
|
|
66
|
+
/** @experimental */
|
|
67
|
+
export declare const EXPERIMENTAL_ROUTE_CONTEXT: InjectionToken<Record<string, unknown>>;
|
|
68
|
+
/** @experimental */
|
|
69
|
+
export declare const EXPERIMENTAL_LOADER_CACHE: InjectionToken<LoaderCacheOptions>;
|
|
70
|
+
/**
|
|
71
|
+
* Enables experimental typed router features.
|
|
72
|
+
*
|
|
73
|
+
* When active, `routePath()`, `injectNavigate()`, `injectParams()`,
|
|
74
|
+
* and `injectQuery()` will enforce route table constraints and
|
|
75
|
+
* optionally log warnings in strict mode.
|
|
76
|
+
*
|
|
77
|
+
* Inspired by TanStack Router's `Register` interface and strict type
|
|
78
|
+
* checking across the entire navigation surface.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* provideFileRouter(
|
|
83
|
+
* withTypedRouter({ strictRouteParams: true }),
|
|
84
|
+
* )
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @experimental
|
|
88
|
+
*/
|
|
89
|
+
export declare function withTypedRouter(options?: TypedRouterOptions): RouterFeatures;
|
|
90
|
+
/**
|
|
91
|
+
* Provides root-level route context available to all route loaders
|
|
92
|
+
* and components via `injectRouteContext()`.
|
|
93
|
+
*
|
|
94
|
+
* Inspired by TanStack Router's `createRootRouteWithContext<T>()` where
|
|
95
|
+
* a typed context object is required at router creation and automatically
|
|
96
|
+
* available in every route's `beforeLoad` and `loader`.
|
|
97
|
+
*
|
|
98
|
+
* In Angular terms, this creates a DI token that server-side load
|
|
99
|
+
* functions and components can inject to access shared services
|
|
100
|
+
* without importing them individually.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* // app.config.ts
|
|
105
|
+
* provideFileRouter(
|
|
106
|
+
* withRouteContext({
|
|
107
|
+
* auth: inject(AuthService),
|
|
108
|
+
* db: inject(DatabaseService),
|
|
109
|
+
* }),
|
|
110
|
+
* )
|
|
111
|
+
*
|
|
112
|
+
* // In a component
|
|
113
|
+
* const ctx = injectRouteContext<{ auth: AuthService; db: DatabaseService }>();
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @experimental
|
|
117
|
+
*/
|
|
118
|
+
export declare function withRouteContext<T extends Record<string, unknown>>(context: T): RouterFeatures;
|
|
119
|
+
/**
|
|
120
|
+
* Configures experimental loader caching behavior for server-loaded
|
|
121
|
+
* route data.
|
|
122
|
+
*
|
|
123
|
+
* Inspired by TanStack Router's built-in cache where `createRouter()`
|
|
124
|
+
* accepts `defaultStaleTime` and `defaultGcTime` to control when
|
|
125
|
+
* loaders re-execute and when cached data is discarded.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* provideFileRouter(
|
|
130
|
+
* withLoaderCaching({
|
|
131
|
+
* defaultStaleTime: 30_000, // 30s before re-fetch
|
|
132
|
+
* defaultGcTime: 300_000, // 5min cache retention
|
|
133
|
+
* defaultPendingMs: 200, // 200ms loading delay
|
|
134
|
+
* }),
|
|
135
|
+
* )
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @experimental
|
|
139
|
+
*/
|
|
140
|
+
export declare function withLoaderCaching(options?: LoaderCacheOptions): RouterFeatures;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type InputSignal, type OutputEmitterRef, type WritableSignal } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
export type FormActionState = 'submitting' | 'error' | 'redirect' | 'success' | 'navigate';
|
|
4
|
+
export declare class FormAction {
|
|
5
|
+
action: InputSignal<string>;
|
|
6
|
+
onSuccess: OutputEmitterRef<unknown>;
|
|
7
|
+
onError: OutputEmitterRef<unknown>;
|
|
8
|
+
state: OutputEmitterRef<FormActionState>;
|
|
9
|
+
private router;
|
|
10
|
+
private route;
|
|
11
|
+
protected currentState: WritableSignal<FormActionState | 'idle'>;
|
|
12
|
+
/** Cached during construction (injection context) so inject() works. */
|
|
13
|
+
private _endpointUrl;
|
|
14
|
+
submitted($event: SubmitEvent): void;
|
|
15
|
+
private _handleGet;
|
|
16
|
+
private _handlePost;
|
|
17
|
+
private _getExplicitAction;
|
|
18
|
+
private _getGetPath;
|
|
19
|
+
private _getPostPath;
|
|
20
|
+
private _emitState;
|
|
21
|
+
private _navigateTo;
|
|
22
|
+
private _isJSON;
|
|
23
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FormAction, never>;
|
|
24
|
+
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>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ActivatedRouteSnapshot } from '@angular/router';
|
|
2
|
+
/**
|
|
3
|
+
* Get server load resolver data for the route
|
|
4
|
+
*
|
|
5
|
+
* @param route Provides the route to get server load resolver
|
|
6
|
+
* @returns Returns server load resolver data for the route
|
|
7
|
+
*/
|
|
8
|
+
export declare function getLoadResolver<T>(route: ActivatedRouteSnapshot): Promise<T>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Injector } from '@angular/core';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { LoadDataResult, PageServerLoad } from './route-types';
|
|
4
|
+
export declare function injectLoad<T extends (pageServerLoad: PageServerLoad) => Promise<unknown>>(options?: {
|
|
5
|
+
injector?: Injector;
|
|
6
|
+
}): Observable<Awaited<ReturnType<T>>>;
|
|
7
|
+
export declare function injectLoadData<T extends (pageServerLoad: PageServerLoad) => Promise<unknown>>(options?: {
|
|
8
|
+
injector?: Injector;
|
|
9
|
+
}): Observable<LoadDataResult<T>>;
|