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,109 +1,109 @@
1
- // @ts-nocheck - This file runs in user's Nuxt project with different TypeScript config
2
- /**
3
- * useDeleteConnector — Runtime connector for DELETE endpoints.
4
- *
5
- * Manages:
6
- * - The target item to delete (set from the table via openDelete)
7
- * - Modal open/close state
8
- * - Confirmation logic
9
- * - Callbacks onSuccess / onError
10
- *
11
- * Copied to the user's project alongside the generated connectors.
12
- */
13
- import { ref, computed } from 'vue';
14
-
15
- /**
16
- * @param composableFn The generated delete composable, e.g. useAsyncDataDeletePet
17
- * @param options Optional configuration
18
- */
19
- export function useDeleteConnector(composableFn, options = {}) {
20
- // ── State ──────────────────────────────────────────────────────────────────
21
-
22
- const target = ref(null);
23
- const isOpen = ref(false);
24
- const loading = ref(false);
25
- const error = ref(null);
26
-
27
- // Callbacks — set by the developer or the generated component
28
- const onSuccess = ref(null);
29
- const onError = ref(null);
30
-
31
- // ── Actions ────────────────────────────────────────────────────────────────
32
-
33
- /**
34
- * Set the item to delete and open the confirmation modal.
35
- * Called by useListConnector.openDelete(row).
36
- */
37
- function setTarget(item) {
38
- target.value = item;
39
- isOpen.value = true;
40
- }
41
-
42
- /**
43
- * Cancel the delete operation — close modal and clear target.
44
- */
45
- function cancel() {
46
- isOpen.value = false;
47
- target.value = null;
48
- error.value = null;
49
- }
50
-
51
- /**
52
- * Confirm the delete — call the underlying composable with the target item.
53
- */
54
- async function confirm() {
55
- if (!target.value) {
56
- return;
57
- }
58
-
59
- loading.value = true;
60
- error.value = null;
61
-
62
- try {
63
- // Pass the full target item; the generated composable extracts the id it needs
64
- const composable = composableFn(target.value);
65
-
66
- if (composable.execute) {
67
- await composable.execute();
68
- }
69
-
70
- const err = composable.error?.value;
71
- if (err) {
72
- throw err;
73
- }
74
-
75
- const deletedItem = target.value;
76
- isOpen.value = false;
77
- target.value = null;
78
-
79
- onSuccess.value?.(deletedItem);
80
- } catch (err) {
81
- error.value = err;
82
- onError.value?.(err);
83
- } finally {
84
- loading.value = false;
85
- }
86
- }
87
-
88
- // ── Derived ────────────────────────────────────────────────────────────────
89
-
90
- const hasTarget = computed(() => target.value !== null);
91
-
92
- return {
93
- // State
94
- target,
95
- isOpen,
96
- loading,
97
- error,
98
- hasTarget,
99
-
100
- // Callbacks (developer-assignable)
101
- onSuccess,
102
- onError,
103
-
104
- // Actions
105
- setTarget,
106
- cancel,
107
- confirm,
108
- };
109
- }
1
+ // @ts-nocheck - This file runs in user's Nuxt project with different TypeScript config
2
+ /**
3
+ * useDeleteConnector — Runtime connector for DELETE endpoints.
4
+ *
5
+ * Manages:
6
+ * - The target item to delete (set from the table via openDelete)
7
+ * - Modal open/close state
8
+ * - Confirmation logic
9
+ * - Callbacks onSuccess / onError
10
+ *
11
+ * Copied to the user's project alongside the generated connectors.
12
+ */
13
+ import { ref, computed } from 'vue';
14
+
15
+ /**
16
+ * @param composableFn The generated delete composable, e.g. useAsyncDataDeletePet
17
+ * @param options Optional configuration
18
+ */
19
+ export function useDeleteConnector(composableFn, options = {}) {
20
+ // ── State ──────────────────────────────────────────────────────────────────
21
+
22
+ const target = ref(null);
23
+ const isOpen = ref(false);
24
+ const loading = ref(false);
25
+ const error = ref(null);
26
+
27
+ // Callbacks — set by the developer or the generated component
28
+ const onSuccess = ref(null);
29
+ const onError = ref(null);
30
+
31
+ // ── Actions ────────────────────────────────────────────────────────────────
32
+
33
+ /**
34
+ * Set the item to delete and open the confirmation modal.
35
+ * Called by useListConnector.openDelete(row).
36
+ */
37
+ function setTarget(item) {
38
+ target.value = item;
39
+ isOpen.value = true;
40
+ }
41
+
42
+ /**
43
+ * Cancel the delete operation — close modal and clear target.
44
+ */
45
+ function cancel() {
46
+ isOpen.value = false;
47
+ target.value = null;
48
+ error.value = null;
49
+ }
50
+
51
+ /**
52
+ * Confirm the delete — call the underlying composable with the target item.
53
+ */
54
+ async function confirm() {
55
+ if (!target.value) {
56
+ return;
57
+ }
58
+
59
+ loading.value = true;
60
+ error.value = null;
61
+
62
+ try {
63
+ // Pass the full target item; the generated composable extracts the id it needs
64
+ const composable = composableFn(target.value);
65
+
66
+ if (composable.execute) {
67
+ await composable.execute();
68
+ }
69
+
70
+ const err = composable.error?.value;
71
+ if (err) {
72
+ throw err;
73
+ }
74
+
75
+ const deletedItem = target.value;
76
+ isOpen.value = false;
77
+ target.value = null;
78
+
79
+ onSuccess.value?.(deletedItem);
80
+ } catch (err) {
81
+ error.value = err;
82
+ onError.value?.(err);
83
+ } finally {
84
+ loading.value = false;
85
+ }
86
+ }
87
+
88
+ // ── Derived ────────────────────────────────────────────────────────────────
89
+
90
+ const hasTarget = computed(() => target.value !== null);
91
+
92
+ return {
93
+ // State
94
+ target,
95
+ isOpen,
96
+ loading,
97
+ error,
98
+ hasTarget,
99
+
100
+ // Callbacks (developer-assignable)
101
+ onSuccess,
102
+ onError,
103
+
104
+ // Actions
105
+ setTarget,
106
+ cancel,
107
+ confirm,
108
+ };
109
+ }
@@ -1,64 +1,64 @@
1
- // @ts-nocheck - This file runs in user's Nuxt project with different TypeScript config
2
- /**
3
- * useDetailConnector — Runtime connector for single-item GET endpoints.
4
- *
5
- * Wraps a useAsyncData composable that returns a single object and exposes:
6
- * - item, loading, error state
7
- * - load(id) to fetch a specific item on demand
8
- * - fields derived from the response (used by detail view components)
9
- *
10
- * Copied to the user's project alongside the generated connectors.
11
- */
12
- import { ref, computed } from 'vue';
13
-
14
- /**
15
- * @param composableFn The generated useAsyncData composable, e.g. useAsyncDataGetPetById
16
- * @param options Optional configuration
17
- */
18
- export function useDetailConnector(composableFn, options = {}) {
19
- const { fields = [] } = options;
20
-
21
- // The item ID to load — reactive. null = not loaded yet.
22
- const currentId = ref(null);
23
-
24
- // ── Execute the underlying composable lazily (only when currentId changes) ─
25
- // We call the composable with lazy: true so it doesn't auto-fetch on mount.
26
- // load(id) sets currentId which triggers the watch inside the composable.
27
- const composable = composableFn(
28
- computed(() => (currentId.value !== null ? { id: currentId.value } : null)),
29
- { lazy: true, immediate: false }
30
- );
31
-
32
- // ── Derived state ──────────────────────────────────────────────────────────
33
-
34
- const item = computed(() => composable.data?.value ?? null);
35
- const loading = computed(() => composable.pending?.value ?? false);
36
- const error = computed(() => composable.error?.value ?? null);
37
-
38
- // ── Actions ────────────────────────────────────────────────────────────────
39
-
40
- async function load(id) {
41
- currentId.value = id;
42
- await composable.refresh?.();
43
- }
44
-
45
- function clear() {
46
- currentId.value = null;
47
- }
48
-
49
- return {
50
- // State
51
- item,
52
- loading,
53
- error,
54
- fields: computed(() => fields),
55
-
56
- // Actions
57
- load,
58
- clear,
59
-
60
- // Expose composable for advanced use (e.g. useFormConnector loadWith)
61
- _composable: composable,
62
- _currentId: currentId,
63
- };
64
- }
1
+ // @ts-nocheck - This file runs in user's Nuxt project with different TypeScript config
2
+ /**
3
+ * useDetailConnector — Runtime connector for single-item GET endpoints.
4
+ *
5
+ * Wraps a useAsyncData composable that returns a single object and exposes:
6
+ * - item, loading, error state
7
+ * - load(id) to fetch a specific item on demand
8
+ * - fields derived from the response (used by detail view components)
9
+ *
10
+ * Copied to the user's project alongside the generated connectors.
11
+ */
12
+ import { ref, computed } from 'vue';
13
+
14
+ /**
15
+ * @param composableFn The generated useAsyncData composable, e.g. useAsyncDataGetPetById
16
+ * @param options Optional configuration
17
+ */
18
+ export function useDetailConnector(composableFn, options = {}) {
19
+ const { fields = [] } = options;
20
+
21
+ // The item ID to load — reactive. null = not loaded yet.
22
+ const currentId = ref(null);
23
+
24
+ // ── Execute the underlying composable lazily (only when currentId changes) ─
25
+ // We call the composable with lazy: true so it doesn't auto-fetch on mount.
26
+ // load(id) sets currentId which triggers the watch inside the composable.
27
+ const composable = composableFn(
28
+ computed(() => (currentId.value !== null ? { id: currentId.value } : null)),
29
+ { lazy: true, immediate: false }
30
+ );
31
+
32
+ // ── Derived state ──────────────────────────────────────────────────────────
33
+
34
+ const item = computed(() => composable.data?.value ?? null);
35
+ const loading = computed(() => composable.pending?.value ?? false);
36
+ const error = computed(() => composable.error?.value ?? null);
37
+
38
+ // ── Actions ────────────────────────────────────────────────────────────────
39
+
40
+ async function load(id) {
41
+ currentId.value = id;
42
+ await composable.refresh?.();
43
+ }
44
+
45
+ function clear() {
46
+ currentId.value = null;
47
+ }
48
+
49
+ return {
50
+ // State
51
+ item,
52
+ loading,
53
+ error,
54
+ fields: computed(() => fields),
55
+
56
+ // Actions
57
+ load,
58
+ clear,
59
+
60
+ // Expose composable for advanced use (e.g. useFormConnector loadWith)
61
+ _composable: composable,
62
+ _currentId: currentId,
63
+ };
64
+ }
@@ -1,139 +1,147 @@
1
- // @ts-nocheck - This file runs in user's Nuxt project with different TypeScript config
2
- /**
3
- * useFormConnector — Runtime connector for create/update form endpoints.
4
- *
5
- * Responsibilities:
6
- * - Hold the reactive form model
7
- * - Validate with a Zod schema (generated at code-gen time) on submit
8
- * - Merge Zod error messages with per-field overrides from config
9
- * - Submit the validated data via the provided useAsyncData composable
10
- * - Optionally pre-fill from a useDetailConnector (loadWith option)
11
- *
12
- * Copied to the user's project alongside the generated connectors.
13
- */
14
- import { ref, computed, watch } from 'vue';
15
- import { mergeZodErrors } from './zod-error-merger.js';
16
-
17
- /**
18
- * @param composableFn The generated mutation composable, e.g. useAsyncDataCreatePet
19
- * @param options { schema, fields, loadWith?, errorConfig? }
20
- */
21
- export function useFormConnector(composableFn, options = {}) {
22
- const { schema, fields = [], loadWith = null, errorConfig = {} } = options;
23
-
24
- // ── Form state ─────────────────────────────────────────────────────────────
25
-
26
- const model = ref({});
27
- const errors = ref({});
28
- const loading = ref(false);
29
- const submitError = ref(null);
30
- const submitted = ref(false);
31
-
32
- // Callbacks set by the developer or the generated component
33
- const onSuccess = ref(null);
34
- const onError = ref(null);
35
-
36
- // ── Pre-fill from detail connector ────────────────────────────────────────
37
-
38
- if (loadWith) {
39
- // When the detail item changes (e.g. user clicks "Edit"), pre-fill the model
40
- watch(
41
- () => loadWith.item?.value,
42
- (newItem) => {
43
- if (newItem) {
44
- setValues(newItem);
45
- }
46
- },
47
- { immediate: true }
48
- );
49
- }
50
-
51
- // ── Actions ────────────────────────────────────────────────────────────────
52
-
53
- function setValues(data) {
54
- model.value = { ...model.value, ...data };
55
- }
56
-
57
- function reset() {
58
- model.value = {};
59
- errors.value = {};
60
- submitError.value = null;
61
- submitted.value = false;
62
- }
63
-
64
- async function submit() {
65
- submitted.value = true;
66
-
67
- // 1. Zod validation (if schema provided)
68
- if (schema) {
69
- const result = schema.safeParse(model.value);
70
-
71
- if (!result.success) {
72
- const fieldErrors = result.error.flatten().fieldErrors;
73
- errors.value = mergeZodErrors(fieldErrors, errorConfig);
74
- return;
75
- }
76
-
77
- // Clear previous errors on successful validation
78
- errors.value = {};
79
- }
80
-
81
- // 2. Call the underlying composable
82
- loading.value = true;
83
- submitError.value = null;
84
-
85
- try {
86
- // The mutation composable accepts the model as its payload
87
- const composable = composableFn(model.value);
88
-
89
- // Wait for the async data to resolve
90
- if (composable.execute) {
91
- await composable.execute();
92
- }
93
-
94
- const data = composable.data?.value;
95
- const err = composable.error?.value;
96
-
97
- if (err) {
98
- throw err;
99
- }
100
-
101
- onSuccess.value?.(data);
102
- } catch (err) {
103
- submitError.value = err;
104
- onError.value?.(err);
105
- } finally {
106
- loading.value = false;
107
- }
108
- }
109
-
110
- // ── Derived ────────────────────────────────────────────────────────────────
111
-
112
- const isValid = computed(() => {
113
- if (!schema) return true;
114
- return schema.safeParse(model.value).success;
115
- });
116
-
117
- const hasErrors = computed(() => Object.keys(errors.value).length > 0);
118
-
119
- return {
120
- // State
121
- model,
122
- errors,
123
- loading,
124
- submitError,
125
- submitted,
126
- isValid,
127
- hasErrors,
128
- fields: computed(() => fields),
129
-
130
- // Callbacks (developer-assignable)
131
- onSuccess,
132
- onError,
133
-
134
- // Actions
135
- submit,
136
- reset,
137
- setValues,
138
- };
139
- }
1
+ // @ts-nocheck - This file runs in user's Nuxt project with different TypeScript config
2
+ /**
3
+ * useFormConnector — Runtime connector for create/update form endpoints.
4
+ *
5
+ * Responsibilities:
6
+ * - Hold the reactive form model
7
+ * - Validate with a Zod schema (generated at code-gen time) on submit
8
+ * - Merge Zod error messages with per-field overrides from config
9
+ * - Submit the validated data via the provided useAsyncData composable
10
+ * - Optionally pre-fill from a useDetailConnector (loadWith option)
11
+ *
12
+ * Copied to the user's project alongside the generated connectors.
13
+ */
14
+ import { ref, computed, watch } from 'vue';
15
+ import { mergeZodErrors } from './zod-error-merger.js';
16
+
17
+ /**
18
+ * @param composableFn The generated mutation composable, e.g. useAsyncDataCreatePet
19
+ * @param options { schema, fields, loadWith?, errorConfig? }
20
+ */
21
+ export function useFormConnector(composableFn, options = {}) {
22
+ const { schema: baseSchema, schemaOverride, fields = [], loadWith = null, errorConfig = {} } = options;
23
+
24
+ // Resolve the active schema:
25
+ // schemaOverride(base) — extend or refine the generated schema
26
+ // schemaOverride — replace the generated schema entirely
27
+ // baseSchema — the generated schema unchanged (default)
28
+ const schema = schemaOverride
29
+ ? (typeof schemaOverride === 'function' ? schemaOverride(baseSchema) : schemaOverride)
30
+ : baseSchema;
31
+
32
+ // ── Form state ─────────────────────────────────────────────────────────────
33
+
34
+ const model = ref({});
35
+ const errors = ref({});
36
+ const loading = ref(false);
37
+ const submitError = ref(null);
38
+ const submitted = ref(false);
39
+
40
+ // Callbacks — set by the developer or the generated component
41
+ const onSuccess = ref(null);
42
+ const onError = ref(null);
43
+
44
+ // ── Pre-fill from detail connector ────────────────────────────────────────
45
+
46
+ if (loadWith) {
47
+ // When the detail item changes (e.g. user clicks "Edit"), pre-fill the model
48
+ watch(
49
+ () => loadWith.item?.value,
50
+ (newItem) => {
51
+ if (newItem) {
52
+ setValues(newItem);
53
+ }
54
+ },
55
+ { immediate: true }
56
+ );
57
+ }
58
+
59
+ // ── Actions ────────────────────────────────────────────────────────────────
60
+
61
+ function setValues(data) {
62
+ model.value = { ...model.value, ...data };
63
+ }
64
+
65
+ function reset() {
66
+ model.value = {};
67
+ errors.value = {};
68
+ submitError.value = null;
69
+ submitted.value = false;
70
+ }
71
+
72
+ async function submit() {
73
+ submitted.value = true;
74
+
75
+ // 1. Zod validation (if schema provided)
76
+ if (schema) {
77
+ const result = schema.safeParse(model.value);
78
+
79
+ if (!result.success) {
80
+ const fieldErrors = result.error.flatten().fieldErrors;
81
+ errors.value = mergeZodErrors(fieldErrors, errorConfig);
82
+ return;
83
+ }
84
+
85
+ // Clear previous errors on successful validation
86
+ errors.value = {};
87
+ }
88
+
89
+ // 2. Call the underlying composable
90
+ loading.value = true;
91
+ submitError.value = null;
92
+
93
+ try {
94
+ // The mutation composable accepts the model as its payload
95
+ const composable = composableFn(model.value);
96
+
97
+ // Wait for the async data to resolve
98
+ if (composable.execute) {
99
+ await composable.execute();
100
+ }
101
+
102
+ const data = composable.data?.value;
103
+ const err = composable.error?.value;
104
+
105
+ if (err) {
106
+ throw err;
107
+ }
108
+
109
+ onSuccess.value?.(data);
110
+ } catch (err) {
111
+ submitError.value = err;
112
+ onError.value?.(err);
113
+ } finally {
114
+ loading.value = false;
115
+ }
116
+ }
117
+
118
+ // ── Derived ────────────────────────────────────────────────────────────────
119
+
120
+ const isValid = computed(() => {
121
+ if (!schema) return true;
122
+ return schema.safeParse(model.value).success;
123
+ });
124
+
125
+ const hasErrors = computed(() => Object.keys(errors.value).length > 0);
126
+
127
+ return {
128
+ // State
129
+ model,
130
+ errors,
131
+ loading,
132
+ submitError,
133
+ submitted,
134
+ isValid,
135
+ hasErrors,
136
+ fields: computed(() => fields),
137
+
138
+ // Callbacks (developer-assignable)
139
+ onSuccess,
140
+ onError,
141
+
142
+ // Actions
143
+ submit,
144
+ reset,
145
+ setValues,
146
+ };
147
+ }