@carlonicora/nextjs-jsonapi 1.16.0 → 1.18.0

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 (202) hide show
  1. package/README.md +1 -1
  2. package/dist/ApiData-DPKNfY-9.d.mts +10 -0
  3. package/dist/ApiData-DPKNfY-9.d.ts +10 -0
  4. package/dist/ApiRequestDataTypeInterface-DIEOFn9s.d.mts +40 -0
  5. package/dist/ApiRequestDataTypeInterface-DIEOFn9s.d.ts +40 -0
  6. package/dist/{ApiResponseInterface-BvWIeLkq.d.ts → ApiResponseInterface-BKyod24U.d.ts} +2 -11
  7. package/dist/{ApiResponseInterface-CAbw0sv7.d.mts → ApiResponseInterface-Dqvu09tz.d.mts} +2 -11
  8. package/dist/{BlockNoteEditor-HFX7Z5BQ.mjs → BlockNoteEditor-6TWTNHNZ.mjs} +7 -6
  9. package/dist/{BlockNoteEditor-HFX7Z5BQ.mjs.map → BlockNoteEditor-6TWTNHNZ.mjs.map} +1 -1
  10. package/dist/{BlockNoteEditor-MBFDWP7X.js → BlockNoteEditor-C3WWGGT6.js} +17 -16
  11. package/dist/BlockNoteEditor-C3WWGGT6.js.map +1 -0
  12. package/dist/JsonApiContext-Bsm_Q2oe.d.mts +41 -0
  13. package/dist/JsonApiContext-Bsm_Q2oe.d.ts +41 -0
  14. package/dist/JsonApiRequest-54ZBO7WQ.js +24 -0
  15. package/dist/{JsonApiRequest-45CLE65I.js.map → JsonApiRequest-54ZBO7WQ.js.map} +1 -1
  16. package/dist/{JsonApiRequest-6IPS3DZJ.mjs → JsonApiRequest-XWQWTFEQ.mjs} +2 -2
  17. package/dist/chunk-3EPNHTMH.js +26 -0
  18. package/dist/chunk-3EPNHTMH.js.map +1 -0
  19. package/dist/{chunk-BCKYJQ3K.mjs → chunk-3VM3WAOV.mjs} +1 -1
  20. package/dist/{chunk-ONB2DAIV.js → chunk-6U6QCSJK.js} +4224 -2775
  21. package/dist/chunk-6U6QCSJK.js.map +1 -0
  22. package/dist/{chunk-R5QSSISB.js → chunk-7DTKRMYW.js} +21 -14
  23. package/dist/chunk-7DTKRMYW.js.map +1 -0
  24. package/dist/{chunk-BCQSE3EU.mjs → chunk-KUFWHMMY.mjs} +8 -8
  25. package/dist/{chunk-POKIJ56Q.mjs → chunk-KX7YG6LY.mjs} +22 -15
  26. package/dist/chunk-KX7YG6LY.mjs.map +1 -0
  27. package/dist/{chunk-GPGJNTHP.js → chunk-LI6CPNJI.js} +1 -1
  28. package/dist/{chunk-GPGJNTHP.js.map → chunk-LI6CPNJI.js.map} +1 -1
  29. package/dist/{chunk-2AZLCF6D.js → chunk-UYY34W7R.js} +28 -28
  30. package/dist/{chunk-2AZLCF6D.js.map → chunk-UYY34W7R.js.map} +1 -1
  31. package/dist/{chunk-5RAUCUAA.mjs → chunk-UZDAPWJG.mjs} +5645 -4196
  32. package/dist/chunk-UZDAPWJG.mjs.map +1 -0
  33. package/dist/chunk-VOXD3ZLY.mjs +26 -0
  34. package/dist/chunk-VOXD3ZLY.mjs.map +1 -0
  35. package/dist/client/index.d.mts +11 -45
  36. package/dist/client/index.d.ts +11 -45
  37. package/dist/client/index.js +9 -7
  38. package/dist/client/index.js.map +1 -1
  39. package/dist/client/index.mjs +11 -9
  40. package/dist/components/index.d.mts +302 -388
  41. package/dist/components/index.d.ts +302 -388
  42. package/dist/components/index.js +31 -6
  43. package/dist/components/index.js.map +1 -1
  44. package/dist/components/index.mjs +40 -15
  45. package/dist/{config-DEaUbBqR.d.ts → config--nwiW74Z.d.ts} +1 -1
  46. package/dist/{config-CWsTwnsK.d.mts → config-BKSQmUWU.d.mts} +1 -1
  47. package/dist/{content.interface-D_4b4RQt.d.ts → content.interface-4VICFRA0.d.ts} +2 -1
  48. package/dist/{content.interface-Dk4UZcJM.d.mts → content.interface-CFc97-Cj.d.mts} +2 -1
  49. package/dist/contexts/index.d.mts +3 -2
  50. package/dist/contexts/index.d.ts +3 -2
  51. package/dist/contexts/index.js +7 -6
  52. package/dist/contexts/index.js.map +1 -1
  53. package/dist/contexts/index.mjs +6 -5
  54. package/dist/core/index.d.mts +11 -8
  55. package/dist/core/index.d.ts +11 -8
  56. package/dist/core/index.js +4 -4
  57. package/dist/core/index.js.map +1 -1
  58. package/dist/core/index.mjs +3 -3
  59. package/dist/index.d.mts +15 -11
  60. package/dist/index.d.ts +15 -11
  61. package/dist/index.js +5 -5
  62. package/dist/index.js.map +1 -1
  63. package/dist/index.mjs +6 -6
  64. package/dist/{notification.interface-BllkURRm.d.ts → notification.interface-BGaPiCUM.d.mts} +2 -40
  65. package/dist/{notification.interface-BllkURRm.d.mts → notification.interface-CqwaOIgM.d.ts} +2 -40
  66. package/dist/{s3.service-BEfGqho0.d.ts → s3.service-BYs88XEE.d.ts} +3 -2
  67. package/dist/{s3.service-DIQRYe93.d.mts → s3.service-C0BjOdvn.d.mts} +3 -2
  68. package/dist/scripts/generate-web-module/templates/components/editor.template.d.ts.map +1 -1
  69. package/dist/scripts/generate-web-module/templates/components/editor.template.js +20 -6
  70. package/dist/scripts/generate-web-module/templates/components/editor.template.js.map +1 -1
  71. package/dist/scripts/generate-web-module/templates/components/selector.template.d.ts.map +1 -1
  72. package/dist/scripts/generate-web-module/templates/components/selector.template.js +45 -48
  73. package/dist/scripts/generate-web-module/templates/components/selector.template.js.map +1 -1
  74. package/dist/server/index.d.mts +6 -4
  75. package/dist/server/index.d.ts +6 -4
  76. package/dist/server/index.js +13 -13
  77. package/dist/server/index.js.map +1 -1
  78. package/dist/server/index.mjs +3 -3
  79. package/dist/{stripe-subscription.interface-C63L6hVg.d.mts → stripe-subscription.interface-B-TM40Io.d.ts} +1 -1
  80. package/dist/{stripe-subscription.interface-CUvNDvw5.d.ts → stripe-subscription.interface-DDxnpj0F.d.mts} +1 -1
  81. package/dist/testing/index.d.mts +338 -0
  82. package/dist/testing/index.d.ts +338 -0
  83. package/dist/testing/index.js +323 -0
  84. package/dist/testing/index.js.map +1 -0
  85. package/dist/testing/index.mjs +323 -0
  86. package/dist/testing/index.mjs.map +1 -0
  87. package/dist/{useSocket-BpenBR2z.d.mts → useSocket-BNj9PrRw.d.mts} +1 -1
  88. package/dist/{useSocket-D-QYA0Sr.d.ts → useSocket-Dwt8cz1x.d.ts} +1 -1
  89. package/package.json +26 -27
  90. package/scripts/generate-web-module/templates/components/editor.template.ts +20 -6
  91. package/scripts/generate-web-module/templates/components/selector.template.ts +45 -48
  92. package/src/client/hooks/__tests__/useJsonApiGet.test.tsx +229 -0
  93. package/src/client/hooks/__tests__/useJsonApiMutation.test.tsx +348 -0
  94. package/src/client/hooks/__tests__/useRehydration.test.ts +188 -0
  95. package/src/components/forms/CommonDeleter.tsx +2 -2
  96. package/src/components/forms/CommonEditorTrigger.tsx +3 -3
  97. package/src/components/forms/DatePickerPopover.tsx +3 -1
  98. package/src/components/forms/DateRangeSelector.tsx +1 -1
  99. package/src/components/forms/FormCheckbox.tsx +1 -1
  100. package/src/components/forms/FormDate.tsx +3 -1
  101. package/src/components/forms/FormDateTime.tsx +5 -3
  102. package/src/components/forms/FormSelect.tsx +1 -1
  103. package/src/components/forms/FormSlider.tsx +4 -1
  104. package/src/components/forms/__tests__/FormCheckbox.test.tsx +242 -0
  105. package/src/components/forms/__tests__/FormDate.test.tsx +216 -0
  106. package/src/components/forms/__tests__/FormInput.test.tsx +292 -0
  107. package/src/components/forms/__tests__/FormSelect.test.tsx +177 -0
  108. package/src/components/navigations/RecentPagesNavigator.tsx +2 -2
  109. package/src/components/tables/ContentListTable.tsx +3 -3
  110. package/src/components/tables/__tests__/ContentListTable.test.tsx +411 -0
  111. package/src/core/endpoint/__tests__/EndpointCreator.test.ts +168 -0
  112. package/src/core/factories/__tests__/JsonApiDataFactory.test.ts +109 -0
  113. package/src/core/factories/__tests__/RehydrationFactory.test.ts +151 -0
  114. package/src/core/registry/__tests__/DataClassRegistry.test.ts +136 -0
  115. package/src/core/registry/__tests__/ModuleRegistrar.test.ts +159 -0
  116. package/src/features/auth/components/details/LandingComponent.tsx +14 -12
  117. package/src/features/billing/stripe-customer/components/details/PaymentMethodCard.tsx +2 -2
  118. package/src/features/company/components/forms/CompanyConfigurationEditor.tsx +2 -2
  119. package/src/features/company/components/forms/CompanyDeleter.tsx +1 -1
  120. package/src/features/content/components/lists/ContentsList.tsx +1 -1
  121. package/src/features/notification/components/lists/NotificationsList.tsx +1 -1
  122. package/src/features/notification/components/modals/NotificationModal.tsx +2 -2
  123. package/src/features/role/components/forms/FormRoles.tsx +1 -1
  124. package/src/features/user/components/forms/UserEditor.tsx +2 -2
  125. package/src/features/user/components/forms/UserReactivator.tsx +1 -1
  126. package/src/features/user/components/forms/UserResentInvitationEmail.tsx +2 -2
  127. package/src/features/user/components/widgets/UserAvatar.tsx +37 -31
  128. package/src/features/user/components/widgets/UserSearchPopover.tsx +1 -1
  129. package/src/hooks/__tests__/useDataListRetriever.test.ts +321 -0
  130. package/src/hooks/__tests__/useDebounce.test.ts +170 -0
  131. package/src/hooks/use-mobile.ts +1 -0
  132. package/src/index.ts +4 -1
  133. package/src/lib/utils.ts +2 -0
  134. package/src/login/config.ts +27 -0
  135. package/src/login/index.ts +2 -0
  136. package/src/shadcnui/custom/multi-select.tsx +10 -21
  137. package/src/shadcnui/ui/accordion.tsx +64 -42
  138. package/src/shadcnui/ui/alert-dialog.tsx +142 -108
  139. package/src/shadcnui/ui/alert.tsx +64 -35
  140. package/src/shadcnui/ui/avatar.tsx +106 -50
  141. package/src/shadcnui/ui/badge.tsx +34 -26
  142. package/src/shadcnui/ui/breadcrumb.tsx +103 -92
  143. package/src/shadcnui/ui/button.tsx +30 -30
  144. package/src/shadcnui/ui/calendar.tsx +192 -50
  145. package/src/shadcnui/ui/card.tsx +94 -43
  146. package/src/shadcnui/ui/carousel.tsx +220 -201
  147. package/src/shadcnui/ui/chart.tsx +244 -190
  148. package/src/shadcnui/ui/checkbox.tsx +25 -25
  149. package/src/shadcnui/ui/collapsible.tsx +10 -4
  150. package/src/shadcnui/ui/combobox.tsx +292 -0
  151. package/src/shadcnui/ui/command.tsx +158 -126
  152. package/src/shadcnui/ui/context-menu.tsx +242 -164
  153. package/src/shadcnui/ui/dialog.tsx +125 -70
  154. package/src/shadcnui/ui/drawer.tsx +106 -70
  155. package/src/shadcnui/ui/dropdown-menu.tsx +231 -182
  156. package/src/shadcnui/ui/field.tsx +227 -0
  157. package/src/shadcnui/ui/hover-card.tsx +45 -23
  158. package/src/shadcnui/ui/input-group.tsx +149 -0
  159. package/src/shadcnui/ui/input-otp.tsx +19 -9
  160. package/src/shadcnui/ui/input.tsx +4 -5
  161. package/src/shadcnui/ui/label.tsx +16 -22
  162. package/src/shadcnui/ui/navigation-menu.tsx +44 -49
  163. package/src/shadcnui/ui/popover.tsx +81 -24
  164. package/src/shadcnui/ui/progress.tsx +77 -22
  165. package/src/shadcnui/ui/radio-group.tsx +30 -28
  166. package/src/shadcnui/ui/resizable.tsx +23 -17
  167. package/src/shadcnui/ui/scroll-area.tsx +50 -35
  168. package/src/shadcnui/ui/select.tsx +163 -135
  169. package/src/shadcnui/ui/separator.tsx +5 -8
  170. package/src/shadcnui/ui/sheet.tsx +40 -50
  171. package/src/shadcnui/ui/sidebar.tsx +317 -271
  172. package/src/shadcnui/ui/skeleton.tsx +2 -2
  173. package/src/shadcnui/ui/slider.tsx +60 -21
  174. package/src/shadcnui/ui/sonner.tsx +25 -1
  175. package/src/shadcnui/ui/switch.tsx +31 -24
  176. package/src/shadcnui/ui/table.tsx +84 -103
  177. package/src/shadcnui/ui/tabs.tsx +82 -55
  178. package/src/shadcnui/ui/textarea.tsx +15 -21
  179. package/src/shadcnui/ui/toggle.tsx +26 -21
  180. package/src/shadcnui/ui/tooltip.tsx +33 -24
  181. package/src/testing/factories/createMockApiData.ts +143 -0
  182. package/src/testing/factories/createMockModule.ts +32 -0
  183. package/src/testing/factories/createMockResponse.ts +88 -0
  184. package/src/testing/factories/createMockService.ts +76 -0
  185. package/src/testing/index.ts +56 -0
  186. package/src/testing/matchers/jsonApiMatchers.ts +172 -0
  187. package/src/testing/providers/MockJsonApiProvider.tsx +58 -0
  188. package/src/testing/utils/renderWithProviders.tsx +76 -0
  189. package/src/utils/__tests__/date-formatter.test.ts +161 -0
  190. package/src/utils/__tests__/exists.test.ts +100 -0
  191. package/src/utils/cn.test.ts +44 -0
  192. package/dist/BlockNoteEditor-MBFDWP7X.js.map +0 -1
  193. package/dist/JsonApiRequest-45CLE65I.js +0 -24
  194. package/dist/chunk-5RAUCUAA.mjs.map +0 -1
  195. package/dist/chunk-ONB2DAIV.js.map +0 -1
  196. package/dist/chunk-POKIJ56Q.mjs.map +0 -1
  197. package/dist/chunk-R5QSSISB.js.map +0 -1
  198. package/src/discord/config.ts +0 -15
  199. package/src/discord/index.ts +0 -1
  200. /package/dist/{JsonApiRequest-6IPS3DZJ.mjs.map → JsonApiRequest-XWQWTFEQ.mjs.map} +0 -0
  201. /package/dist/{chunk-BCKYJQ3K.mjs.map → chunk-3VM3WAOV.mjs.map} +0 -0
  202. /package/dist/{chunk-BCQSE3EU.mjs.map → chunk-KUFWHMMY.mjs.map} +0 -0
@@ -0,0 +1,338 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React__default, { ReactElement } from 'react';
3
+ import { J as JsonApiConfig } from '../JsonApiContext-Bsm_Q2oe.mjs';
4
+ import { a as ApiRequestDataTypeInterface, A as ApiDataInterface } from '../ApiRequestDataTypeInterface-DIEOFn9s.mjs';
5
+ import { A as ApiResponseInterface } from '../ApiResponseInterface-Dqvu09tz.mjs';
6
+ import { Mock } from 'vitest';
7
+ import { RenderOptions, RenderResult } from '@testing-library/react';
8
+ export { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
9
+ export { userEvent } from '@testing-library/user-event';
10
+
11
+ interface MockJsonApiProviderProps {
12
+ children: React__default.ReactNode;
13
+ config?: Partial<JsonApiConfig>;
14
+ }
15
+ declare const defaultMockConfig: JsonApiConfig;
16
+ /**
17
+ * A test-friendly provider that wraps components with mock JSON:API context.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * import { MockJsonApiProvider } from '@carlonicora/nextjs-jsonapi/testing';
22
+ *
23
+ * render(
24
+ * <MockJsonApiProvider>
25
+ * <MyComponent />
26
+ * </MockJsonApiProvider>
27
+ * );
28
+ * ```
29
+ *
30
+ * @example With custom config
31
+ * ```tsx
32
+ * render(
33
+ * <MockJsonApiProvider config={{ apiUrl: 'https://custom.api.com' }}>
34
+ * <MyComponent />
35
+ * </MockJsonApiProvider>
36
+ * );
37
+ * ```
38
+ */
39
+ declare function MockJsonApiProvider({ children, config }: MockJsonApiProviderProps): react_jsx_runtime.JSX.Element;
40
+
41
+ interface CreateMockModuleOptions {
42
+ name: string;
43
+ cache?: string;
44
+ inclusions?: ApiRequestDataTypeInterface["inclusions"];
45
+ }
46
+ /**
47
+ * Creates a mock module definition for testing.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { createMockModule } from '@carlonicora/nextjs-jsonapi/testing';
52
+ *
53
+ * const mockArticleModule = createMockModule({ name: 'articles' });
54
+ * ```
55
+ */
56
+ declare function createMockModule(options: CreateMockModuleOptions): ApiRequestDataTypeInterface;
57
+
58
+ interface CreateMockResponseOptions {
59
+ data?: ApiDataInterface | ApiDataInterface[] | null;
60
+ ok?: boolean;
61
+ response?: number;
62
+ error?: string;
63
+ meta?: Record<string, any>;
64
+ self?: string;
65
+ next?: string;
66
+ prev?: string;
67
+ }
68
+ /**
69
+ * Creates a mock API response for testing.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import { createMockResponse, createMockApiData } from '@carlonicora/nextjs-jsonapi/testing';
74
+ *
75
+ * const mockData = createMockApiData({ type: 'articles', id: '1' });
76
+ * const response = createMockResponse({ data: mockData, ok: true });
77
+ * ```
78
+ *
79
+ * @example With pagination
80
+ * ```ts
81
+ * const response = createMockResponse({
82
+ * data: [mockData],
83
+ * ok: true,
84
+ * next: '/articles?page=2',
85
+ * prev: '/articles?page=0',
86
+ * });
87
+ * ```
88
+ */
89
+ declare function createMockResponse(options?: CreateMockResponseOptions): ApiResponseInterface;
90
+ /**
91
+ * Creates a mock error response for testing error scenarios.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import { createMockErrorResponse } from '@carlonicora/nextjs-jsonapi/testing';
96
+ *
97
+ * const errorResponse = createMockErrorResponse(404, 'Not Found');
98
+ * ```
99
+ */
100
+ declare function createMockErrorResponse(statusCode: number, errorMessage: string): ApiResponseInterface;
101
+
102
+ type MockApiMethod = Mock<(...args: any[]) => Promise<ApiResponseInterface>>;
103
+ interface MockService {
104
+ get: MockApiMethod;
105
+ post: MockApiMethod;
106
+ put: MockApiMethod;
107
+ patch: MockApiMethod;
108
+ delete: MockApiMethod;
109
+ }
110
+ interface CreateMockServiceOptions {
111
+ defaultResponse?: ApiResponseInterface;
112
+ }
113
+ /**
114
+ * Creates a mock service with Vitest mock functions for all HTTP methods.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { createMockService, createMockResponse } from '@carlonicora/nextjs-jsonapi/testing';
119
+ *
120
+ * const mockService = createMockService();
121
+ * mockService.get.mockResolvedValue(createMockResponse({ data: mockData }));
122
+ *
123
+ * // Use in test
124
+ * expect(mockService.get).toHaveBeenCalled();
125
+ * ```
126
+ *
127
+ * @example With default response
128
+ * ```ts
129
+ * const mockService = createMockService({
130
+ * defaultResponse: createMockResponse({ ok: true, data: [] }),
131
+ * });
132
+ * ```
133
+ */
134
+ declare function createMockService(options?: CreateMockServiceOptions): MockService;
135
+ /**
136
+ * Creates a mock service that returns errors for all methods.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * import { createMockErrorService } from '@carlonicora/nextjs-jsonapi/testing';
141
+ *
142
+ * const errorService = createMockErrorService(500, 'Internal Server Error');
143
+ * ```
144
+ */
145
+ declare function createMockErrorService(statusCode?: number, errorMessage?: string): MockService;
146
+
147
+ interface CreateMockApiDataOptions {
148
+ type: string;
149
+ id?: string;
150
+ attributes?: Record<string, any>;
151
+ relationships?: Record<string, any>;
152
+ included?: any[];
153
+ createdAt?: Date;
154
+ updatedAt?: Date;
155
+ self?: string;
156
+ }
157
+ /**
158
+ * Creates a mock ApiDataInterface object for testing.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * import { createMockApiData } from '@carlonicora/nextjs-jsonapi/testing';
163
+ *
164
+ * const mockArticle = createMockApiData({
165
+ * type: 'articles',
166
+ * id: '1',
167
+ * attributes: { title: 'Test Article', body: 'Content here' },
168
+ * });
169
+ * ```
170
+ *
171
+ * @example With relationships
172
+ * ```ts
173
+ * const mockArticle = createMockApiData({
174
+ * type: 'articles',
175
+ * id: '1',
176
+ * attributes: { title: 'Test' },
177
+ * relationships: {
178
+ * author: { data: { type: 'users', id: '42' } },
179
+ * },
180
+ * });
181
+ * ```
182
+ */
183
+ declare function createMockApiData(options: CreateMockApiDataOptions): ApiDataInterface;
184
+ /**
185
+ * Creates an array of mock ApiDataInterface objects.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * import { createMockApiDataList } from '@carlonicora/nextjs-jsonapi/testing';
190
+ *
191
+ * const mockArticles = createMockApiDataList('articles', 5, (index) => ({
192
+ * title: `Article ${index + 1}`,
193
+ * }));
194
+ * ```
195
+ */
196
+ declare function createMockApiDataList(type: string, count: number, attributesFactory?: (index: number) => Record<string, any>): ApiDataInterface[];
197
+
198
+ interface JsonApiResponse {
199
+ data?: {
200
+ type?: string;
201
+ id?: string;
202
+ attributes?: Record<string, any>;
203
+ relationships?: Record<string, any>;
204
+ } | Array<{
205
+ type?: string;
206
+ id?: string;
207
+ attributes?: Record<string, any>;
208
+ relationships?: Record<string, any>;
209
+ }>;
210
+ }
211
+ /**
212
+ * Custom Vitest matchers for JSON:API assertions.
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * import { jsonApiMatchers } from '@carlonicora/nextjs-jsonapi/testing';
217
+ * import { expect } from 'vitest';
218
+ *
219
+ * expect.extend(jsonApiMatchers);
220
+ *
221
+ * // Then use in tests:
222
+ * expect(response).toBeValidJsonApi();
223
+ * expect(response).toHaveJsonApiType('articles');
224
+ * expect(response).toHaveJsonApiAttribute('title', 'My Article');
225
+ * expect(response).toHaveJsonApiRelationship('author');
226
+ * ```
227
+ */
228
+ declare const jsonApiMatchers: {
229
+ /**
230
+ * Asserts that the response has a valid JSON:API structure with type and id.
231
+ */
232
+ toBeValidJsonApi(received: JsonApiResponse): {
233
+ pass: boolean;
234
+ message: () => string;
235
+ };
236
+ /**
237
+ * Asserts that the response data has the expected JSON:API type.
238
+ */
239
+ toHaveJsonApiType(received: JsonApiResponse, expectedType: string): {
240
+ pass: boolean;
241
+ message: () => string;
242
+ };
243
+ /**
244
+ * Asserts that the response data has an attribute with the expected value.
245
+ */
246
+ toHaveJsonApiAttribute(received: JsonApiResponse, attributeName: string, expectedValue?: any): {
247
+ pass: boolean;
248
+ message: () => string;
249
+ };
250
+ /**
251
+ * Asserts that the response data has the specified relationship.
252
+ */
253
+ toHaveJsonApiRelationship(received: JsonApiResponse, relationshipName: string): {
254
+ pass: boolean;
255
+ message: () => string;
256
+ };
257
+ /**
258
+ * Asserts that the response data array has the expected length.
259
+ */
260
+ toHaveJsonApiLength(received: JsonApiResponse, expectedLength: number): {
261
+ pass: boolean;
262
+ message: () => string;
263
+ };
264
+ };
265
+ declare module "vitest" {
266
+ interface Assertion<T = any> {
267
+ toBeValidJsonApi(): T;
268
+ toHaveJsonApiType(expectedType: string): T;
269
+ toHaveJsonApiAttribute(attributeName: string, expectedValue?: any): T;
270
+ toHaveJsonApiRelationship(relationshipName: string): T;
271
+ toHaveJsonApiLength(expectedLength: number): T;
272
+ }
273
+ interface AsymmetricMatchersContaining {
274
+ toBeValidJsonApi(): any;
275
+ toHaveJsonApiType(expectedType: string): any;
276
+ toHaveJsonApiAttribute(attributeName: string, expectedValue?: any): any;
277
+ toHaveJsonApiRelationship(relationshipName: string): any;
278
+ toHaveJsonApiLength(expectedLength: number): any;
279
+ }
280
+ }
281
+ /**
282
+ * Extends Vitest's expect with JSON:API matchers.
283
+ * Call this in your test setup file.
284
+ *
285
+ * @example
286
+ * ```ts
287
+ * // vitest.setup.ts
288
+ * import { extendExpectWithJsonApiMatchers } from '@carlonicora/nextjs-jsonapi/testing';
289
+ *
290
+ * extendExpectWithJsonApiMatchers();
291
+ * ```
292
+ */
293
+ declare function extendExpectWithJsonApiMatchers(): void;
294
+
295
+ interface RenderWithProvidersOptions extends Omit<RenderOptions, "wrapper"> {
296
+ /**
297
+ * Custom JSON:API configuration to pass to the mock provider.
298
+ */
299
+ jsonApiConfig?: Partial<JsonApiConfig>;
300
+ /**
301
+ * Additional wrapper component to wrap around the providers.
302
+ */
303
+ wrapper?: React__default.ComponentType<{
304
+ children: React__default.ReactNode;
305
+ }>;
306
+ }
307
+ /**
308
+ * Renders a component wrapped with all necessary providers for testing.
309
+ *
310
+ * @example
311
+ * ```tsx
312
+ * import { renderWithProviders } from '@carlonicora/nextjs-jsonapi/testing';
313
+ *
314
+ * const { getByText } = renderWithProviders(<MyComponent />);
315
+ * expect(getByText('Hello')).toBeInTheDocument();
316
+ * ```
317
+ *
318
+ * @example With custom config
319
+ * ```tsx
320
+ * const { getByText } = renderWithProviders(<MyComponent />, {
321
+ * jsonApiConfig: { apiUrl: 'https://custom.api.com' },
322
+ * });
323
+ * ```
324
+ *
325
+ * @example With additional wrapper
326
+ * ```tsx
327
+ * const CustomWrapper = ({ children }) => (
328
+ * <ThemeProvider>{children}</ThemeProvider>
329
+ * );
330
+ *
331
+ * const { getByText } = renderWithProviders(<MyComponent />, {
332
+ * wrapper: CustomWrapper,
333
+ * });
334
+ * ```
335
+ */
336
+ declare function renderWithProviders(ui: ReactElement, options?: RenderWithProvidersOptions): RenderResult;
337
+
338
+ export { type CreateMockApiDataOptions, type CreateMockModuleOptions, type CreateMockResponseOptions, type CreateMockServiceOptions, type MockApiMethod, MockJsonApiProvider, type MockJsonApiProviderProps, type MockService, type RenderWithProvidersOptions, createMockApiData, createMockApiDataList, createMockErrorResponse, createMockErrorService, createMockModule, createMockResponse, createMockService, defaultMockConfig, extendExpectWithJsonApiMatchers, jsonApiMatchers, renderWithProviders };
@@ -0,0 +1,338 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React__default, { ReactElement } from 'react';
3
+ import { J as JsonApiConfig } from '../JsonApiContext-Bsm_Q2oe.js';
4
+ import { a as ApiRequestDataTypeInterface, A as ApiDataInterface } from '../ApiRequestDataTypeInterface-DIEOFn9s.js';
5
+ import { A as ApiResponseInterface } from '../ApiResponseInterface-BKyod24U.js';
6
+ import { Mock } from 'vitest';
7
+ import { RenderOptions, RenderResult } from '@testing-library/react';
8
+ export { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
9
+ export { userEvent } from '@testing-library/user-event';
10
+
11
+ interface MockJsonApiProviderProps {
12
+ children: React__default.ReactNode;
13
+ config?: Partial<JsonApiConfig>;
14
+ }
15
+ declare const defaultMockConfig: JsonApiConfig;
16
+ /**
17
+ * A test-friendly provider that wraps components with mock JSON:API context.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * import { MockJsonApiProvider } from '@carlonicora/nextjs-jsonapi/testing';
22
+ *
23
+ * render(
24
+ * <MockJsonApiProvider>
25
+ * <MyComponent />
26
+ * </MockJsonApiProvider>
27
+ * );
28
+ * ```
29
+ *
30
+ * @example With custom config
31
+ * ```tsx
32
+ * render(
33
+ * <MockJsonApiProvider config={{ apiUrl: 'https://custom.api.com' }}>
34
+ * <MyComponent />
35
+ * </MockJsonApiProvider>
36
+ * );
37
+ * ```
38
+ */
39
+ declare function MockJsonApiProvider({ children, config }: MockJsonApiProviderProps): react_jsx_runtime.JSX.Element;
40
+
41
+ interface CreateMockModuleOptions {
42
+ name: string;
43
+ cache?: string;
44
+ inclusions?: ApiRequestDataTypeInterface["inclusions"];
45
+ }
46
+ /**
47
+ * Creates a mock module definition for testing.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { createMockModule } from '@carlonicora/nextjs-jsonapi/testing';
52
+ *
53
+ * const mockArticleModule = createMockModule({ name: 'articles' });
54
+ * ```
55
+ */
56
+ declare function createMockModule(options: CreateMockModuleOptions): ApiRequestDataTypeInterface;
57
+
58
+ interface CreateMockResponseOptions {
59
+ data?: ApiDataInterface | ApiDataInterface[] | null;
60
+ ok?: boolean;
61
+ response?: number;
62
+ error?: string;
63
+ meta?: Record<string, any>;
64
+ self?: string;
65
+ next?: string;
66
+ prev?: string;
67
+ }
68
+ /**
69
+ * Creates a mock API response for testing.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import { createMockResponse, createMockApiData } from '@carlonicora/nextjs-jsonapi/testing';
74
+ *
75
+ * const mockData = createMockApiData({ type: 'articles', id: '1' });
76
+ * const response = createMockResponse({ data: mockData, ok: true });
77
+ * ```
78
+ *
79
+ * @example With pagination
80
+ * ```ts
81
+ * const response = createMockResponse({
82
+ * data: [mockData],
83
+ * ok: true,
84
+ * next: '/articles?page=2',
85
+ * prev: '/articles?page=0',
86
+ * });
87
+ * ```
88
+ */
89
+ declare function createMockResponse(options?: CreateMockResponseOptions): ApiResponseInterface;
90
+ /**
91
+ * Creates a mock error response for testing error scenarios.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import { createMockErrorResponse } from '@carlonicora/nextjs-jsonapi/testing';
96
+ *
97
+ * const errorResponse = createMockErrorResponse(404, 'Not Found');
98
+ * ```
99
+ */
100
+ declare function createMockErrorResponse(statusCode: number, errorMessage: string): ApiResponseInterface;
101
+
102
+ type MockApiMethod = Mock<(...args: any[]) => Promise<ApiResponseInterface>>;
103
+ interface MockService {
104
+ get: MockApiMethod;
105
+ post: MockApiMethod;
106
+ put: MockApiMethod;
107
+ patch: MockApiMethod;
108
+ delete: MockApiMethod;
109
+ }
110
+ interface CreateMockServiceOptions {
111
+ defaultResponse?: ApiResponseInterface;
112
+ }
113
+ /**
114
+ * Creates a mock service with Vitest mock functions for all HTTP methods.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { createMockService, createMockResponse } from '@carlonicora/nextjs-jsonapi/testing';
119
+ *
120
+ * const mockService = createMockService();
121
+ * mockService.get.mockResolvedValue(createMockResponse({ data: mockData }));
122
+ *
123
+ * // Use in test
124
+ * expect(mockService.get).toHaveBeenCalled();
125
+ * ```
126
+ *
127
+ * @example With default response
128
+ * ```ts
129
+ * const mockService = createMockService({
130
+ * defaultResponse: createMockResponse({ ok: true, data: [] }),
131
+ * });
132
+ * ```
133
+ */
134
+ declare function createMockService(options?: CreateMockServiceOptions): MockService;
135
+ /**
136
+ * Creates a mock service that returns errors for all methods.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * import { createMockErrorService } from '@carlonicora/nextjs-jsonapi/testing';
141
+ *
142
+ * const errorService = createMockErrorService(500, 'Internal Server Error');
143
+ * ```
144
+ */
145
+ declare function createMockErrorService(statusCode?: number, errorMessage?: string): MockService;
146
+
147
+ interface CreateMockApiDataOptions {
148
+ type: string;
149
+ id?: string;
150
+ attributes?: Record<string, any>;
151
+ relationships?: Record<string, any>;
152
+ included?: any[];
153
+ createdAt?: Date;
154
+ updatedAt?: Date;
155
+ self?: string;
156
+ }
157
+ /**
158
+ * Creates a mock ApiDataInterface object for testing.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * import { createMockApiData } from '@carlonicora/nextjs-jsonapi/testing';
163
+ *
164
+ * const mockArticle = createMockApiData({
165
+ * type: 'articles',
166
+ * id: '1',
167
+ * attributes: { title: 'Test Article', body: 'Content here' },
168
+ * });
169
+ * ```
170
+ *
171
+ * @example With relationships
172
+ * ```ts
173
+ * const mockArticle = createMockApiData({
174
+ * type: 'articles',
175
+ * id: '1',
176
+ * attributes: { title: 'Test' },
177
+ * relationships: {
178
+ * author: { data: { type: 'users', id: '42' } },
179
+ * },
180
+ * });
181
+ * ```
182
+ */
183
+ declare function createMockApiData(options: CreateMockApiDataOptions): ApiDataInterface;
184
+ /**
185
+ * Creates an array of mock ApiDataInterface objects.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * import { createMockApiDataList } from '@carlonicora/nextjs-jsonapi/testing';
190
+ *
191
+ * const mockArticles = createMockApiDataList('articles', 5, (index) => ({
192
+ * title: `Article ${index + 1}`,
193
+ * }));
194
+ * ```
195
+ */
196
+ declare function createMockApiDataList(type: string, count: number, attributesFactory?: (index: number) => Record<string, any>): ApiDataInterface[];
197
+
198
+ interface JsonApiResponse {
199
+ data?: {
200
+ type?: string;
201
+ id?: string;
202
+ attributes?: Record<string, any>;
203
+ relationships?: Record<string, any>;
204
+ } | Array<{
205
+ type?: string;
206
+ id?: string;
207
+ attributes?: Record<string, any>;
208
+ relationships?: Record<string, any>;
209
+ }>;
210
+ }
211
+ /**
212
+ * Custom Vitest matchers for JSON:API assertions.
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * import { jsonApiMatchers } from '@carlonicora/nextjs-jsonapi/testing';
217
+ * import { expect } from 'vitest';
218
+ *
219
+ * expect.extend(jsonApiMatchers);
220
+ *
221
+ * // Then use in tests:
222
+ * expect(response).toBeValidJsonApi();
223
+ * expect(response).toHaveJsonApiType('articles');
224
+ * expect(response).toHaveJsonApiAttribute('title', 'My Article');
225
+ * expect(response).toHaveJsonApiRelationship('author');
226
+ * ```
227
+ */
228
+ declare const jsonApiMatchers: {
229
+ /**
230
+ * Asserts that the response has a valid JSON:API structure with type and id.
231
+ */
232
+ toBeValidJsonApi(received: JsonApiResponse): {
233
+ pass: boolean;
234
+ message: () => string;
235
+ };
236
+ /**
237
+ * Asserts that the response data has the expected JSON:API type.
238
+ */
239
+ toHaveJsonApiType(received: JsonApiResponse, expectedType: string): {
240
+ pass: boolean;
241
+ message: () => string;
242
+ };
243
+ /**
244
+ * Asserts that the response data has an attribute with the expected value.
245
+ */
246
+ toHaveJsonApiAttribute(received: JsonApiResponse, attributeName: string, expectedValue?: any): {
247
+ pass: boolean;
248
+ message: () => string;
249
+ };
250
+ /**
251
+ * Asserts that the response data has the specified relationship.
252
+ */
253
+ toHaveJsonApiRelationship(received: JsonApiResponse, relationshipName: string): {
254
+ pass: boolean;
255
+ message: () => string;
256
+ };
257
+ /**
258
+ * Asserts that the response data array has the expected length.
259
+ */
260
+ toHaveJsonApiLength(received: JsonApiResponse, expectedLength: number): {
261
+ pass: boolean;
262
+ message: () => string;
263
+ };
264
+ };
265
+ declare module "vitest" {
266
+ interface Assertion<T = any> {
267
+ toBeValidJsonApi(): T;
268
+ toHaveJsonApiType(expectedType: string): T;
269
+ toHaveJsonApiAttribute(attributeName: string, expectedValue?: any): T;
270
+ toHaveJsonApiRelationship(relationshipName: string): T;
271
+ toHaveJsonApiLength(expectedLength: number): T;
272
+ }
273
+ interface AsymmetricMatchersContaining {
274
+ toBeValidJsonApi(): any;
275
+ toHaveJsonApiType(expectedType: string): any;
276
+ toHaveJsonApiAttribute(attributeName: string, expectedValue?: any): any;
277
+ toHaveJsonApiRelationship(relationshipName: string): any;
278
+ toHaveJsonApiLength(expectedLength: number): any;
279
+ }
280
+ }
281
+ /**
282
+ * Extends Vitest's expect with JSON:API matchers.
283
+ * Call this in your test setup file.
284
+ *
285
+ * @example
286
+ * ```ts
287
+ * // vitest.setup.ts
288
+ * import { extendExpectWithJsonApiMatchers } from '@carlonicora/nextjs-jsonapi/testing';
289
+ *
290
+ * extendExpectWithJsonApiMatchers();
291
+ * ```
292
+ */
293
+ declare function extendExpectWithJsonApiMatchers(): void;
294
+
295
+ interface RenderWithProvidersOptions extends Omit<RenderOptions, "wrapper"> {
296
+ /**
297
+ * Custom JSON:API configuration to pass to the mock provider.
298
+ */
299
+ jsonApiConfig?: Partial<JsonApiConfig>;
300
+ /**
301
+ * Additional wrapper component to wrap around the providers.
302
+ */
303
+ wrapper?: React__default.ComponentType<{
304
+ children: React__default.ReactNode;
305
+ }>;
306
+ }
307
+ /**
308
+ * Renders a component wrapped with all necessary providers for testing.
309
+ *
310
+ * @example
311
+ * ```tsx
312
+ * import { renderWithProviders } from '@carlonicora/nextjs-jsonapi/testing';
313
+ *
314
+ * const { getByText } = renderWithProviders(<MyComponent />);
315
+ * expect(getByText('Hello')).toBeInTheDocument();
316
+ * ```
317
+ *
318
+ * @example With custom config
319
+ * ```tsx
320
+ * const { getByText } = renderWithProviders(<MyComponent />, {
321
+ * jsonApiConfig: { apiUrl: 'https://custom.api.com' },
322
+ * });
323
+ * ```
324
+ *
325
+ * @example With additional wrapper
326
+ * ```tsx
327
+ * const CustomWrapper = ({ children }) => (
328
+ * <ThemeProvider>{children}</ThemeProvider>
329
+ * );
330
+ *
331
+ * const { getByText } = renderWithProviders(<MyComponent />, {
332
+ * wrapper: CustomWrapper,
333
+ * });
334
+ * ```
335
+ */
336
+ declare function renderWithProviders(ui: ReactElement, options?: RenderWithProvidersOptions): RenderResult;
337
+
338
+ export { type CreateMockApiDataOptions, type CreateMockModuleOptions, type CreateMockResponseOptions, type CreateMockServiceOptions, type MockApiMethod, MockJsonApiProvider, type MockJsonApiProviderProps, type MockService, type RenderWithProvidersOptions, createMockApiData, createMockApiDataList, createMockErrorResponse, createMockErrorService, createMockModule, createMockResponse, createMockService, defaultMockConfig, extendExpectWithJsonApiMatchers, jsonApiMatchers, renderWithProviders };