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
@@ -1,158 +1,158 @@
1
- // @ts-nocheck
2
- /**
3
- * Global API Pagination Plugin
4
- *
5
- * ⚠️ IMPORTANT: This file is NEVER regenerated - your changes are safe!
6
- *
7
- * Configure the global pagination convention for all paginated API requests.
8
- * Each composable can override this config locally via `paginationConfig` option.
9
- *
10
- * ── HOW IT WORKS ──────────────────────────────────────────────────────────────
11
- *
12
- * When you call a composable with `paginated: true`, the wrapper will:
13
- * 1. Inject page/perPage params into the request (query, body, or headers)
14
- * 2. After the response, read total/totalPages/currentPage/perPage from the
15
- * response headers or JSON body, according to `metaSource`
16
- * 3. Expose `pagination`, `goToPage()`, `nextPage()`, `prevPage()`, `setPerPage()`
17
- *
18
- * ── USAGE ─────────────────────────────────────────────────────────────────────
19
- *
20
- * // In your page/component:
21
- * const { data, pagination, goToPage, nextPage, prevPage, setPerPage } =
22
- * useGetPets(params, { paginated: true })
23
- *
24
- * // pagination is a computed ref:
25
- * pagination.value.currentPage // current page
26
- * pagination.value.totalPages // total pages
27
- * pagination.value.total // total items
28
- * pagination.value.perPage // items per page
29
- * pagination.value.hasNextPage // boolean
30
- * pagination.value.hasPrevPage // boolean
31
- *
32
- * // Navigation helpers — automatically trigger re-fetch:
33
- * goToPage(3)
34
- * nextPage()
35
- * prevPage()
36
- * setPerPage(50)
37
- *
38
- * ── PRIORITY ──────────────────────────────────────────────────────────────────
39
- *
40
- * Per-call paginationConfig > this plugin's global config > built-in defaults
41
- *
42
- * Example of per-call override:
43
- * useGetPets(params, {
44
- * paginated: true,
45
- * paginationConfig: {
46
- * meta: { metaSource: 'headers', fields: { ... } },
47
- * request: { sendAs: 'query', params: { page: 'p', perPage: 'size' }, defaults: { page: 1, perPage: 10 } }
48
- * }
49
- * })
50
- */
51
-
52
- export default defineNuxtPlugin(() => {
53
- // Uncomment and configure ONE of the examples below that matches your backend.
54
-
55
- // ============================================================================
56
- // EXAMPLE 1 — Query params + response body (most common REST pattern)
57
- //
58
- // Request: GET /pets?page=1&limit=20
59
- // Response: { data: [...], total: 100, totalPages: 5, currentPage: 1, perPage: 20 }
60
- // ============================================================================
61
- // const paginationConfig = {
62
- // meta: {
63
- // metaSource: 'body',
64
- // fields: {
65
- // total: 'total',
66
- // totalPages: 'totalPages',
67
- // currentPage: 'currentPage',
68
- // perPage: 'perPage',
69
- // dataKey: 'data', // response.data contains the actual array
70
- // },
71
- // },
72
- // request: {
73
- // sendAs: 'query',
74
- // params: { page: 'page', perPage: 'limit' },
75
- // defaults: { page: 1, perPage: 20 },
76
- // },
77
- // };
78
-
79
- // ============================================================================
80
- // EXAMPLE 2 — Laravel paginate() convention
81
- //
82
- // Request: GET /pets?page=1&per_page=15
83
- // Response: { data: [...], meta: { total: 100, last_page: 7, current_page: 1, per_page: 15 } }
84
- // ============================================================================
85
- // const paginationConfig = {
86
- // meta: {
87
- // metaSource: 'body',
88
- // fields: {
89
- // total: 'meta.total',
90
- // totalPages: 'meta.last_page',
91
- // currentPage: 'meta.current_page',
92
- // perPage: 'meta.per_page',
93
- // dataKey: 'data',
94
- // },
95
- // },
96
- // request: {
97
- // sendAs: 'query',
98
- // params: { page: 'page', perPage: 'per_page' },
99
- // defaults: { page: 1, perPage: 15 },
100
- // },
101
- // };
102
-
103
- // ============================================================================
104
- // EXAMPLE 3 — HTTP response headers convention
105
- //
106
- // Request: GET /pets?page=1&limit=20
107
- // Response headers: X-Total-Count: 100, X-Total-Pages: 5, X-Page: 1, X-Per-Page: 20
108
- // ============================================================================
109
- // const paginationConfig = {
110
- // meta: {
111
- // metaSource: 'headers',
112
- // fields: {
113
- // total: 'X-Total-Count',
114
- // totalPages: 'X-Total-Pages',
115
- // currentPage: 'X-Page',
116
- // perPage: 'X-Per-Page',
117
- // // No dataKey needed — response body is the array directly
118
- // },
119
- // },
120
- // request: {
121
- // sendAs: 'query',
122
- // params: { page: 'page', perPage: 'limit' },
123
- // defaults: { page: 1, perPage: 20 },
124
- // },
125
- // };
126
-
127
- // ============================================================================
128
- // EXAMPLE 4 — POST-as-search (body pagination)
129
- //
130
- // Request: POST /pets/search body: { filters: {...}, page: 1, pageSize: 20 }
131
- // Response: { items: [...], total: 100, pages: 5 }
132
- // ============================================================================
133
- // const paginationConfig = {
134
- // meta: {
135
- // metaSource: 'body',
136
- // fields: {
137
- // total: 'total',
138
- // totalPages: 'pages',
139
- // currentPage: 'page',
140
- // perPage: 'pageSize',
141
- // dataKey: 'items',
142
- // },
143
- // },
144
- // request: {
145
- // sendAs: 'body',
146
- // params: { page: 'page', perPage: 'pageSize' },
147
- // defaults: { page: 1, perPage: 20 },
148
- // },
149
- // };
150
-
151
- return {
152
- provide: {
153
- // Expose the config so the runtime wrappers can read it.
154
- // Uncomment this line once you've configured paginationConfig above:
155
- // getGlobalApiPagination: () => paginationConfig,
156
- },
157
- };
158
- });
1
+ // @ts-nocheck
2
+ /**
3
+ * Global API Pagination Plugin
4
+ *
5
+ * ⚠️ IMPORTANT: This file is NEVER regenerated - your changes are safe!
6
+ *
7
+ * Configure the global pagination convention for all paginated API requests.
8
+ * Each composable can override this config locally via `paginationConfig` option.
9
+ *
10
+ * ── HOW IT WORKS ──────────────────────────────────────────────────────────────
11
+ *
12
+ * When you call a composable with `paginated: true`, the wrapper will:
13
+ * 1. Inject page/perPage params into the request (query, body, or headers)
14
+ * 2. After the response, read total/totalPages/currentPage/perPage from the
15
+ * response headers or JSON body, according to `metaSource`
16
+ * 3. Expose `pagination`, `goToPage()`, `nextPage()`, `prevPage()`, `setPerPage()`
17
+ *
18
+ * ── USAGE ─────────────────────────────────────────────────────────────────────
19
+ *
20
+ * // In your page/component:
21
+ * const { data, pagination, goToPage, nextPage, prevPage, setPerPage } =
22
+ * useGetPets(params, { paginated: true })
23
+ *
24
+ * // pagination is a computed ref:
25
+ * pagination.value.currentPage // current page
26
+ * pagination.value.totalPages // total pages
27
+ * pagination.value.total // total items
28
+ * pagination.value.perPage // items per page
29
+ * pagination.value.hasNextPage // boolean
30
+ * pagination.value.hasPrevPage // boolean
31
+ *
32
+ * // Navigation helpers — automatically trigger re-fetch:
33
+ * goToPage(3)
34
+ * nextPage()
35
+ * prevPage()
36
+ * setPerPage(50)
37
+ *
38
+ * ── PRIORITY ──────────────────────────────────────────────────────────────────
39
+ *
40
+ * Per-call paginationConfig > this plugin's global config > built-in defaults
41
+ *
42
+ * Example of per-call override:
43
+ * useGetPets(params, {
44
+ * paginated: true,
45
+ * paginationConfig: {
46
+ * meta: { metaSource: 'headers', fields: { ... } },
47
+ * request: { sendAs: 'query', params: { page: 'p', perPage: 'size' }, defaults: { page: 1, perPage: 10 } }
48
+ * }
49
+ * })
50
+ */
51
+
52
+ export default defineNuxtPlugin(() => {
53
+ // Uncomment and configure ONE of the examples below that matches your backend.
54
+
55
+ // ============================================================================
56
+ // EXAMPLE 1 — Query params + response body (most common REST pattern)
57
+ //
58
+ // Request: GET /pets?page=1&limit=20
59
+ // Response: { data: [...], total: 100, totalPages: 5, currentPage: 1, perPage: 20 }
60
+ // ============================================================================
61
+ // const paginationConfig = {
62
+ // meta: {
63
+ // metaSource: 'body',
64
+ // fields: {
65
+ // total: 'total',
66
+ // totalPages: 'totalPages',
67
+ // currentPage: 'currentPage',
68
+ // perPage: 'perPage',
69
+ // dataKey: 'data', // response.data contains the actual array
70
+ // },
71
+ // },
72
+ // request: {
73
+ // sendAs: 'query',
74
+ // params: { page: 'page', perPage: 'limit' },
75
+ // defaults: { page: 1, perPage: 20 },
76
+ // },
77
+ // };
78
+
79
+ // ============================================================================
80
+ // EXAMPLE 2 — Laravel paginate() convention
81
+ //
82
+ // Request: GET /pets?page=1&per_page=15
83
+ // Response: { data: [...], meta: { total: 100, last_page: 7, current_page: 1, per_page: 15 } }
84
+ // ============================================================================
85
+ // const paginationConfig = {
86
+ // meta: {
87
+ // metaSource: 'body',
88
+ // fields: {
89
+ // total: 'meta.total',
90
+ // totalPages: 'meta.last_page',
91
+ // currentPage: 'meta.current_page',
92
+ // perPage: 'meta.per_page',
93
+ // dataKey: 'data',
94
+ // },
95
+ // },
96
+ // request: {
97
+ // sendAs: 'query',
98
+ // params: { page: 'page', perPage: 'per_page' },
99
+ // defaults: { page: 1, perPage: 15 },
100
+ // },
101
+ // };
102
+
103
+ // ============================================================================
104
+ // EXAMPLE 3 — HTTP response headers convention
105
+ //
106
+ // Request: GET /pets?page=1&limit=20
107
+ // Response headers: X-Total-Count: 100, X-Total-Pages: 5, X-Page: 1, X-Per-Page: 20
108
+ // ============================================================================
109
+ // const paginationConfig = {
110
+ // meta: {
111
+ // metaSource: 'headers',
112
+ // fields: {
113
+ // total: 'X-Total-Count',
114
+ // totalPages: 'X-Total-Pages',
115
+ // currentPage: 'X-Page',
116
+ // perPage: 'X-Per-Page',
117
+ // // No dataKey needed — response body is the array directly
118
+ // },
119
+ // },
120
+ // request: {
121
+ // sendAs: 'query',
122
+ // params: { page: 'page', perPage: 'limit' },
123
+ // defaults: { page: 1, perPage: 20 },
124
+ // },
125
+ // };
126
+
127
+ // ============================================================================
128
+ // EXAMPLE 4 — POST-as-search (body pagination)
129
+ //
130
+ // Request: POST /pets/search body: { filters: {...}, page: 1, pageSize: 20 }
131
+ // Response: { items: [...], total: 100, pages: 5 }
132
+ // ============================================================================
133
+ // const paginationConfig = {
134
+ // meta: {
135
+ // metaSource: 'body',
136
+ // fields: {
137
+ // total: 'total',
138
+ // totalPages: 'pages',
139
+ // currentPage: 'page',
140
+ // perPage: 'pageSize',
141
+ // dataKey: 'items',
142
+ // },
143
+ // },
144
+ // request: {
145
+ // sendAs: 'body',
146
+ // params: { page: 'page', perPage: 'pageSize' },
147
+ // defaults: { page: 1, perPage: 20 },
148
+ // },
149
+ // };
150
+
151
+ return {
152
+ provide: {
153
+ // Expose the config so the runtime wrappers can read it.
154
+ // Uncomment this line once you've configured paginationConfig above:
155
+ // getGlobalApiPagination: () => paginationConfig,
156
+ },
157
+ };
158
+ });