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.
- package/.editorconfig +26 -26
- package/.prettierignore +17 -17
- package/CONTRIBUTING.md +291 -291
- package/INSTRUCTIONS.md +327 -327
- package/LICENSE +202 -202
- package/README.md +309 -231
- package/dist/cli/config.d.ts +9 -2
- package/dist/cli/config.js +1 -1
- package/dist/cli/logo.js +5 -5
- package/dist/cli/messages.d.ts +1 -0
- package/dist/cli/messages.js +2 -0
- package/dist/cli/prompts.d.ts +5 -0
- package/dist/cli/prompts.js +12 -0
- package/dist/cli/types.d.ts +1 -1
- package/dist/generators/components/connector-generator/templates.js +68 -19
- package/dist/generators/shared/runtime/useFormConnector.js +8 -1
- package/dist/generators/shared/runtime/useListConnector.js +13 -6
- package/dist/generators/use-async-data/generator.js +4 -0
- package/dist/generators/use-async-data/runtime/useApiAsyncData.js +4 -4
- package/dist/generators/use-async-data/runtime/useApiAsyncDataRaw.js +4 -4
- package/dist/generators/use-async-data/templates.js +17 -17
- package/dist/generators/use-fetch/generator.js +4 -0
- package/dist/generators/use-fetch/templates.js +14 -14
- package/dist/index.js +40 -27
- package/dist/module/index.js +19 -0
- package/dist/module/types.d.ts +7 -0
- package/docs/API-REFERENCE.md +886 -886
- package/docs/generated-components.md +615 -615
- package/docs/headless-composables-ui.md +569 -569
- package/eslint.config.js +85 -85
- package/package.json +1 -1
- package/src/cli/config.ts +147 -140
- package/src/cli/logger.ts +124 -124
- package/src/cli/logo.ts +25 -25
- package/src/cli/messages.ts +4 -0
- package/src/cli/prompts.ts +14 -1
- package/src/cli/types.ts +50 -50
- package/src/generators/components/connector-generator/generator.ts +138 -138
- package/src/generators/components/connector-generator/templates.ts +307 -254
- package/src/generators/components/connector-generator/types.ts +34 -34
- package/src/generators/components/schema-analyzer/index.ts +44 -44
- package/src/generators/components/schema-analyzer/intent-detector.ts +187 -187
- package/src/generators/components/schema-analyzer/openapi-reader.ts +96 -96
- package/src/generators/components/schema-analyzer/resource-grouper.ts +166 -166
- package/src/generators/components/schema-analyzer/schema-field-mapper.ts +268 -268
- package/src/generators/components/schema-analyzer/types.ts +177 -177
- package/src/generators/nuxt-server/generator.ts +272 -272
- package/src/generators/shared/runtime/apiHelpers.ts +535 -535
- package/src/generators/shared/runtime/pagination.ts +323 -323
- package/src/generators/shared/runtime/useDeleteConnector.ts +109 -109
- package/src/generators/shared/runtime/useDetailConnector.ts +64 -64
- package/src/generators/shared/runtime/useFormConnector.ts +147 -139
- package/src/generators/shared/runtime/useListConnector.ts +158 -148
- package/src/generators/shared/runtime/zod-error-merger.ts +119 -119
- package/src/generators/shared/templates/api-callbacks-plugin.ts +399 -399
- package/src/generators/shared/templates/api-pagination-plugin.ts +158 -158
- package/src/generators/use-async-data/generator.ts +213 -205
- package/src/generators/use-async-data/runtime/useApiAsyncData.ts +329 -329
- package/src/generators/use-async-data/runtime/useApiAsyncDataRaw.ts +324 -324
- package/src/generators/use-async-data/templates.ts +257 -257
- package/src/generators/use-fetch/generator.ts +178 -170
- package/src/generators/use-fetch/runtime/useApiRequest.ts +354 -354
- package/src/generators/use-fetch/templates.ts +214 -214
- package/src/index.ts +306 -303
- package/src/module/index.ts +158 -133
- package/src/module/types.ts +39 -31
- package/dist/generators/tanstack-query/generator.d.ts +0 -5
- 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
|
+
});
|