@devup-api/next-plugin 0.1.1 → 0.1.3

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/README.md CHANGED
@@ -1,22 +1,141 @@
1
1
  # @devup-api/next-plugin
2
2
 
3
- devup API plugin for Next.js
3
+ Next.js plugin for devup-api that generates TypeScript types from OpenAPI schemas.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @devup-api/next-plugin
8
+ npm install @devup-api/next-plugin @devup-api/fetch
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
- ```typescript
14
- import devupApiPlugin from '@devup-api/next-plugin';
13
+ ### Basic Setup
15
14
 
16
- const nextConfig = {
17
- // ... existing configuration
18
- ...devupApiPlugin({
19
- // options
20
- }),
21
- };
15
+ Add the plugin to your `next.config.ts`:
16
+
17
+ ```ts
18
+ import devupApi from '@devup-api/next-plugin'
19
+
20
+ export default devupApi({
21
+ reactStrictMode: true,
22
+ })
23
+ ```
24
+
25
+ ### With Options
26
+
27
+ ```ts
28
+ import devupApi from '@devup-api/next-plugin'
29
+
30
+ export default devupApi(
31
+ {
32
+ reactStrictMode: true,
33
+ },
34
+ {
35
+ openapiFile: './api/openapi.json',
36
+ convertCase: 'camel',
37
+ tempDir: 'temp'
38
+ }
39
+ )
40
+ ```
41
+
42
+ ## Options
43
+
44
+ ```ts
45
+ interface DevupApiOptions {
46
+ /**
47
+ * OpenAPI file path
48
+ * @default 'openapi.json'
49
+ */
50
+ openapiFile?: string
51
+
52
+ /**
53
+ * Temporary directory for storing generated files
54
+ * @default 'df'
55
+ */
56
+ tempDir?: string
57
+
58
+ /**
59
+ * Case conversion type for API endpoint names and parameters
60
+ * @default 'camel'
61
+ */
62
+ convertCase?: 'snake' | 'camel' | 'pascal' | 'maintain'
63
+
64
+ /**
65
+ * Whether to make all properties non-nullable by default
66
+ * @default false
67
+ */
68
+ requestDefaultNonNullable?: boolean
69
+
70
+ /**
71
+ * Whether to make all request properties non-nullable by default
72
+ * @default true
73
+ */
74
+ responseDefaultNonNullable?: boolean
75
+ }
22
76
  ```
77
+
78
+ ## How It Works
79
+
80
+ ### Turbopack Mode
81
+
82
+ When using Turbopack (Next.js 13+), the plugin:
83
+ 1. Reads your `openapi.json` file
84
+ 2. Generates TypeScript interface definitions
85
+ 3. Creates a URL map and sets it as `process.env.DEVUP_API_URL_MAP`
86
+ 4. Makes types available for use with `@devup-api/fetch`
87
+
88
+ ### Webpack Mode
89
+
90
+ When using Webpack, the plugin uses `@devup-api/webpack-plugin` internally to:
91
+ 1. Generate types during build time
92
+ 2. Inject URL map via webpack DefinePlugin
93
+ 3. Make types available for use with `@devup-api/fetch`
94
+
95
+ ## TypeScript Configuration
96
+
97
+ To use the generated types, add the generated type definitions to your `tsconfig.json`:
98
+
99
+ ```json
100
+ {
101
+ "compilerOptions": {
102
+ // ... your compiler options
103
+ },
104
+ "include": [
105
+ "next-env.d.ts",
106
+ "**/*.ts",
107
+ "**/*.tsx",
108
+ ".next/types/**/*.ts",
109
+ ".next/dev/types/**/*.ts",
110
+ "df/**/*.d.ts"
111
+ ]
112
+ }
113
+ ```
114
+
115
+ > **Note:** If you've customized `tempDir` in plugin options, adjust the path accordingly (e.g., `"your-temp-dir/**/*.d.ts"`).
116
+
117
+ ## Using the Generated Types
118
+
119
+ After the plugin runs, you can use the generated types with `@devup-api/fetch`:
120
+
121
+ ```ts
122
+ import { createApi } from '@devup-api/fetch'
123
+
124
+ const api = createApi('https://api.example.com')
125
+
126
+ // Types are automatically available
127
+ const users = await api.get('getUsers', {})
128
+ ```
129
+
130
+ ## Cold Typing vs Bold Typing
131
+
132
+ devup-api uses a two-phase typing system:
133
+
134
+ - **Cold Typing**: Before the build runs, types are `any` to prevent type errors. Your code compiles and runs smoothly.
135
+ - **Bold Typing**: After the build runs and `api.d.ts` is generated, full type safety is enforced with strict type checking.
136
+
137
+ This ensures you can start coding immediately without waiting for the build, while still getting full type safety in production.
138
+
139
+ ## License
140
+
141
+ Apache 2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devup-api/next-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -20,10 +20,10 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "@devup-api/utils": "0.1.1",
24
- "@devup-api/core": "0.1.1",
25
- "@devup-api/generator": "0.1.1",
26
- "@devup-api/webpack-plugin": "0.1.1"
23
+ "@devup-api/utils": "0.1.3",
24
+ "@devup-api/core": "0.1.3",
25
+ "@devup-api/generator": "0.1.3",
26
+ "@devup-api/webpack-plugin": "0.1.3"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "next": "*",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/index.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=plugin.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/plugin.test.ts"],"names":[],"mappings":""}