@midwayjs/core 4.0.0-beta.2 → 4.0.0-beta.4

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/README.md CHANGED
@@ -9,4 +9,4 @@ Document: [https://midwayjs.org](https://midwayjs.org)
9
9
 
10
10
  ## License
11
11
 
12
- [MIT]((https://github.com/midwayjs/midway/blob/master/LICENSE))
12
+ [MIT](https://github.com/midwayjs/midway/blob/master/LICENSE)
@@ -8,6 +8,9 @@ export interface ControllerOption {
8
8
  description?: string;
9
9
  tagName?: string;
10
10
  ignoreGlobalPrefix?: boolean;
11
+ version?: string | string[];
12
+ versionType?: 'URI' | 'HEADER' | 'MEDIA_TYPE' | 'CUSTOM';
13
+ versionPrefix?: string;
11
14
  };
12
15
  }
13
16
  export declare function Controller(prefix?: string, routerOptions?: {
@@ -16,5 +19,8 @@ export declare function Controller(prefix?: string, routerOptions?: {
16
19
  description?: string;
17
20
  tagName?: string;
18
21
  ignoreGlobalPrefix?: boolean;
22
+ version?: string | string[];
23
+ versionType?: 'URI' | 'HEADER' | 'MEDIA_TYPE' | 'CUSTOM';
24
+ versionPrefix?: string;
19
25
  }): ClassDecorator;
20
26
  //# sourceMappingURL=controller.d.ts.map
@@ -92,6 +92,18 @@ export interface RouterInfo {
92
92
  * url after wildcard and can be path-to-regexp by path-to-regexp v6
93
93
  */
94
94
  fullUrlFlattenString?: string;
95
+ /**
96
+ * version information for API versioning
97
+ */
98
+ version?: string | string[];
99
+ /**
100
+ * version type for API versioning
101
+ */
102
+ versionType?: 'URI' | 'HEADER' | 'MEDIA_TYPE' | 'CUSTOM';
103
+ /**
104
+ * version prefix for URI versioning
105
+ */
106
+ versionPrefix?: string;
95
107
  }
96
108
  export type DynamicRouterInfo = Omit<RouterInfo, 'id' | 'method' | 'controllerId' | 'controllerMiddleware' | 'responseMetadata'>;
97
109
  export interface RouterPriority {
@@ -232,6 +244,18 @@ export declare class MidwayWebRouterService {
232
244
  * url after wildcard and can be path-to-regexp by path-to-regexp v6
233
245
  */
234
246
  fullUrlFlattenString?: string;
247
+ /**
248
+ * version information for API versioning
249
+ */
250
+ version?: string | string[];
251
+ /**
252
+ * version type for API versioning
253
+ */
254
+ versionType?: "URI" | "HEADER" | "MEDIA_TYPE" | "CUSTOM";
255
+ /**
256
+ * version prefix for URI versioning
257
+ */
258
+ versionPrefix?: string;
235
259
  }[];
236
260
  getRoutePriorityList(): Promise<RouterPriority[]>;
237
261
  getRouterTable(): Promise<Map<string, RouterInfo[]>>;
@@ -81,6 +81,22 @@ let MidwayWebRouterService = class MidwayWebRouterService {
81
81
  if (controllerIgnoreGlobalPrefix) {
82
82
  prefix = ignorePrefix;
83
83
  }
84
+ // Apply version prefix for URI versioning
85
+ if (controllerOption.routerOptions?.version &&
86
+ (!controllerOption.routerOptions?.versionType ||
87
+ controllerOption.routerOptions?.versionType === 'URI')) {
88
+ const versionPrefix = controllerOption.routerOptions?.versionPrefix || 'v';
89
+ const version = Array.isArray(controllerOption.routerOptions.version)
90
+ ? controllerOption.routerOptions.version[0]
91
+ : controllerOption.routerOptions.version;
92
+ const versionedPrefix = `/${versionPrefix}${version}`;
93
+ if (controllerIgnoreGlobalPrefix) {
94
+ prefix = (0, util_1.joinURLPath)(versionedPrefix, ignorePrefix);
95
+ }
96
+ else {
97
+ prefix = (0, util_1.joinURLPath)(this.options.globalPrefix, versionedPrefix, controllerOption.prefix || '/');
98
+ }
99
+ }
84
100
  if (/\*/.test(prefix)) {
85
101
  throw new error_1.MidwayCommonError(`Router prefix ${prefix} can't set string with *`);
86
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "4.0.0-beta.2",
3
+ "version": "4.0.0-beta.4",
4
4
  "description": "midway core",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -61,5 +61,5 @@
61
61
  "types": "./dist/functional/index.d.ts"
62
62
  }
63
63
  },
64
- "gitHead": "53bfef4c5279da5f09025e4610bdbf64f94f60bd"
64
+ "gitHead": "64b0cc5d7f67134b1bc75959233e9048e796f8b2"
65
65
  }