@spfn/core 0.1.0-alpha.54 → 0.1.0-alpha.55

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.
@@ -22,7 +22,10 @@ async function scanContracts(routesDir) {
22
22
  contractImportPath: getImportPathFromRoutes(filePath, routesDir),
23
23
  routeFile: "",
24
24
  // Not needed anymore
25
- contractFile: filePath
25
+ contractFile: filePath,
26
+ hasQuery: contractExport.hasQuery,
27
+ hasBody: contractExport.hasBody,
28
+ hasParams: contractExport.hasParams
26
29
  });
27
30
  }
28
31
  }
@@ -78,7 +81,10 @@ function extractContractExports(filePath) {
78
81
  exports.push({
79
82
  name,
80
83
  method: contractData.method,
81
- path: contractData.path
84
+ path: contractData.path,
85
+ hasQuery: contractData.hasQuery,
86
+ hasBody: contractData.hasBody,
87
+ hasParams: contractData.hasParams
82
88
  });
83
89
  }
84
90
  }
@@ -113,6 +119,12 @@ function extractContractData(objectLiteral) {
113
119
  value = prop.initializer.expression.text;
114
120
  }
115
121
  if (value) result.path = value;
122
+ } else if (propName === "query") {
123
+ result.hasQuery = true;
124
+ } else if (propName === "body") {
125
+ result.hasBody = true;
126
+ } else if (propName === "params") {
127
+ result.hasParams = true;
116
128
  }
117
129
  }
118
130
  }
@@ -338,8 +350,9 @@ export const api = {
338
350
  function generateMethodCode(mapping, options) {
339
351
  const methodName = generateMethodName(mapping);
340
352
  const contractType = `typeof ${mapping.contractName}`;
341
- const hasParams = mapping.path.includes(":");
342
- const hasBody = ["POST", "PUT", "PATCH"].indexOf(mapping.method) !== -1;
353
+ const hasParams = mapping.hasParams || mapping.path.includes(":");
354
+ const hasQuery = mapping.hasQuery || false;
355
+ const hasBody = mapping.hasBody || false;
343
356
  let code = "";
344
357
  {
345
358
  code += ` /**
@@ -354,6 +367,9 @@ function generateMethodCode(mapping, options) {
354
367
  if (hasParams) {
355
368
  params.push(`params: InferContract<${contractType}>['params']`);
356
369
  }
370
+ if (hasQuery) {
371
+ params.push(`query?: InferContract<${contractType}>['query']`);
372
+ }
357
373
  if (hasBody) {
358
374
  params.push(`body: InferContract<${contractType}>['body']`);
359
375
  }