1 | import { VersioningType } from '../enums/version-type.enum';
|
2 | /**
|
3 | * Indicates that this will work for any version passed in the request, or no version.
|
4 | *
|
5 | * @publicApi
|
6 | */
|
7 | export declare const VERSION_NEUTRAL: unique symbol;
|
8 | /**
|
9 | * @publicApi
|
10 | */
|
11 | export type VersionValue = string | typeof VERSION_NEUTRAL | Array<string | typeof VERSION_NEUTRAL>;
|
12 | /**
|
13 | * @publicApi
|
14 | */
|
15 | export interface VersionOptions {
|
16 | /**
|
17 | * Specifies an optional API Version. When configured, methods
|
18 | * within the controller will only be routed if the request version
|
19 | * matches the specified value.
|
20 | *
|
21 | * Supported only by HTTP-based applications (does not apply to non-HTTP microservices).
|
22 | *
|
23 | * @see [Versioning](https://docs.nestjs.com/techniques/versioning)
|
24 | */
|
25 | version?: VersionValue;
|
26 | }
|
27 | /**
|
28 | * @publicApi
|
29 | */
|
30 | export interface HeaderVersioningOptions {
|
31 | type: VersioningType.HEADER;
|
32 | /**
|
33 | * The name of the Request Header that contains the version.
|
34 | */
|
35 | header: string;
|
36 | }
|
37 | /**
|
38 | * @publicApi
|
39 | */
|
40 | export interface UriVersioningOptions {
|
41 | type: VersioningType.URI;
|
42 | /**
|
43 | * Optional prefix that will prepend the version within the URI.
|
44 | *
|
45 | * Defaults to `v`.
|
46 | *
|
47 | * Ex. Assuming a version of `1`, for `/api/v1/route`, `v` is the prefix.
|
48 | */
|
49 | prefix?: string | false;
|
50 | }
|
51 | /**
|
52 | * @publicApi
|
53 | */
|
54 | export interface MediaTypeVersioningOptions {
|
55 | type: VersioningType.MEDIA_TYPE;
|
56 | /**
|
57 | * The key within the Media Type Header to determine the version from.
|
58 | *
|
59 | * Ex. For `application/json;v=1`, the key is `v=`.
|
60 | */
|
61 | key: string;
|
62 | }
|
63 | /**
|
64 | * @publicApi
|
65 | */
|
66 | export interface CustomVersioningOptions {
|
67 | type: VersioningType.CUSTOM;
|
68 | /**
|
69 | * A function that accepts a request object (specific to the underlying platform, ie Express or Fastify)
|
70 | * and returns a single version value or an ordered array of versions, in order from HIGHEST to LOWEST.
|
71 | *
|
72 | * Ex. Returned version array = ['3.1', '3.0', '2.5', '2', '1.9']
|
73 | *
|
74 | * Use type assertion or narrowing to identify the specific request type.
|
75 | */
|
76 | extractor: (request: unknown) => string | string[];
|
77 | }
|
78 | /**
|
79 | * @publicApi
|
80 | */
|
81 | interface VersioningCommonOptions {
|
82 | /**
|
83 | * The default version to be used as a fallback when you did not provide some
|
84 | * version to `@Controller()` nor `@Version()`.
|
85 | */
|
86 | defaultVersion?: VersionOptions['version'];
|
87 | }
|
88 | /**
|
89 | * @publicApi
|
90 | */
|
91 | export type VersioningOptions = VersioningCommonOptions & (HeaderVersioningOptions | UriVersioningOptions | MediaTypeVersioningOptions | CustomVersioningOptions);
|
92 | export {};
|