nuxt-openapi-hyperfetch 0.2.7-alpha.1 → 0.3.0-beta

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.
Files changed (68) hide show
  1. package/.editorconfig +26 -26
  2. package/.prettierignore +17 -17
  3. package/CONTRIBUTING.md +291 -291
  4. package/INSTRUCTIONS.md +327 -327
  5. package/LICENSE +202 -202
  6. package/README.md +309 -231
  7. package/dist/cli/config.d.ts +9 -2
  8. package/dist/cli/config.js +1 -1
  9. package/dist/cli/logo.js +5 -5
  10. package/dist/cli/messages.d.ts +1 -0
  11. package/dist/cli/messages.js +2 -0
  12. package/dist/cli/prompts.d.ts +5 -0
  13. package/dist/cli/prompts.js +12 -0
  14. package/dist/cli/types.d.ts +1 -1
  15. package/dist/generators/components/connector-generator/templates.js +68 -19
  16. package/dist/generators/shared/runtime/useFormConnector.js +8 -1
  17. package/dist/generators/shared/runtime/useListConnector.js +13 -6
  18. package/dist/generators/use-async-data/generator.js +4 -0
  19. package/dist/generators/use-async-data/runtime/useApiAsyncData.js +4 -4
  20. package/dist/generators/use-async-data/runtime/useApiAsyncDataRaw.js +4 -4
  21. package/dist/generators/use-async-data/templates.js +17 -17
  22. package/dist/generators/use-fetch/generator.js +4 -0
  23. package/dist/generators/use-fetch/templates.js +14 -14
  24. package/dist/index.js +40 -27
  25. package/dist/module/index.js +19 -0
  26. package/dist/module/types.d.ts +7 -0
  27. package/docs/API-REFERENCE.md +886 -886
  28. package/docs/generated-components.md +615 -615
  29. package/docs/headless-composables-ui.md +569 -569
  30. package/eslint.config.js +85 -85
  31. package/package.json +1 -1
  32. package/src/cli/config.ts +147 -140
  33. package/src/cli/logger.ts +124 -124
  34. package/src/cli/logo.ts +25 -25
  35. package/src/cli/messages.ts +4 -0
  36. package/src/cli/prompts.ts +14 -1
  37. package/src/cli/types.ts +50 -50
  38. package/src/generators/components/connector-generator/generator.ts +138 -138
  39. package/src/generators/components/connector-generator/templates.ts +307 -254
  40. package/src/generators/components/connector-generator/types.ts +34 -34
  41. package/src/generators/components/schema-analyzer/index.ts +44 -44
  42. package/src/generators/components/schema-analyzer/intent-detector.ts +187 -187
  43. package/src/generators/components/schema-analyzer/openapi-reader.ts +96 -96
  44. package/src/generators/components/schema-analyzer/resource-grouper.ts +166 -166
  45. package/src/generators/components/schema-analyzer/schema-field-mapper.ts +268 -268
  46. package/src/generators/components/schema-analyzer/types.ts +177 -177
  47. package/src/generators/nuxt-server/generator.ts +272 -272
  48. package/src/generators/shared/runtime/apiHelpers.ts +535 -535
  49. package/src/generators/shared/runtime/pagination.ts +323 -323
  50. package/src/generators/shared/runtime/useDeleteConnector.ts +109 -109
  51. package/src/generators/shared/runtime/useDetailConnector.ts +64 -64
  52. package/src/generators/shared/runtime/useFormConnector.ts +147 -139
  53. package/src/generators/shared/runtime/useListConnector.ts +158 -148
  54. package/src/generators/shared/runtime/zod-error-merger.ts +119 -119
  55. package/src/generators/shared/templates/api-callbacks-plugin.ts +399 -399
  56. package/src/generators/shared/templates/api-pagination-plugin.ts +158 -158
  57. package/src/generators/use-async-data/generator.ts +213 -205
  58. package/src/generators/use-async-data/runtime/useApiAsyncData.ts +329 -329
  59. package/src/generators/use-async-data/runtime/useApiAsyncDataRaw.ts +324 -324
  60. package/src/generators/use-async-data/templates.ts +257 -257
  61. package/src/generators/use-fetch/generator.ts +178 -170
  62. package/src/generators/use-fetch/runtime/useApiRequest.ts +354 -354
  63. package/src/generators/use-fetch/templates.ts +214 -214
  64. package/src/index.ts +306 -303
  65. package/src/module/index.ts +158 -133
  66. package/src/module/types.ts +39 -31
  67. package/dist/generators/tanstack-query/generator.d.ts +0 -5
  68. package/dist/generators/tanstack-query/generator.js +0 -11
package/src/cli/logger.ts CHANGED
@@ -1,124 +1,124 @@
1
- /**
2
- * Centralized logging utilities using @clack/prompts
3
- * Re-exports @clack for easy use across the project
4
- */
5
- import * as p from '@clack/prompts';
6
-
7
- /**
8
- * Re-export @clack/prompts for consistent usage
9
- */
10
- export { p };
11
-
12
- /**
13
- * Create and manage a spinner for long operations
14
- *
15
- * @example
16
- * const spinner = createSpinner();
17
- * spinner.start('Processing files');
18
- * // do work
19
- * spinner.stop('Files processed');
20
- */
21
- export function createSpinner() {
22
- return p.spinner();
23
- }
24
-
25
- /**
26
- * Log a success message (replaces console.log with ✓)
27
- */
28
- export function logSuccess(message: string) {
29
- p.log.success(message);
30
- }
31
-
32
- /**
33
- * Log an error message
34
- */
35
- export function logError(message: string) {
36
- p.log.error(message);
37
- }
38
-
39
- /**
40
- * Log a warning message
41
- */
42
- export function logWarning(message: string) {
43
- p.log.warn(message);
44
- }
45
-
46
- /**
47
- * Log an info message
48
- */
49
- export function logInfo(message: string) {
50
- p.log.info(message);
51
- }
52
-
53
- /**
54
- * Display a note/box with multiple lines of information
55
- * Great for "Next steps" sections
56
- */
57
- export function logNote(message: string, title?: string) {
58
- p.note(message, title);
59
- }
60
-
61
- /**
62
- * Display section separator
63
- */
64
- export function logStep(message: string) {
65
- p.log.step(message);
66
- }
67
-
68
- // ---------------------------------------------------------------------------
69
- // Logger abstraction — allows generators to run in both CLI and Nuxt module
70
- // ---------------------------------------------------------------------------
71
-
72
- /**
73
- * Abstract logger interface used by generators.
74
- * Decouples generator output from @clack/prompts so the same generators work
75
- * in the interactive CLI and in the Nuxt module (where clack is irrelevant).
76
- */
77
- export interface Logger {
78
- spinner(): { start(msg: string): void; stop(msg: string): void };
79
- log: {
80
- warn(msg: string): void;
81
- info(msg: string): void;
82
- success(msg: string): void;
83
- error(msg: string): void;
84
- };
85
- note(msg: string, title?: string): void;
86
- }
87
-
88
- /**
89
- * Creates a Logger backed by @clack/prompts — used by the CLI.
90
- */
91
- export function createClackLogger(): Logger {
92
- return {
93
- spinner: () => p.spinner(),
94
- log: {
95
- warn: (msg) => p.log.warn(msg),
96
- info: (msg) => p.log.info(msg),
97
- success: (msg) => p.log.success(msg),
98
- error: (msg) => p.log.error(msg),
99
- },
100
- note: (msg, title) => p.note(msg, title),
101
- };
102
- }
103
-
104
- /**
105
- * Creates a Logger backed by console — used by the Nuxt module.
106
- */
107
- export function createConsoleLogger(): Logger {
108
- const prefix = '[nuxt-openapi-hyperfetch]';
109
- return {
110
- spinner() {
111
- return {
112
- start: (msg: string) => console.log(`${prefix} ⏳ ${msg}`),
113
- stop: (msg: string) => console.log(`${prefix} ✓ ${msg}`),
114
- };
115
- },
116
- log: {
117
- warn: (msg) => console.warn(`${prefix} ⚠ ${msg}`),
118
- info: (msg) => console.info(`${prefix} ℹ ${msg}`),
119
- success: (msg) => console.log(`${prefix} ✓ ${msg}`),
120
- error: (msg) => console.error(`${prefix} ✗ ${msg}`),
121
- },
122
- note: (msg, title) => console.log(title ? `\n${prefix} ${title}:\n${msg}\n` : `\n${msg}\n`),
123
- };
124
- }
1
+ /**
2
+ * Centralized logging utilities using @clack/prompts
3
+ * Re-exports @clack for easy use across the project
4
+ */
5
+ import * as p from '@clack/prompts';
6
+
7
+ /**
8
+ * Re-export @clack/prompts for consistent usage
9
+ */
10
+ export { p };
11
+
12
+ /**
13
+ * Create and manage a spinner for long operations
14
+ *
15
+ * @example
16
+ * const spinner = createSpinner();
17
+ * spinner.start('Processing files');
18
+ * // do work
19
+ * spinner.stop('Files processed');
20
+ */
21
+ export function createSpinner() {
22
+ return p.spinner();
23
+ }
24
+
25
+ /**
26
+ * Log a success message (replaces console.log with ✓)
27
+ */
28
+ export function logSuccess(message: string) {
29
+ p.log.success(message);
30
+ }
31
+
32
+ /**
33
+ * Log an error message
34
+ */
35
+ export function logError(message: string) {
36
+ p.log.error(message);
37
+ }
38
+
39
+ /**
40
+ * Log a warning message
41
+ */
42
+ export function logWarning(message: string) {
43
+ p.log.warn(message);
44
+ }
45
+
46
+ /**
47
+ * Log an info message
48
+ */
49
+ export function logInfo(message: string) {
50
+ p.log.info(message);
51
+ }
52
+
53
+ /**
54
+ * Display a note/box with multiple lines of information
55
+ * Great for "Next steps" sections
56
+ */
57
+ export function logNote(message: string, title?: string) {
58
+ p.note(message, title);
59
+ }
60
+
61
+ /**
62
+ * Display section separator
63
+ */
64
+ export function logStep(message: string) {
65
+ p.log.step(message);
66
+ }
67
+
68
+ // ---------------------------------------------------------------------------
69
+ // Logger abstraction — allows generators to run in both CLI and Nuxt module
70
+ // ---------------------------------------------------------------------------
71
+
72
+ /**
73
+ * Abstract logger interface used by generators.
74
+ * Decouples generator output from @clack/prompts so the same generators work
75
+ * in the interactive CLI and in the Nuxt module (where clack is irrelevant).
76
+ */
77
+ export interface Logger {
78
+ spinner(): { start(msg: string): void; stop(msg: string): void };
79
+ log: {
80
+ warn(msg: string): void;
81
+ info(msg: string): void;
82
+ success(msg: string): void;
83
+ error(msg: string): void;
84
+ };
85
+ note(msg: string, title?: string): void;
86
+ }
87
+
88
+ /**
89
+ * Creates a Logger backed by @clack/prompts — used by the CLI.
90
+ */
91
+ export function createClackLogger(): Logger {
92
+ return {
93
+ spinner: () => p.spinner(),
94
+ log: {
95
+ warn: (msg) => p.log.warn(msg),
96
+ info: (msg) => p.log.info(msg),
97
+ success: (msg) => p.log.success(msg),
98
+ error: (msg) => p.log.error(msg),
99
+ },
100
+ note: (msg, title) => p.note(msg, title),
101
+ };
102
+ }
103
+
104
+ /**
105
+ * Creates a Logger backed by console — used by the Nuxt module.
106
+ */
107
+ export function createConsoleLogger(): Logger {
108
+ const prefix = '[nuxt-openapi-hyperfetch]';
109
+ return {
110
+ spinner() {
111
+ return {
112
+ start: (msg: string) => console.log(`${prefix} ⏳ ${msg}`),
113
+ stop: (msg: string) => console.log(`${prefix} ✓ ${msg}`),
114
+ };
115
+ },
116
+ log: {
117
+ warn: (msg) => console.warn(`${prefix} ⚠ ${msg}`),
118
+ info: (msg) => console.info(`${prefix} ℹ ${msg}`),
119
+ success: (msg) => console.log(`${prefix} ✓ ${msg}`),
120
+ error: (msg) => console.error(`${prefix} ✗ ${msg}`),
121
+ },
122
+ note: (msg, title) => console.log(title ? `\n${prefix} ${title}:\n${msg}\n` : `\n${msg}\n`),
123
+ };
124
+ }
package/src/cli/logo.ts CHANGED
@@ -1,25 +1,25 @@
1
- import gradient from 'gradient-string';
2
-
3
- const NUXT_LOGO = `███╗ ██╗██╗ ██╗██╗ ██╗████████╗
4
- ████╗ ██║██║ ██║╚██╗██╔╝╚══██╔══╝
5
- ██╔██╗ ██║██║ ██║ ╚███╔╝ ██║
6
- ██║╚██╗██║██║ ██║ ██╔██╗ ██║
7
- ██║ ╚████║╚██████╔╝██╔╝ ██╗ ██║
8
- ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝`;
9
-
10
- const SUBTITLE = 'Nuxt OpenAPI Generator - useFetch, useAsyncData & Nuxt server';
11
-
12
- /**
13
- * Display the Nuxt logo with gradient colors
14
- * - Green gradient for Nuxt logo (official Nuxt color #00DC82)
15
- * - Blue gradient for Swagger subtitle
16
- */
17
- export function displayLogo(): void {
18
- const nuxtGradient = gradient('#00DC82', '#00E090');
19
- const swaggerGradient = gradient('#3B82F6', '#0EA5E9');
20
-
21
- console.log('\n');
22
- console.log(nuxtGradient(NUXT_LOGO));
23
- console.log(swaggerGradient(SUBTITLE));
24
- console.log('\n');
25
- }
1
+ import gradient from 'gradient-string';
2
+
3
+ const NUXT_LOGO = `███╗ ██╗██╗ ██╗██╗ ██╗████████╗
4
+ ████╗ ██║██║ ██║╚██╗██╔╝╚══██╔══╝
5
+ ██╔██╗ ██║██║ ██║ ╚███╔╝ ██║
6
+ ██║╚██╗██║██║ ██║ ██╔██╗ ██║
7
+ ██║ ╚████║╚██████╔╝██╔╝ ██╗ ██║
8
+ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝`;
9
+
10
+ const SUBTITLE = 'Nuxt OpenAPI Generator - useFetch, useAsyncData & Nuxt server';
11
+
12
+ /**
13
+ * Display the Nuxt logo with gradient colors
14
+ * - Green gradient for Nuxt logo (official Nuxt color #00DC82)
15
+ * - Blue gradient for Swagger subtitle
16
+ */
17
+ export function displayLogo(): void {
18
+ const nuxtGradient = gradient('#00DC82', '#00E090');
19
+ const swaggerGradient = gradient('#3B82F6', '#0EA5E9');
20
+
21
+ console.log('\n');
22
+ console.log(nuxtGradient(NUXT_LOGO));
23
+ console.log(swaggerGradient(SUBTITLE));
24
+ console.log('\n');
25
+ }
@@ -67,6 +67,10 @@ export const CHOICES = {
67
67
  },
68
68
  ],
69
69
 
70
+ // Connectors prompt (shown only when useAsyncData is selected)
71
+ connectorsPrompt:
72
+ 'Generate headless UI connectors? (tables, pagination, forms & delete logic built on top of useAsyncData)',
73
+
70
74
  // Server path options
71
75
  serverPaths: [
72
76
  {
@@ -96,7 +96,7 @@ export async function promptComposablesSelection(): Promise<ComposablesSelection
96
96
  });
97
97
  checkCancellation(result);
98
98
 
99
- return { composables: result as ComposableType[] };
99
+ return { composables: result as ('useFetch' | 'useAsyncData' | 'nuxtServer')[] };
100
100
  }
101
101
 
102
102
  /**
@@ -141,3 +141,16 @@ export async function promptBffConfig(): Promise<BffConfig> {
141
141
 
142
142
  return { enableBff: result as boolean };
143
143
  }
144
+
145
+ /**
146
+ * Ask whether to generate headless UI connectors on top of useAsyncData.
147
+ * Only called when useAsyncData was selected and no config value is present.
148
+ */
149
+ export async function promptConnectors(): Promise<boolean> {
150
+ const result = await p.confirm({
151
+ message: CHOICES.connectorsPrompt,
152
+ initialValue: false,
153
+ });
154
+ checkCancellation(result);
155
+ return result as boolean;
156
+ }
package/src/cli/types.ts CHANGED
@@ -1,50 +1,50 @@
1
- /**
2
- * TypeScript types for CLI prompts and responses
3
- */
4
-
5
- /**
6
- * Generator backend selector (internal)
7
- */
8
- export type GeneratorBackend = 'official' | 'heyapi';
9
-
10
- /**
11
- * Generator engine value for nxh.config — user-facing alias
12
- * 'openapi' maps to the official Java-based OpenAPI Generator
13
- * 'heyapi' maps to @hey-api/openapi-ts (Node.js native)
14
- */
15
- export type ConfigGenerator = 'openapi' | 'heyapi';
16
-
17
- /**
18
- * Initial input and output paths
19
- */
20
- export interface InitialInputs {
21
- inputPath: string;
22
- outputPath: string;
23
- }
24
-
25
- /**
26
- * Composables selection (checkbox response)
27
- */
28
- export interface ComposablesSelection {
29
- composables: Array<'useFetch' | 'useAsyncData' | 'nuxtServer'>;
30
- }
31
-
32
- /**
33
- * Server route path configuration
34
- */
35
- export interface ServerRouteConfig {
36
- serverPath: string;
37
- customPath?: string;
38
- }
39
-
40
- /**
41
- * BFF (Backend for Frontend) configuration
42
- */
43
- export interface BffConfig {
44
- enableBff: boolean;
45
- }
46
-
47
- /**
48
- * Valid composable types
49
- */
50
- export type ComposableType = 'useFetch' | 'useAsyncData' | 'nuxtServer';
1
+ /**
2
+ * TypeScript types for CLI prompts and responses
3
+ */
4
+
5
+ /**
6
+ * Generator backend selector (internal)
7
+ */
8
+ export type GeneratorBackend = 'official' | 'heyapi';
9
+
10
+ /**
11
+ * Generator engine value for nxh.config — user-facing alias
12
+ * 'openapi' maps to the official Java-based OpenAPI Generator
13
+ * 'heyapi' maps to @hey-api/openapi-ts (Node.js native)
14
+ */
15
+ export type ConfigGenerator = 'openapi' | 'heyapi';
16
+
17
+ /**
18
+ * Initial input and output paths
19
+ */
20
+ export interface InitialInputs {
21
+ inputPath: string;
22
+ outputPath: string;
23
+ }
24
+
25
+ /**
26
+ * Composables selection (checkbox response)
27
+ */
28
+ export interface ComposablesSelection {
29
+ composables: Array<'useFetch' | 'useAsyncData' | 'nuxtServer'>;
30
+ }
31
+
32
+ /**
33
+ * Server route path configuration
34
+ */
35
+ export interface ServerRouteConfig {
36
+ serverPath: string;
37
+ customPath?: string;
38
+ }
39
+
40
+ /**
41
+ * BFF (Backend for Frontend) configuration
42
+ */
43
+ export interface BffConfig {
44
+ enableBff: boolean;
45
+ }
46
+
47
+ /**
48
+ * Valid composable types
49
+ */
50
+ export type ComposableType = 'useFetch' | 'useAsyncData' | 'nuxtServer' | 'connectors';