@carlonicora/nextjs-jsonapi 1.15.0 → 1.17.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.
- package/dist/ApiData-DPKNfY-9.d.mts +10 -0
- package/dist/ApiData-DPKNfY-9.d.ts +10 -0
- package/dist/ApiRequestDataTypeInterface-DIEOFn9s.d.mts +40 -0
- package/dist/ApiRequestDataTypeInterface-DIEOFn9s.d.ts +40 -0
- package/dist/{ApiResponseInterface-QLDnxLA9.d.ts → ApiResponseInterface-BKyod24U.d.ts} +3 -11
- package/dist/{ApiResponseInterface-B4QdWh-y.d.mts → ApiResponseInterface-Dqvu09tz.d.mts} +3 -11
- package/dist/{BlockNoteEditor-FGXYUAWI.js → BlockNoteEditor-34T5CY27.js} +17 -16
- package/dist/BlockNoteEditor-34T5CY27.js.map +1 -0
- package/dist/{BlockNoteEditor-ITJLAOXC.mjs → BlockNoteEditor-4Z6TZBJE.mjs} +7 -6
- package/dist/{BlockNoteEditor-ITJLAOXC.mjs.map → BlockNoteEditor-4Z6TZBJE.mjs.map} +1 -1
- package/dist/JsonApiContext-Bsm_Q2oe.d.mts +41 -0
- package/dist/JsonApiContext-Bsm_Q2oe.d.ts +41 -0
- package/dist/JsonApiRequest-54ZBO7WQ.js +24 -0
- package/dist/{JsonApiRequest-FXZCYIER.js.map → JsonApiRequest-54ZBO7WQ.js.map} +1 -1
- package/dist/{JsonApiRequest-HFWXMKMA.mjs → JsonApiRequest-XWQWTFEQ.mjs} +2 -2
- package/dist/chunk-3EPNHTMH.js +26 -0
- package/dist/chunk-3EPNHTMH.js.map +1 -0
- package/dist/{chunk-TGBXBUWM.mjs → chunk-3VM3WAOV.mjs} +8 -1
- package/dist/chunk-3VM3WAOV.mjs.map +1 -0
- package/dist/{chunk-6YD42BP6.js → chunk-7DTKRMYW.js} +31 -19
- package/dist/chunk-7DTKRMYW.js.map +1 -0
- package/dist/{chunk-PK5DRSUD.js → chunk-D7H7SRWB.js} +4104 -793
- package/dist/chunk-D7H7SRWB.js.map +1 -0
- package/dist/{chunk-JGVXZS7M.mjs → chunk-KUFWHMMY.mjs} +1592 -133
- package/dist/chunk-KUFWHMMY.mjs.map +1 -0
- package/dist/{chunk-SJIVGCNM.mjs → chunk-KX7YG6LY.mjs} +27 -15
- package/dist/chunk-KX7YG6LY.mjs.map +1 -0
- package/dist/{chunk-FPZPD4JI.js → chunk-LI6CPNJI.js} +17 -10
- package/dist/chunk-LI6CPNJI.js.map +1 -0
- package/dist/{chunk-WAFOKMKT.mjs → chunk-SXPXC2TY.mjs} +3729 -418
- package/dist/chunk-SXPXC2TY.mjs.map +1 -0
- package/dist/{chunk-C6QXZGL7.js → chunk-UYY34W7R.js} +1622 -163
- package/dist/chunk-UYY34W7R.js.map +1 -0
- package/dist/chunk-VOXD3ZLY.mjs +26 -0
- package/dist/chunk-VOXD3ZLY.mjs.map +1 -0
- package/dist/client/index.d.mts +11 -45
- package/dist/client/index.d.ts +11 -45
- package/dist/client/index.js +10 -6
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +13 -9
- package/dist/components/index.d.mts +254 -9
- package/dist/components/index.d.ts +254 -9
- package/dist/components/index.js +85 -6
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +84 -5
- package/dist/{config-C5tGGrYf.d.mts → config--nwiW74Z.d.ts} +7 -2
- package/dist/{config-eceYM5kN.d.ts → config-BKSQmUWU.d.mts} +7 -2
- package/dist/{content.interface-CxBBC7ec.d.mts → content.interface-4VICFRA0.d.ts} +2 -1
- package/dist/{content.interface-TB2MfJGs.d.ts → content.interface-CFc97-Cj.d.mts} +2 -1
- package/dist/contexts/index.d.mts +3 -2
- package/dist/contexts/index.d.ts +3 -2
- package/dist/contexts/index.js +7 -6
- package/dist/contexts/index.js.map +1 -1
- package/dist/contexts/index.mjs +6 -5
- package/dist/core/index.d.mts +524 -18
- package/dist/core/index.d.ts +524 -18
- package/dist/core/index.js +54 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +53 -3
- package/dist/index.d.mts +16 -12
- package/dist/index.d.ts +16 -12
- package/dist/index.js +57 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -6
- package/dist/{notification.interface-lG6UpTpt.d.mts → notification.interface-BGaPiCUM.d.mts} +3 -42
- package/dist/{notification.interface-lG6UpTpt.d.ts → notification.interface-CqwaOIgM.d.ts} +3 -42
- package/dist/{s3.service-DP_hsssD.d.mts → s3.service-BYs88XEE.d.ts} +21 -2
- package/dist/{s3.service-Dq-PTUNa.d.ts → s3.service-C0BjOdvn.d.mts} +21 -2
- package/dist/scripts/generate-web-module/generator.d.ts.map +1 -1
- package/dist/scripts/generate-web-module/generator.js +66 -0
- package/dist/scripts/generate-web-module/generator.js.map +1 -1
- package/dist/scripts/generate-web-module/templates/index.d.ts +8 -0
- package/dist/scripts/generate-web-module/templates/index.d.ts.map +1 -1
- package/dist/scripts/generate-web-module/templates/index.js +18 -1
- package/dist/scripts/generate-web-module/templates/index.js.map +1 -1
- package/dist/scripts/generate-web-module/templates/project/bootstrapper.template.d.ts +7 -0
- package/dist/scripts/generate-web-module/templates/project/bootstrapper.template.d.ts.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/bootstrapper.template.js +141 -0
- package/dist/scripts/generate-web-module/templates/project/bootstrapper.template.js.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/env.template.d.ts +7 -0
- package/dist/scripts/generate-web-module/templates/project/env.template.d.ts.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/env.template.js +110 -0
- package/dist/scripts/generate-web-module/templates/project/env.template.js.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/main-layout.template.d.ts +7 -0
- package/dist/scripts/generate-web-module/templates/project/main-layout.template.d.ts.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/main-layout.template.js +101 -0
- package/dist/scripts/generate-web-module/templates/project/main-layout.template.js.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/middleware-env.template.d.ts +7 -0
- package/dist/scripts/generate-web-module/templates/project/middleware-env.template.d.ts.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/middleware-env.template.js +66 -0
- package/dist/scripts/generate-web-module/templates/project/middleware-env.template.js.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/settings-container.template.d.ts +7 -0
- package/dist/scripts/generate-web-module/templates/project/settings-container.template.d.ts.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/settings-container.template.js +257 -0
- package/dist/scripts/generate-web-module/templates/project/settings-container.template.js.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/settings-context.template.d.ts +7 -0
- package/dist/scripts/generate-web-module/templates/project/settings-context.template.d.ts.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/settings-context.template.js +124 -0
- package/dist/scripts/generate-web-module/templates/project/settings-context.template.js.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/settings-module-page.template.d.ts +7 -0
- package/dist/scripts/generate-web-module/templates/project/settings-module-page.template.d.ts.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/settings-module-page.template.js +78 -0
- package/dist/scripts/generate-web-module/templates/project/settings-module-page.template.js.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/settings-page.template.d.ts +7 -0
- package/dist/scripts/generate-web-module/templates/project/settings-page.template.d.ts.map +1 -0
- package/dist/scripts/generate-web-module/templates/project/settings-page.template.js +75 -0
- package/dist/scripts/generate-web-module/templates/project/settings-page.template.js.map +1 -0
- package/dist/scripts/generate-web-module/types/template-data.interface.d.ts +1 -1
- package/dist/scripts/generate-web-module/types/template-data.interface.d.ts.map +1 -1
- package/dist/server/index.d.mts +6 -4
- package/dist/server/index.d.ts +6 -4
- package/dist/server/index.js +13 -13
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +3 -3
- package/dist/stripe-subscription.interface-B-TM40Io.d.ts +226 -0
- package/dist/stripe-subscription.interface-DDxnpj0F.d.mts +226 -0
- package/dist/testing/index.d.mts +338 -0
- package/dist/testing/index.d.ts +338 -0
- package/dist/testing/index.js +323 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/index.mjs +323 -0
- package/dist/testing/index.mjs.map +1 -0
- package/dist/{useSocket-Bua6MwLi.d.mts → useSocket-BNj9PrRw.d.mts} +1 -1
- package/dist/{useSocket-D5dhUp4m.d.ts → useSocket-Dwt8cz1x.d.ts} +1 -1
- package/package.json +29 -3
- package/scripts/generate-web-module/generator.ts +83 -0
- package/scripts/generate-web-module/templates/index.ts +10 -0
- package/scripts/generate-web-module/templates/project/bootstrapper.template.ts +108 -0
- package/scripts/generate-web-module/templates/project/env.template.ts +77 -0
- package/scripts/generate-web-module/templates/project/main-layout.template.tsx +68 -0
- package/scripts/generate-web-module/templates/project/middleware-env.template.ts +33 -0
- package/scripts/generate-web-module/templates/project/settings-container.template.tsx +224 -0
- package/scripts/generate-web-module/templates/project/settings-context.template.tsx +91 -0
- package/scripts/generate-web-module/templates/project/settings-module-page.template.tsx +45 -0
- package/scripts/generate-web-module/templates/project/settings-page.template.tsx +42 -0
- package/scripts/generate-web-module/types/template-data.interface.ts +1 -1
- package/src/client/config.ts +9 -0
- package/src/client/hooks/__tests__/useJsonApiGet.test.tsx +229 -0
- package/src/client/hooks/__tests__/useJsonApiMutation.test.tsx +348 -0
- package/src/client/hooks/__tests__/useRehydration.test.ts +188 -0
- package/src/components/forms/__tests__/FormCheckbox.test.tsx +238 -0
- package/src/components/forms/__tests__/FormDate.test.tsx +212 -0
- package/src/components/forms/__tests__/FormInput.test.tsx +292 -0
- package/src/components/forms/__tests__/FormSelect.test.tsx +173 -0
- package/src/components/index.ts +7 -0
- package/src/components/tables/__tests__/ContentListTable.test.tsx +411 -0
- package/src/core/abstracts/AbstractService.ts +104 -0
- package/src/core/endpoint/EndpointCreator.ts +7 -4
- package/src/core/endpoint/__tests__/EndpointCreator.test.ts +168 -0
- package/src/core/factories/__tests__/JsonApiDataFactory.test.ts +109 -0
- package/src/core/factories/__tests__/RehydrationFactory.test.ts +151 -0
- package/src/core/index.ts +12 -4
- package/src/core/interfaces/ApiResponseInterface.ts +1 -0
- package/src/core/registry/ModuleRegistry.ts +11 -2
- package/src/core/registry/__tests__/DataClassRegistry.test.ts +136 -0
- package/src/core/registry/__tests__/ModuleRegistrar.test.ts +159 -0
- package/src/core/utils/translateResponse.ts +17 -0
- package/src/features/auth/components/details/LandingComponent.tsx +14 -12
- package/src/features/billing/components/cards/BillingUsageSummaryCard.tsx +97 -0
- package/src/features/billing/components/cards/CustomerInfoCard.tsx +112 -0
- package/src/features/billing/components/cards/InvoicesSummaryCard.tsx +114 -0
- package/src/features/billing/components/cards/PaymentMethodSummaryCard.tsx +119 -0
- package/src/features/billing/components/cards/SubscriptionSummaryCard.tsx +146 -0
- package/src/features/billing/components/cards/index.ts +5 -0
- package/src/features/billing/components/containers/BillingDashboardContainer.tsx +427 -0
- package/src/features/billing/components/containers/index.ts +1 -0
- package/src/features/billing/components/index.ts +6 -0
- package/src/features/billing/components/modals/BillingDetailModal.tsx +36 -0
- package/src/features/billing/components/modals/index.ts +1 -0
- package/src/features/billing/components/providers/StripeProvider.tsx +48 -0
- package/src/features/billing/components/providers/index.ts +1 -0
- package/src/features/billing/components/utils/currency.ts +49 -0
- package/src/features/billing/components/utils/date.ts +21 -0
- package/src/features/billing/components/utils/index.ts +2 -0
- package/src/features/billing/components/widgets/BillingAlertBanner.tsx +63 -0
- package/src/features/billing/components/widgets/index.ts +1 -0
- package/src/features/billing/data/Billing.ts +17 -0
- package/src/features/billing/data/billing.service.ts +58 -0
- package/src/features/billing/data/index.ts +5 -0
- package/src/features/billing/index.ts +3 -0
- package/src/features/billing/modules/billing.module.ts +9 -0
- package/src/features/billing/modules/index.ts +1 -0
- package/src/features/billing/stripe-customer/components/containers/PaymentMethodsContainer.tsx +79 -0
- package/src/features/billing/stripe-customer/components/containers/index.ts +1 -0
- package/src/features/billing/stripe-customer/components/details/PaymentMethodCard.tsx +151 -0
- package/src/features/billing/stripe-customer/components/details/index.ts +1 -0
- package/src/features/billing/stripe-customer/components/forms/PaymentMethodEditor.tsx +186 -0
- package/src/features/billing/stripe-customer/components/forms/index.ts +1 -0
- package/src/features/billing/stripe-customer/components/index.ts +4 -0
- package/src/features/billing/stripe-customer/components/lists/PaymentMethodsList.tsx +19 -0
- package/src/features/billing/stripe-customer/components/lists/index.ts +1 -0
- package/src/features/billing/stripe-customer/data/index.ts +5 -0
- package/src/features/billing/stripe-customer/data/payment-method.interface.ts +27 -0
- package/src/features/billing/stripe-customer/data/payment-method.ts +119 -0
- package/src/features/billing/stripe-customer/data/stripe-customer.interface.ts +16 -0
- package/src/features/billing/stripe-customer/data/stripe-customer.service.ts +128 -0
- package/src/features/billing/stripe-customer/data/stripe-customer.ts +71 -0
- package/src/features/billing/stripe-customer/index.ts +3 -0
- package/src/features/billing/stripe-customer/stripe-customer.module.ts +9 -0
- package/src/features/billing/stripe-customer/stripe-payment-method.module.ts +9 -0
- package/src/features/billing/stripe-invoice/components/containers/InvoicesContainer.tsx +66 -0
- package/src/features/billing/stripe-invoice/components/containers/index.ts +1 -0
- package/src/features/billing/stripe-invoice/components/details/InvoiceDetails.tsx +172 -0
- package/src/features/billing/stripe-invoice/components/details/index.ts +1 -0
- package/src/features/billing/stripe-invoice/components/index.ts +4 -0
- package/src/features/billing/stripe-invoice/components/lists/InvoicesList.tsx +84 -0
- package/src/features/billing/stripe-invoice/components/lists/index.ts +1 -0
- package/src/features/billing/stripe-invoice/components/widgets/InvoiceStatusBadge.tsx +41 -0
- package/src/features/billing/stripe-invoice/components/widgets/index.ts +1 -0
- package/src/features/billing/stripe-invoice/data/index.ts +3 -0
- package/src/features/billing/stripe-invoice/data/stripe-invoice.interface.ts +65 -0
- package/src/features/billing/stripe-invoice/data/stripe-invoice.service.ts +64 -0
- package/src/features/billing/stripe-invoice/data/stripe-invoice.ts +177 -0
- package/src/features/billing/stripe-invoice/index.ts +2 -0
- package/src/features/billing/stripe-invoice/stripe-invoice.module.ts +9 -0
- package/src/features/billing/stripe-price/components/forms/PriceEditor.tsx +304 -0
- package/src/features/billing/stripe-price/components/forms/index.ts +1 -0
- package/src/features/billing/stripe-price/components/index.ts +2 -0
- package/src/features/billing/stripe-price/components/lists/PricesList.tsx +283 -0
- package/src/features/billing/stripe-price/components/lists/index.ts +1 -0
- package/src/features/billing/stripe-price/data/index.ts +3 -0
- package/src/features/billing/stripe-price/data/stripe-price.interface.ts +48 -0
- package/src/features/billing/stripe-price/data/stripe-price.service.ts +123 -0
- package/src/features/billing/stripe-price/data/stripe-price.ts +156 -0
- package/src/features/billing/stripe-price/index.ts +2 -0
- package/src/features/billing/stripe-price/stripe-price.module.ts +9 -0
- package/src/features/billing/stripe-product/components/containers/ProductsAdminContainer.tsx +86 -0
- package/src/features/billing/stripe-product/components/containers/index.ts +1 -0
- package/src/features/billing/stripe-product/components/forms/ProductEditor.tsx +100 -0
- package/src/features/billing/stripe-product/components/forms/index.ts +1 -0
- package/src/features/billing/stripe-product/components/index.ts +3 -0
- package/src/features/billing/stripe-product/components/lists/ProductsList.tsx +206 -0
- package/src/features/billing/stripe-product/components/lists/index.ts +1 -0
- package/src/features/billing/stripe-product/data/index.ts +3 -0
- package/src/features/billing/stripe-product/data/stripe-product.interface.ts +18 -0
- package/src/features/billing/stripe-product/data/stripe-product.service.ts +112 -0
- package/src/features/billing/stripe-product/data/stripe-product.ts +74 -0
- package/src/features/billing/stripe-product/index.ts +2 -0
- package/src/features/billing/stripe-product/stripe-product.module.ts +9 -0
- package/src/features/billing/stripe-subscription/components/containers/SubscriptionsContainer.tsx +304 -0
- package/src/features/billing/stripe-subscription/components/containers/index.ts +1 -0
- package/src/features/billing/stripe-subscription/components/details/SubscriptionDetails.tsx +223 -0
- package/src/features/billing/stripe-subscription/components/details/index.ts +1 -0
- package/src/features/billing/stripe-subscription/components/forms/CancelSubscriptionDialog.tsx +116 -0
- package/src/features/billing/stripe-subscription/components/forms/SubscriptionEditor.tsx +331 -0
- package/src/features/billing/stripe-subscription/components/forms/index.ts +2 -0
- package/src/features/billing/stripe-subscription/components/index.ts +5 -0
- package/src/features/billing/stripe-subscription/components/lists/SubscriptionsList.tsx +104 -0
- package/src/features/billing/stripe-subscription/components/lists/index.ts +1 -0
- package/src/features/billing/stripe-subscription/components/widgets/PricingCard.tsx +95 -0
- package/src/features/billing/stripe-subscription/components/widgets/PricingCardsGrid.tsx +110 -0
- package/src/features/billing/stripe-subscription/components/widgets/ProrationPreview.tsx +41 -0
- package/src/features/billing/stripe-subscription/components/widgets/SubscriptionStatusBadge.tsx +60 -0
- package/src/features/billing/stripe-subscription/components/widgets/index.ts +4 -0
- package/src/features/billing/stripe-subscription/data/index.ts +3 -0
- package/src/features/billing/stripe-subscription/data/stripe-subscription.interface.ts +66 -0
- package/src/features/billing/stripe-subscription/data/stripe-subscription.service.ts +193 -0
- package/src/features/billing/stripe-subscription/data/stripe-subscription.ts +135 -0
- package/src/features/billing/stripe-subscription/hooks/index.ts +1 -0
- package/src/features/billing/stripe-subscription/hooks/useConfirmSubscriptionPayment.ts +111 -0
- package/src/features/billing/stripe-subscription/index.ts +5 -0
- package/src/features/billing/stripe-subscription/stripe-subscription.module.ts +9 -0
- package/src/features/billing/stripe-usage/components/containers/UsageContainer.tsx +109 -0
- package/src/features/billing/stripe-usage/components/containers/index.ts +1 -0
- package/src/features/billing/stripe-usage/components/details/UsageSummaryCard.tsx +90 -0
- package/src/features/billing/stripe-usage/components/details/index.ts +1 -0
- package/src/features/billing/stripe-usage/components/index.ts +4 -0
- package/src/features/billing/stripe-usage/components/lists/UsageHistoryTable.tsx +72 -0
- package/src/features/billing/stripe-usage/components/lists/index.ts +1 -0
- package/src/features/billing/stripe-usage/components/widgets/UsageSummaryCards.tsx +19 -0
- package/src/features/billing/stripe-usage/components/widgets/index.ts +1 -0
- package/src/features/billing/stripe-usage/data/index.ts +3 -0
- package/src/features/billing/stripe-usage/data/stripe-usage.interface.ts +55 -0
- package/src/features/billing/stripe-usage/data/stripe-usage.service.ts +129 -0
- package/src/features/billing/stripe-usage/data/stripe-usage.ts +70 -0
- package/src/features/billing/stripe-usage/index.ts +2 -0
- package/src/features/billing/stripe-usage/stripe-usage.module.ts +9 -0
- package/src/features/company/components/forms/CompanyEditor.tsx +2 -2
- package/src/features/company/contexts/CompanyContext.tsx +2 -2
- package/src/features/feature/components/forms/FormFeatures.tsx +13 -106
- package/src/features/feature/data/feature.interface.ts +1 -1
- package/src/features/feature/data/feature.ts +4 -4
- package/src/features/index.ts +7 -0
- package/src/features/module/data/module.interface.ts +0 -1
- package/src/features/module/data/module.ts +0 -6
- package/src/features/user/components/lists/ContributorsList.tsx +2 -2
- package/src/features/user/components/widgets/UserAvatar.tsx +1 -1
- package/src/hooks/__tests__/useDataListRetriever.test.ts +321 -0
- package/src/hooks/__tests__/useDebounce.test.ts +170 -0
- package/src/index.ts +5 -2
- package/src/login/config.ts +27 -0
- package/src/login/index.ts +2 -0
- package/src/shadcnui/custom/link.tsx +16 -6
- package/src/testing/factories/createMockApiData.ts +143 -0
- package/src/testing/factories/createMockModule.ts +32 -0
- package/src/testing/factories/createMockResponse.ts +93 -0
- package/src/testing/factories/createMockService.ts +79 -0
- package/src/testing/index.ts +70 -0
- package/src/testing/matchers/jsonApiMatchers.ts +174 -0
- package/src/testing/providers/MockJsonApiProvider.tsx +58 -0
- package/src/testing/utils/renderWithProviders.tsx +76 -0
- package/src/utils/__tests__/date-formatter.test.ts +161 -0
- package/src/utils/__tests__/exists.test.ts +100 -0
- package/src/utils/blocknote-diff.util.ts +2 -1
- package/src/utils/blocknote-word-diff-renderer.util.ts +8 -7
- package/src/utils/cn.test.ts +44 -0
- package/dist/AuthComponent-hxOPs9o8.d.mts +0 -11
- package/dist/AuthComponent-hxOPs9o8.d.ts +0 -11
- package/dist/BlockNoteEditor-FGXYUAWI.js.map +0 -1
- package/dist/JsonApiRequest-FXZCYIER.js +0 -24
- package/dist/chunk-6YD42BP6.js.map +0 -1
- package/dist/chunk-C6QXZGL7.js.map +0 -1
- package/dist/chunk-FPZPD4JI.js.map +0 -1
- package/dist/chunk-JGVXZS7M.mjs.map +0 -1
- package/dist/chunk-PK5DRSUD.js.map +0 -1
- package/dist/chunk-SJIVGCNM.mjs.map +0 -1
- package/dist/chunk-TGBXBUWM.mjs.map +0 -1
- package/dist/chunk-WAFOKMKT.mjs.map +0 -1
- package/src/discord/config.ts +0 -15
- package/src/discord/index.ts +0 -1
- /package/dist/{JsonApiRequest-HFWXMKMA.mjs.map → JsonApiRequest-XWQWTFEQ.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 };
|