@deepkit/http 1.0.1-alpha.129 → 1.0.1-alpha.131

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.
@@ -170,22 +170,28 @@ function isTypeUnknown(type: Type): boolean {
170
170
  || type.kind === ReflectionKind.never;
171
171
  }
172
172
 
173
- export function buildRequestParser(parseOptions: HttpParserOptions, parameters: ReflectionParameter[], path?: string): (request: HttpRequest) => any[] {
173
+ export function buildRequestParser(parseOptions: HttpParserOptions, parameters: ReflectionParameter[], routeConfig?: RouteConfig): (request: HttpRequest) => any[] {
174
174
  const compiler = new CompilerContext();
175
175
  const params = parameters.map(v => new ParameterForRequestParser(v));
176
176
 
177
177
  //todo: parse path
178
178
  let pathRegex = '';
179
- if (path) {
180
- const parsedPath = parseRoutePathToRegex(path, parameters);
179
+ let pathParameterNames: { [name: string]: number } = {};
180
+
181
+ if (routeConfig) {
182
+ const parsedPath = parseRoutePathToRegex(routeConfig.getFullPath(), parameters);
181
183
  pathRegex = parsedPath.regex;
184
+ pathParameterNames = parsedPath.parameterNames;
182
185
 
183
186
  for (const param of params) {
184
187
  param.regexPosition = parsedPath.parameterNames[param.parameter.name];
185
188
  }
186
189
  }
187
190
 
188
- const code = getRequestParserCodeForParameters(compiler, parseOptions, params, {});
191
+ const code = getRequestParserCodeForParameters(compiler, parseOptions, params, {
192
+ pathParameterNames,
193
+ routeConfig
194
+ });
189
195
  compiler.context.set('ValidationError', ValidationError);
190
196
  compiler.context.set('qs', qs);
191
197
 
@@ -245,8 +251,17 @@ export function getRequestParserCodeForParameters(
245
251
  if (parameter.requestParser) {
246
252
  const parseOptionsVar = compiler.reserveVariable('parseOptions', parseOptions);
247
253
  const parseBodyVar = compiler.reserveVariable('parseBody', parseBody);
254
+
255
+ let assignPathNames: string[] = [];
256
+ for (const [name, index] of Object.entries(config.pathParameterNames || {})) {
257
+ assignPathNames.push(`res.${name} = _match[${1 + index}];`);
258
+ }
259
+
248
260
  setParameters.push(`parameters.${parameter.parameter.name} = async (options = {}) => {
249
- let res = options.withPath !== false ? Object.assign({}, parameters) : {};
261
+ let res = {};
262
+ if (options.withPath !== false) {
263
+ ${assignPathNames.join('\n')}
264
+ }
250
265
  if (options.withHeader !== false) {
251
266
  Object.assign(res, _headers);
252
267
  }
package/src/router.ts CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  serializer,
19
19
  Serializer,
20
20
  Type,
21
- ValidationError
21
+ ValidationError,
22
22
  } from '@deepkit/type';
23
23
  import { getActions, HttpAction, httpClass, HttpController, HttpDecorator } from './decorator.js';
24
24
  import { HttpRequest, HttpRequestPositionedParameters, HttpRequestQuery, HttpRequestResolvedParameters } from './model.js';
@@ -169,7 +169,7 @@ export class RouteConfig {
169
169
  }
170
170
  }
171
171
 
172
- class ParsedRoute {
172
+ export class ParsedRoute {
173
173
  public regex?: string;
174
174
 
175
175
  public pathParameterNames: { [name: string]: number } = {};