UNPKG

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