Repository: RobinTail/express-zod-api
Pull request #983 (2023-05-06 12:26:01)

Add missing `async` keyword to `ExpressZodAPIClient::provide()`
Related to https://github.com/RobinTail/express-zod-api/discussions/931#discussioncomment-5601197

ESLint notice on missing `async`


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a7bf28d3..287fc85e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
 
 ## Version 10
 
+### v10.8.1
+
+- Add missing `async` keyword to `ExpressZodAPIClient::provide()` method.
+
 ### v10.8.0
 
 - Supporting Node 20.
diff --git a/example/example.client.ts b/example/example.client.ts
index 740fe778..d17e43ab 100644
--- a/example/example.client.ts
+++ b/example/example.client.ts
@@ -153,7 +153,7 @@ client.provide("get", "/v1/user/retrieve", { id: "10" });
 */
 export class ExpressZodAPIClient {
   constructor(protected readonly implementation: Implementation) {}
-  public readonly provide: Provider = (method, path, params) =>
+  public readonly provide: Provider = async (method, path, params) =>
     this.implementation(
       method,
       Object.keys(params).reduce(
diff --git a/src/client-helpers.ts b/src/client-helpers.ts
index b50149a7..0bcb12bf 100644
--- a/src/client-helpers.ts
+++ b/src/client-helpers.ts
@@ -4,6 +4,8 @@ export const f = ts.factory;
 
 export const exportModifier = [f.createModifier(ts.SyntaxKind.ExportKeyword)];
 
+const asyncModifier = [f.createModifier(ts.SyntaxKind.AsyncKeyword)];
+
 const publicReadonlyModifier = [
   f.createModifier(ts.SyntaxKind.PublicKeyword),
   f.createModifier(ts.SyntaxKind.ReadonlyKeyword),
@@ -156,7 +158,7 @@ export const makeImplementationCallFn = (
   args: ts.Expression[]
 ) =>
   f.createArrowFunction(
-    undefined,
+    asyncModifier,
     undefined,
     params.map((key) => makeParam(key)),
     undefined,


Test patch:
diff --git a/tests/unit/__snapshots__/integration.spec.ts.snap b/tests/unit/__snapshots__/integration.spec.ts.snap
index 69d7445c..87908ac9 100644
--- a/tests/unit/__snapshots__/integration.spec.ts.snap
+++ b/tests/unit/__snapshots__/integration.spec.ts.snap
@@ -61,7 +61,7 @@ client.provide("get", "/v1/user/retrieve", { id: "10" });
 */
 export class ExpressZodAPIClient {
     constructor(protected readonly implementation: Implementation) { }
-    public readonly provide: Provider = (method, path, params) => this.implementation(method, Object.keys(params).reduce((acc, key) => acc.replace(\`:\${key}\`, params[key]), path), Object.keys(params).reduce((acc, key) => path.indexOf(\`:\${key}\`) >= 0 ? acc : { ...acc, [key]: params[key] }, {}));
+    public readonly provide: Provider = async (method, path, params) => this.implementation(method, Object.keys(params).reduce((acc, key) => acc.replace(\`:\${key}\`, params[key]), path), Object.keys(params).reduce((acc, key) => path.indexOf(\`:\${key}\`) >= 0 ? acc : { ...acc, [key]: params[key] }, {}));
 }"
 `;
 
@@ -126,7 +126,7 @@ client.provide("get", "/v1/user/retrieve", { id: "10" });
 */
 export class ExpressZodAPIClient {
     constructor(protected readonly implementation: Implementation) { }
-    public readonly provide: Provider = (method, path, params) => this.implementation(method, Object.keys(params).reduce((acc, key) => acc.replace(\`:\${key}\`, params[key]), path), Object.keys(params).reduce((acc, key) => path.indexOf(\`:\${key}\`) >= 0 ? acc : { ...acc, [key]: params[key] }, {}));
+    public readonly provide: Provider = async (method, path, params) => this.implementation(method, Object.keys(params).reduce((acc, key) => acc.replace(\`:\${key}\`, params[key]), path), Object.keys(params).reduce((acc, key) => path.indexOf(\`:\${key}\`) >= 0 ? acc : { ...acc, [key]: params[key] }, {}));
 }"
 `;
 
@@ -191,7 +191,7 @@ client.provide("get", "/v1/user/retrieve", { id: "10" });
 */
 export class ExpressZodAPIClient {
     constructor(protected readonly implementation: Implementation) { }
-    public readonly provide: Provider = (method, path, params) => this.implementation(method, Object.keys(params).reduce((acc, key) => acc.replace(\`:\${key}\`, params[key]), path), Object.keys(params).reduce((acc, key) => path.indexOf(\`:\${key}\`) >= 0 ? acc : { ...acc, [key]: params[key] }, {}));
+    public readonly provide: Provider = async (method, path, params) => this.implementation(method, Object.keys(params).reduce((acc, key) => acc.replace(\`:\${key}\`, params[key]), path), Object.keys(params).reduce((acc, key) => path.indexOf(\`:\${key}\`) >= 0 ? acc : { ...acc, [key]: params[key] }, {}));
 }"
 `;
 
@@ -328,7 +328,7 @@ client.provide("get", "/v1/user/retrieve", { id: "10" });
 */
 export class ExpressZodAPIClient {
     constructor(protected readonly implementation: Implementation) { }
-    public readonly provide: Provider = (method, path, params) => this.implementation(method, Object.keys(params).reduce((acc, key) => acc.replace(\`:\${key}\`, params[key]), path), Object.keys(params).reduce((acc, key) => path.indexOf(\`:\${key}\`) >= 0 ? acc : { ...acc, [key]: params[key] }, {}));
+    public readonly provide: Provider = async (method, path, params) => this.implementation(method, Object.keys(params).reduce((acc, key) => acc.replace(\`:\${key}\`, params[key]), path), Object.keys(params).reduce((acc, key) => path.indexOf(\`:\${key}\`) >= 0 ? acc : { ...acc, [key]: params[key] }, {}));
 }"
 `;
 
@@ -497,6 +497,6 @@ client.provide("get", "/v1/user/retrieve", { id: "10" });
 */
 export class ExpressZodAPIClient {
     constructor(protected readonly implementation: Implementation) { }
-    public readonly provide: Provider = (method, path, params) => this.implementation(method, Object.keys(params).reduce((acc, key) => acc.replace(\`:\${key}\`, params[key]), path), Object.keys(params).reduce((acc, key) => path.indexOf(\`:\${key}\`) >= 0 ? acc : { ...acc, [key]: params[key] }, {}));
+    public readonly provide: Provider = async (method, path, params) => this.implementation(method, Object.keys(params).reduce((acc, key) => acc.replace(\`:\${key}\`, params[key]), path), Object.keys(params).reduce((acc, key) => path.indexOf(\`:\${key}\`) >= 0 ? acc : { ...acc, [key]: params[key] }, {}));
 }"
 `;