express-zod-api 5.1.0-beta2 → 5.1.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Version 5
4
4
 
5
+ ### v5.1.0
6
+
7
+ - No changes.
8
+
5
9
  ### v5.1.0-beta2
6
10
 
7
11
  - Fixing a warning message when using `testEndpoint()` method.
package/README.md CHANGED
@@ -39,7 +39,7 @@ Start your API server with I/O schema validation and custom middlewares in minut
39
39
  11. [Multiple schemas for one route](#multiple-schemas-for-one-route)
40
40
  12. [Customizing input sources](#customizing-input-sources)
41
41
  13. [Enabling HTTPS](#enabling-https)
42
- 14. [Exporting endpoint types to frontend](#exporting-endpoint-types-to-frontend)
42
+ 14. [Informing the frontend about the API](#informing-the-frontend-about-the-api)
43
43
  15. [Creating a documentation](#creating-a-documentation)
44
44
  5. [Additional hints](#additional-hints)
45
45
  1. [How to test endpoints](#how-to-test-endpoints)
@@ -605,23 +605,46 @@ At least you need to specify the port or socket (usually it is 443), certificate
605
605
  certifying authority. For example, you can acquire a free TLS certificate for your API at
606
606
  [Let's Encrypt](https://letsencrypt.org/).
607
607
 
608
- ## Exporting endpoint types to frontend
608
+ ## Informing the frontend about the API
609
609
 
610
- You can export only the types of your endpoints for your frontend. Here is an approach:
610
+ You can inform your frontend about the I/O types of your endpoints by exporting them to `.d.ts` files (they only
611
+ contain types without any executable code). To achieve that you are going to need an additional `tsconfig.dts.json`
612
+ file with the following content:
611
613
 
612
- ```typescript
613
- export type YourEndpointType = typeof yourEndpoint;
614
+ ```json
615
+ {
616
+ "extends": "./tsconfig.json",
617
+ "compilerOptions": {
618
+ "outDir": "dts",
619
+ "declaration": true,
620
+ "emitDeclarationOnly": true
621
+ }
622
+ }
614
623
  ```
615
624
 
616
- Then use provided helpers to obtain their input and response types:
625
+ Most likely you have a file with all the configured routing, in which you can do the following:
617
626
 
618
627
  ```typescript
619
628
  import { EndpointInput, EndpointResponse } from "express-zod-api";
620
- import type { YourEndpointType } from "../your/backend";
621
- // ^---- please note the import syntax of the type only
622
629
 
623
- type YourEndpointInput = EndpointInput<YourEndpointType>;
624
- type YourEndpointResponse = EndpointResponse<YourEndpointType>;
630
+ export type YourEndpointInput = EndpointInput<typeof yourEndpoint>;
631
+ export type YourEndpointResponse = EndpointResponse<typeof yourEndpoint>;
632
+ ```
633
+
634
+ By executing the following command you'll get the compiled `/dts/routing.d.ts` file.
635
+
636
+ ```shell
637
+ yarn tsc -p tsconfig.dts.json
638
+ ```
639
+
640
+ The command might become a part of your CI/CD.
641
+ Then import the I/O type of your endpoint from the compiled file using `import type` syntax on the frontend.
642
+
643
+ ```typescript
644
+ import type {
645
+ YourEndpointInput,
646
+ YourEndpointResponse,
647
+ } from "../your_backend/dts/routing";
625
648
  ```
626
649
 
627
650
  ## Creating a documentation
@@ -667,7 +690,7 @@ _See the example of the generated documentation
667
690
 
668
691
  The way to test endpoints is to mock the request, response, and logger objects, invoke the `execute()` method, and
669
692
  assert the expectations for calls of certain mocked methods. The library provides a special method that makes mocking
670
- easier, so the test might look the following way:
693
+ easier, it requires `jest` (and optionally `@types/jest`) to be installed, so the test might look the following way:
671
694
 
672
695
  ```typescript
673
696
  import { testEndpoint } from "express-zod-api";
@@ -675,11 +698,11 @@ import { testEndpoint } from "express-zod-api";
675
698
  test("should respond successfully", async () => {
676
699
  const { responseMock, loggerMock } = await testEndpoint({
677
700
  endpoint: yourEndpoint,
678
- // available options: requestProps, responseProps, configProps, loggerProps
679
701
  requestProps: {
680
702
  method: "POST", // default: GET
681
703
  body: { ... },
682
704
  },
705
+ // responseProps, configProps, loggerProps
683
706
  });
684
707
  expect(loggerMock.error).toBeCalledTimes(0);
685
708
  expect(responseMock.status).toBeCalledWith(200);
@@ -1 +1 @@
1
- {"type":"module","version":"5.1.0-beta2"}
1
+ {"type":"module","version":"5.1.0"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-zod-api",
3
- "version": "5.1.0-beta2",
3
+ "version": "5.1.0",
4
4
  "description": "A Typescript library to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.",
5
5
  "license": "MIT",
6
6
  "scripts": {