@analogjs/router 3.0.0-alpha.96 → 3.0.0-alpha.98
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 +4 -97
- package/fesm2022/analogjs-router-server-actions.mjs.map +1 -1
- package/fesm2022/analogjs-router-tanstack-query.mjs.map +1 -1
- package/fesm2022/analogjs-router.mjs +103 -146
- package/fesm2022/analogjs-router.mjs.map +1 -1
- package/fesm2022/route-files.mjs +2 -2
- package/fesm2022/route-files.mjs.map +1 -1
- package/fesm2022/routes.mjs +1 -2
- package/fesm2022/routes.mjs.map +1 -1
- package/migrations/migrate-deprecated-router-apis/migrate-deprecated-router-apis.js +183 -0
- package/migrations/migrate-deprecated-router-apis/migrate-deprecated-router-apis.js.map +1 -0
- package/migrations/migration.json +12 -1
- package/migrations/remove-request-context-interceptor/remove-request-context-interceptor.js +122 -0
- package/migrations/remove-request-context-interceptor/remove-request-context-interceptor.js.map +1 -0
- package/package.json +4 -4
- package/types/migrations/migrate-deprecated-router-apis/migrate-deprecated-router-apis.d.ts +11 -0
- package/types/migrations/remove-request-context-interceptor/remove-request-context-interceptor.d.ts +2 -0
- package/types/migrations/utils/source-edits.d.ts +9 -0
- package/types/server/actions/src/define-api-route.d.ts +12 -1
- package/types/server/actions/src/define-page-load.d.ts +1 -1
- package/types/server/actions/src/index.d.ts +1 -3
- package/types/src/index.d.ts +1 -2
- package/types/src/lib/form-action.directive.d.ts +1 -0
- package/types/src/lib/models.d.ts +1 -2
- package/types/src/lib/routes.d.ts +1 -2
- package/types/tanstack-query/src/server-query.d.ts +4 -4
- package/types/server/actions/src/define-server-route.d.ts +0 -68
- package/types/src/lib/define-route.d.ts +0 -51
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from './standard-schema';
|
|
2
2
|
import type { H3Event } from 'h3';
|
|
3
3
|
export type DefineApiRouteResult = Response | unknown;
|
|
4
|
+
export interface ApiRouteHandler<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 ApiRouteHandler<infer Q, any, any> ? Q : never;
|
|
13
|
+
export type InferRouteBody<T> = T extends ApiRouteHandler<any, infer B, any> ? B : never;
|
|
14
|
+
export type InferRouteResult<T> = T extends ApiRouteHandler<any, any, infer R> ? Exclude<R, Response> : never;
|
|
4
15
|
type OptionalSchema = StandardSchemaV1 | undefined;
|
|
5
16
|
type InferSchema<TSchema extends OptionalSchema, TFallback = unknown> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
|
|
6
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;
|
|
@@ -52,5 +63,5 @@ export interface DefineApiRouteOptions<TInput extends StandardSchemaV1 | undefin
|
|
|
52
63
|
* });
|
|
53
64
|
* ```
|
|
54
65
|
*/
|
|
55
|
-
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>):
|
|
66
|
+
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>): ApiRouteHandler<InferSchema<TQuery, undefined>, InferSchema<TBody, undefined>, TResult>;
|
|
56
67
|
export {};
|
|
@@ -20,7 +20,7 @@ export interface DefinePageLoadOptions<TParamsSchema extends OptionalSchema = un
|
|
|
20
20
|
* Creates a typed page server load function with optional
|
|
21
21
|
* Standard Schema validation for route params and query.
|
|
22
22
|
*
|
|
23
|
-
* Follows the same validation pattern as `
|
|
23
|
+
* Follows the same validation pattern as `defineApiRoute`:
|
|
24
24
|
* validates before invoking the handler and returns
|
|
25
25
|
* `fail(422, issues)` on validation failure.
|
|
26
26
|
*
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export type { PageServerAction } from './actions';
|
|
2
2
|
export { json, redirect, fail } from './actions';
|
|
3
|
-
export { defineServerRoute } from './define-server-route';
|
|
4
|
-
export type { DefineServerRouteContext, DefineServerRouteOptions, DefineServerRouteResult, ServerRouteHandler, InferRouteQuery, InferRouteBody, InferRouteResult, } from './define-server-route';
|
|
5
3
|
export { definePageLoad } from './define-page-load';
|
|
6
4
|
export type { PageLoadContext, DefinePageLoadOptions, } from './define-page-load';
|
|
7
5
|
export { validateWithSchema } from './validate';
|
|
8
6
|
export type { StandardSchemaV1 } from './standard-schema';
|
|
9
7
|
export { defineAction, type DefineActionContext, type DefineActionOptions, } from './define-action';
|
|
10
|
-
export { defineApiRoute, type DefineApiRouteContext, type DefineApiRouteOptions, type DefineApiRouteResult, } from './define-api-route';
|
|
8
|
+
export { defineApiRoute, type DefineApiRouteContext, type DefineApiRouteOptions, type DefineApiRouteResult, type ApiRouteHandler, type InferRouteQuery, type InferRouteBody, type InferRouteResult, } from './define-api-route';
|
package/types/src/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export type { RouteExport } from './lib/models';
|
|
2
2
|
export type { Files } from './lib/route-files';
|
|
3
|
-
export {
|
|
4
|
-
export { defineRouteMeta, injectActivatedRoute, injectRouter, } from './lib/define-route';
|
|
3
|
+
export { createRoutes } from './lib/routes';
|
|
5
4
|
export type { RouteMeta } from './lib/models';
|
|
6
5
|
export { provideFileRouter, withExtraRoutes } from './lib/provide-file-router';
|
|
7
6
|
export type { MetaTag } from './lib/meta-tags';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Type } from '@angular/core';
|
|
2
2
|
import { CanActivateChildFn, CanActivateFn, CanDeactivateFn, CanMatchFn, DeprecatedGuard, ResolveFn, Route } from '@angular/router';
|
|
3
|
-
import { defineRouteMeta } from './define-route';
|
|
4
3
|
import { AnalogJsonLdDocument } from './json-ld';
|
|
5
4
|
import { MetaTag } from './meta-tags';
|
|
6
5
|
type OmittedRouteProps = 'path' | 'matcher' | 'component' | 'loadComponent' | 'children' | 'loadChildren' | 'canLoad' | 'outlet';
|
|
@@ -26,7 +25,7 @@ export type RouteMeta = (DefaultRouteMeta & {
|
|
|
26
25
|
}) | RedirectRouteMeta;
|
|
27
26
|
export type RouteExport = {
|
|
28
27
|
default: Type<unknown>;
|
|
29
|
-
routeMeta?: RouteMeta
|
|
28
|
+
routeMeta?: RouteMeta;
|
|
30
29
|
routeJsonLd?: AnalogJsonLdDocument | ResolveFn<AnalogJsonLdDocument | undefined>;
|
|
31
30
|
};
|
|
32
31
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Route } from '@angular/router';
|
|
2
|
-
import {
|
|
2
|
+
import type { Files } from './route-files';
|
|
3
3
|
/**
|
|
4
4
|
* A function used to parse list of files and create configuration of routes.
|
|
5
5
|
*
|
|
@@ -8,4 +8,3 @@ import { type Files } from './route-files';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function createRoutes(files: Files, debug?: boolean): Route[];
|
|
10
10
|
export { ANALOG_ROUTE_FILES } from './route-files';
|
|
11
|
-
export declare const routes: Route[];
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { HttpClient } from '@angular/common/http';
|
|
2
2
|
import type { CreateQueryOptions, CreateMutationOptions, CreateInfiniteQueryOptions, DefaultError, InfiniteData, QueryKey } from '@tanstack/angular-query-experimental';
|
|
3
|
-
import type {
|
|
4
|
-
export declare function serverQueryOptions<TRoute extends
|
|
3
|
+
import type { ApiRouteHandler, InferRouteQuery, InferRouteBody, InferRouteResult } from '@analogjs/router/server/actions';
|
|
4
|
+
export declare function serverQueryOptions<TRoute extends ApiRouteHandler<any, any, any>, TError = DefaultError, TData = InferRouteResult<TRoute>, TQueryKey extends QueryKey = QueryKey>(http: HttpClient, url: string, options: {
|
|
5
5
|
queryKey: TQueryKey;
|
|
6
6
|
query?: InferRouteQuery<TRoute>;
|
|
7
7
|
} & Omit<CreateQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey>, 'queryKey' | 'queryFn'>): CreateQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey>;
|
|
8
|
-
export declare function serverMutationOptions<TRoute extends
|
|
9
|
-
export declare function serverInfiniteQueryOptions<TRoute extends
|
|
8
|
+
export declare function serverMutationOptions<TRoute extends ApiRouteHandler<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 ApiRouteHandler<any, any, any>, TError = DefaultError, TData = InfiniteData<InferRouteResult<TRoute>>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(http: HttpClient, url: string, options: {
|
|
10
10
|
queryKey: TQueryKey;
|
|
11
11
|
query: (context: {
|
|
12
12
|
pageParam: TPageParam;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from './standard-schema';
|
|
2
|
-
import type { H3Event } from '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 {};
|
|
@@ -1,51 +0,0 @@
|
|
|
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 {};
|