@yigityalim/next-router-client 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 myy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @yigityalim/next-router-client
2
+
3
+ TypeScript client code generator from OpenAPI specifications for [@yigityalim/next-router](https://www.npmjs.com/package/@yigityalim/next-router).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @yigityalim/next-router-client
9
+ # or
10
+ pnpm add @yigityalim/next-router-client
11
+ # or
12
+ yarn add @yigityalim/next-router-client
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### CLI (Recommended)
18
+
19
+ Use via [@yigityalim/next-router-cli](https://www.npmjs.com/package/@yigityalim/next-router-cli):
20
+
21
+ ```bash
22
+ npx @yigityalim/next-router-cli generate-client -i ./openapi.json -o ./src/api
23
+ ```
24
+
25
+ ### Programmatic API
26
+
27
+ ```typescript
28
+ import { generateClient } from '@yigityalim/next-router-client';
29
+
30
+ await generateClient({
31
+ openApiPath: './api-spec.json',
32
+ outputDir: './src/api',
33
+ library: 'react-query', // 'react-query' | 'swr' | 'vanilla'
34
+ baseUrl: '/api/v1'
35
+ });
36
+ ```
37
+
38
+ ## Features
39
+
40
+ - **Multiple Libraries**: Generate clients for React Query, SWR, or vanilla fetchers
41
+ - **Type-Safe**: Full TypeScript support with generated types from OpenAPI spec
42
+ - **Customizable**: Configure base URL, output directory, and more
43
+ - **OpenAPI 3.x**: Full support for OpenAPI 3.0 and 3.1 specifications
44
+
45
+ ## Generated Code
46
+
47
+ ### React Query Example
48
+
49
+ ```typescript
50
+ import { useGetUsers, useCreateUser } from './api/hooks';
51
+
52
+ function Users() {
53
+ const { data, isLoading } = useGetUsers();
54
+ const createMutation = useCreateUser();
55
+
56
+ // ...
57
+ }
58
+ ```
59
+
60
+ ### SWR Example
61
+
62
+ ```typescript
63
+ import { useGetUsers, useCreateUser } from './api/hooks';
64
+
65
+ function Users() {
66
+ const { data, error } = useGetUsers();
67
+ const { trigger } = useCreateUser();
68
+
69
+ // ...
70
+ }
71
+ ```
72
+
73
+ ### Vanilla Example
74
+
75
+ ```typescript
76
+ import { getUsers, createUser } from './api/fetchers';
77
+
78
+ const users = await getUsers();
79
+ const newUser = await createUser({ name: 'John' });
80
+ ```
81
+
82
+ ## API
83
+
84
+ ### `generateClient(options)`
85
+
86
+ Generate TypeScript client code from OpenAPI spec.
87
+
88
+ **Options:**
89
+ - `openApiPath` (string, required) - Path to OpenAPI JSON/YAML file
90
+ - `outputDir` (string, required) - Output directory for generated code
91
+ - `library` (string, optional) - Client library: `'react-query'` | `'swr'` | `'vanilla'` (default: `'react-query'`)
92
+ - `baseUrl` (string, optional) - Base URL for API requests (default: `'/api'`)
93
+
94
+ ## Related Packages
95
+
96
+ - [@yigityalim/next-router](https://www.npmjs.com/package/@yigityalim/next-router) - Type-safe Next.js API route handler
97
+ - [@yigityalim/next-router-cli](https://www.npmjs.com/package/@yigityalim/next-router-cli) - CLI tools for route management
98
+
99
+ ## License
100
+
101
+ MIT © [yigityalim](https://github.com/yigityalim)
@@ -0,0 +1,52 @@
1
+ type ClientLibrary = "react-query" | "swr" | "vanilla";
2
+ interface GenerateOptions {
3
+ /**
4
+ * Path to OpenAPI spec (JSON or YAML)
5
+ */
6
+ openApiPath: string;
7
+ /**
8
+ * Output directory for generated files
9
+ * @default ".next-router/generated"
10
+ */
11
+ outputDir?: string;
12
+ /**
13
+ * Client library to use for hooks
14
+ * @default "vanilla"
15
+ */
16
+ library?: ClientLibrary;
17
+ /**
18
+ * Base URL for API requests
19
+ * @default "/api/v1"
20
+ */
21
+ baseUrl?: string;
22
+ }
23
+
24
+ declare function generateClient(options: GenerateOptions): Promise<void>;
25
+
26
+ interface GenerateFetchersOptions {
27
+ openApiPath: string;
28
+ outputDir: string;
29
+ baseUrl: string;
30
+ }
31
+ declare function generateFetchers(options: GenerateFetchersOptions): Promise<void>;
32
+
33
+ interface GenerateHooksOptions {
34
+ openApiPath: string;
35
+ outputDir: string;
36
+ library: ClientLibrary;
37
+ }
38
+ declare function generateHooks(options: GenerateHooksOptions): Promise<void>;
39
+
40
+ interface GenerateKeysOptions {
41
+ openApiPath: string;
42
+ outputDir: string;
43
+ }
44
+ declare function generateKeys(options: GenerateKeysOptions): Promise<void>;
45
+
46
+ interface GenerateTypesOptions {
47
+ openApiPath: string;
48
+ outputDir: string;
49
+ }
50
+ declare function generateTypes(options: GenerateTypesOptions): Promise<void>;
51
+
52
+ export { type ClientLibrary, type GenerateOptions, generateClient, generateFetchers, generateHooks, generateKeys, generateTypes };
@@ -0,0 +1,52 @@
1
+ type ClientLibrary = "react-query" | "swr" | "vanilla";
2
+ interface GenerateOptions {
3
+ /**
4
+ * Path to OpenAPI spec (JSON or YAML)
5
+ */
6
+ openApiPath: string;
7
+ /**
8
+ * Output directory for generated files
9
+ * @default ".next-router/generated"
10
+ */
11
+ outputDir?: string;
12
+ /**
13
+ * Client library to use for hooks
14
+ * @default "vanilla"
15
+ */
16
+ library?: ClientLibrary;
17
+ /**
18
+ * Base URL for API requests
19
+ * @default "/api/v1"
20
+ */
21
+ baseUrl?: string;
22
+ }
23
+
24
+ declare function generateClient(options: GenerateOptions): Promise<void>;
25
+
26
+ interface GenerateFetchersOptions {
27
+ openApiPath: string;
28
+ outputDir: string;
29
+ baseUrl: string;
30
+ }
31
+ declare function generateFetchers(options: GenerateFetchersOptions): Promise<void>;
32
+
33
+ interface GenerateHooksOptions {
34
+ openApiPath: string;
35
+ outputDir: string;
36
+ library: ClientLibrary;
37
+ }
38
+ declare function generateHooks(options: GenerateHooksOptions): Promise<void>;
39
+
40
+ interface GenerateKeysOptions {
41
+ openApiPath: string;
42
+ outputDir: string;
43
+ }
44
+ declare function generateKeys(options: GenerateKeysOptions): Promise<void>;
45
+
46
+ interface GenerateTypesOptions {
47
+ openApiPath: string;
48
+ outputDir: string;
49
+ }
50
+ declare function generateTypes(options: GenerateTypesOptions): Promise<void>;
51
+
52
+ export { type ClientLibrary, type GenerateOptions, generateClient, generateFetchers, generateHooks, generateKeys, generateTypes };