Compare commits
6 Commits
@blitzjs/a
...
@blitzjs/a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7735d59a3 | ||
|
|
6d5f9efe14 | ||
|
|
b84c5bedbd | ||
|
|
f80cd3dba9 | ||
|
|
e5cd2c8622 | ||
|
|
86e8eb7c8c |
@@ -4004,6 +4004,16 @@
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "papsavas",
|
||||
"name": "Savvas Papageorgiadis",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/50584606?v=4",
|
||||
"profile": "https://github.com/papsavas",
|
||||
"contributions": [
|
||||
"doc",
|
||||
"code"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7,
|
||||
|
||||
6
.changeset/cyan-rings-play.md
Normal file
6
.changeset/cyan-rings-play.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@blitzjs/rpc": patch
|
||||
"blitz": patch
|
||||
---
|
||||
|
||||
Add helpful error message when RPC resolvers have the same path
|
||||
9
.changeset/modern-cups-cheat.md
Normal file
9
.changeset/modern-cups-cheat.md
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
"@blitzjs/auth": patch
|
||||
"@blitzjs/next": patch
|
||||
"@blitzjs/rpc": patch
|
||||
"blitz": patch
|
||||
---
|
||||
|
||||
Next 14 Compatibility
|
||||
|
||||
5
.changeset/poor-bikes-wait.md
Normal file
5
.changeset/poor-bikes-wait.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
new blitz app starter
|
||||
@@ -93,6 +93,7 @@
|
||||
"curvy-drinks-perform",
|
||||
"cyan-bulldogs-heal",
|
||||
"cyan-cars-greet",
|
||||
"cyan-rings-play",
|
||||
"dirty-monkeys-greet",
|
||||
"dirty-planets-chew",
|
||||
"dull-rings-arrive",
|
||||
@@ -199,6 +200,7 @@
|
||||
"mean-ears-speak",
|
||||
"mean-gorillas-reply",
|
||||
"modern-cameras-pull",
|
||||
"modern-cups-cheat",
|
||||
"modern-games-dream",
|
||||
"modern-insects-raise",
|
||||
"modern-ligers-behave",
|
||||
@@ -240,6 +242,7 @@
|
||||
"plenty-gifts-provide",
|
||||
"plenty-kiwis-greet",
|
||||
"polite-lizards-love",
|
||||
"poor-bikes-wait",
|
||||
"poor-crabs-drum",
|
||||
"poor-peas-lick",
|
||||
"poor-penguins-look",
|
||||
@@ -258,6 +261,7 @@
|
||||
"quiet-pans-hunt",
|
||||
"quiet-sloths-rule",
|
||||
"rare-crews-sleep",
|
||||
"rare-squids-brake",
|
||||
"red-badgers-retire",
|
||||
"red-gorillas-marry",
|
||||
"rich-chairs-invent",
|
||||
|
||||
5
.changeset/rare-squids-brake.md
Normal file
5
.changeset/rare-squids-brake.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/rpc": minor
|
||||
---
|
||||
|
||||
expose `ctx` to `rpcHandler` error callbacks in [[...blitz]].ts files
|
||||
@@ -6,6 +6,7 @@
|
||||
### Now we can configure Blitz RPC in the following way,
|
||||
|
||||
In your `[[...blitz]].ts` api file you can see the following settings
|
||||
|
||||
```ts
|
||||
logging?: {
|
||||
/**
|
||||
@@ -29,6 +30,7 @@ logging?: {
|
||||
disablelevel?: "debug" | "info"
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
import { rpcHandler } from "@blitzjs/rpc"
|
||||
import { api } from "src/blitz-server"
|
||||
@@ -48,6 +50,7 @@ export default api(
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```ts
|
||||
export default api(
|
||||
rpcHandler({
|
||||
@@ -65,4 +68,3 @@ export default api(
|
||||
```
|
||||
|
||||
This is enable verbose blitz rpc logging for all resolvers except the resolvers `getCurrentUser` and others mentioned in the `blockList`
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<img alt="" src="https://img.shields.io/badge/Join%20our%20community-6700EB.svg?style=for-the-badge&labelColor=000000&logoWidth=20&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAQ9SURBVHgB7d3dVdtAEIbhcSpICUoH0IEogQqSVBBSAU4FSSpIOoAORAfQgSghHXzZ1U/YcMD4R9rZmf2ec3y448LyiNf27iLiGIAmPLrweC9Un3DhrzG6EarLNP09nlwJ1SOZ/lQr5N80/S/p2QMVCBf5N17XCfm1Y/rBHqjAG9PPHvBsz+mf9WAP+HLA9M/YA14cOP2payH7jpj+VCtk1wnTP+vj7xCy6cTpn7EHLMLp059iD1iD8eveJbVCNsSLheX1YA/YgOWnf8YeKB3Wmf7Ud6Fy4f/FHmtpxbl3YlC4MJ/Cj0bWdwPnPbARg+L0S54XQHS32WwuxClzd4CM0z9rPfeAuTtA5ulPXYQ7wZ04Y+oOoDD9KZc9YOoOoDj9s4dwFzgXR6w1wIPoOvPWA9buAHEJ173o3gWiy3AnuBUHLEbgmYwvAk1/wuM8vAgexThzbwPDkx7/DHwVXfFOxP2GmsKd4Ab6zPeAyU8CI7AHFmH2BRCBPXAyk18GzUrqAXCTiR4ssyj0VFw/oCU8+e+RZ33AWz6KMaYbIIWxB+JSLs1bsbkeMN0AqakHvoku9oA2sAfqBvbAQdw0QArsgb25aYBUQT3QgT2gB+yBuqGcHij2UCqXDZACe2Anlw2QYg/QAOyBuoE98CL3DZDCuK4/rh/Q7oGL6U+TOvcNkJoijN8X1C48+T+g75eQDrAH/qmqAVJgDwyqaoAUe4AGYA/UDZX3QLUNkEIZPRCd5+6BahsgVUgPROwBTSijB7jpVAvGHriHvmw9wAZ4BpX1ABvgmakHtPcbRuwBTWAPULgAV9D/jKDY9YRvwvgEaurD44uQHvAol7qBW7WKluVtIHiUS7GyvA0s6CiXDnxrpQfsgbqBS7GKk/2jYHCrVlGyfxTMrVo0ALdq1Q3sgSKofh0M9oA61a+D2QM0AHugbmAPqClmSRjK2apVVQ8UsySsoK1aHdgDesCtWnUDeyCrIpeFg1u3sylyWTi3btMA7IG6gT2wuuK3hoE9sKrit4YVslWLPaAN7IG6ocKt2zmY2h4O9sDiTG0PZw/QANy6XTewBxZj9ogYVHy025LMHhEz9cBn0We6B0yfERReBLfhx0/R1YQHPx/QBPbA0VwcEwf2wNFcHBPHHjiem3MC2QPHcXdSaJjA+KfgTPQ8hhfjBzHC40mhlzJ+Xq9lK4a4PCs43AVaGTed5mZq+iOXZwWHi3AnOj2wFWNcnxYe7gTxLtBKHuamP/J+Wnh8a5irB7ZC5Yk9gPX1QuXC+usHWqGyhYvUYR0a7zboUOFCNVhnk0krZAOW7wFOvzXhom2xnEbIHizTA1wEYhWW6YFGyC6c1gOcfg9wfA80Qj7g8B7g9HuCww+haIR8wf49wOn3Cvv9k8tGyC/s7gFOv3fY3QONkH+v9MBWqB7PeqDn9FcIT//kcitUn6kHOu/T/xfWzlQy3dEHhwAAAABJRU5ErkJggg==">
|
||||
</a>
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
<a aria-label="All Contributors" href="#contributors-"><img alt="" src="https://img.shields.io/badge/all_contributors-422-17BB8A.svg?style=for-the-badge&labelColor=000000"></a>
|
||||
<a aria-label="All Contributors" href="#contributors-"><img alt="" src="https://img.shields.io/badge/all_contributors-423-17BB8A.svg?style=for-the-badge&labelColor=000000"></a>
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
<a aria-label="License" href="https://github.com/blitz-js/blitz/blob/main/LICENSE">
|
||||
<img alt="" src="https://img.shields.io/npm/l/blitz.svg?style=for-the-badge&labelColor=000000&color=blue">
|
||||
@@ -746,6 +746,7 @@ Thanks to these wonderful people ([emoji key](https://allcontributors.org/docs/e
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/Zamfi99"><img src="https://avatars.githubusercontent.com/u/19189337?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Zamfira Costin-Andrei</b></sub></a><br /><a href="https://github.com/blitz-js/blitz/commits?author=Zamfi99" title="Documentation">📖</a> <a href="https://github.com/blitz-js/blitz/commits?author=Zamfi99" title="Code">💻</a></td>
|
||||
<td align="center"><a href="https://github.com/potikhanovsergey"><img src="https://avatars.githubusercontent.com/u/71494201?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sergey</b></sub></a><br /><a href="https://github.com/blitz-js/blitz/commits?author=potikhanovsergey" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/papsavas"><img src="https://avatars.githubusercontent.com/u/50584606?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Savvas Papageorgiadis</b></sub></a><br /><a href="https://github.com/blitz-js/blitz/commits?author=papsavas" title="Documentation">📖</a> <a href="https://github.com/blitz-js/blitz/commits?author=papsavas" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
# next-blitz-auth
|
||||
|
||||
## 0.1.1-beta.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [86e8eb7c8]
|
||||
- Updated dependencies [b84c5bedb]
|
||||
- Updated dependencies [e5cd2c862]
|
||||
- @blitzjs/rpc@2.0.0-beta.37
|
||||
- blitz@2.0.0-beta.37
|
||||
- @blitzjs/auth@2.0.0-beta.37
|
||||
- @blitzjs/next@2.0.0-beta.37
|
||||
- @blitzjs/config@2.0.0-beta.37
|
||||
|
||||
## 0.1.1-beta.12
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
const {withBlitz} = require("@blitzjs/next")
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
experimental: {
|
||||
appDir: true,
|
||||
serverComponentsExternalPackages: ["@prisma/client", "prisma"],
|
||||
},
|
||||
}
|
||||
const nextConfig = {}
|
||||
|
||||
module.exports = withBlitz(nextConfig)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "next-blitz-auth",
|
||||
"version": "0.1.1-beta.12",
|
||||
"version": "0.1.1-beta.13",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"blitz:dev": "next dev",
|
||||
@@ -8,18 +8,21 @@
|
||||
"blitz:start": "next start",
|
||||
"lint": "next lint"
|
||||
},
|
||||
"prisma": {
|
||||
"schema": "prisma/schema.prisma"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@hookform/error-message": "2.0.0",
|
||||
"@hookform/resolvers": "2.9.10",
|
||||
"@prisma/client": "^4.5.0",
|
||||
"@tanstack/react-query": "4.0.10",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"flatted": "3.2.7",
|
||||
"next": "13.5.2",
|
||||
"next": "14.0.4",
|
||||
"prisma": "^4.5.0",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
|
||||
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
import {useAuthenticatedBlitzContext} from "../../src/blitz-server"
|
||||
import {useAuthenticatedBlitzContext} from "../../blitz-server"
|
||||
|
||||
export default async function RootLayout({children}: {children: React.ReactNode}) {
|
||||
await useAuthenticatedBlitzContext({
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import {LoginForm} from "../../../src/auth/components/LoginForm"
|
||||
import {LoginForm} from "../../../auth/components/LoginForm"
|
||||
import {useRouter} from "next/navigation"
|
||||
import {useSearchParams} from "next/navigation"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import {useRouter} from "next/navigation"
|
||||
import SignupForm from "../../../src/auth/components/SignupForm"
|
||||
import SignupForm from "../../../auth/components/SignupForm"
|
||||
|
||||
const SignUp = () => {
|
||||
const router = useRouter()
|
||||
@@ -1,5 +1,5 @@
|
||||
import "src/styles/globals.css"
|
||||
import {BlitzProvider} from "../src/blitz-client"
|
||||
import {BlitzProvider} from "../blitz-client"
|
||||
import styles from "src/styles/Home.module.css"
|
||||
|
||||
export default function RootLayout({children}: {children: React.ReactNode}) {
|
||||
@@ -1,8 +1,8 @@
|
||||
import Link from "next/link"
|
||||
import styles from "src/styles/Home.module.css"
|
||||
import Test from "./react-query"
|
||||
import {invoke, useAuthenticatedBlitzContext} from "../src/blitz-server"
|
||||
import getCurrentUser from "../src/users/queries/getCurrentUser"
|
||||
import {invoke, useAuthenticatedBlitzContext} from "../blitz-server"
|
||||
import getCurrentUser from "../users/queries/getCurrentUser"
|
||||
|
||||
export default async function Home() {
|
||||
await useAuthenticatedBlitzContext({
|
||||
@@ -1,8 +1,8 @@
|
||||
"use client"
|
||||
|
||||
import {useQuery, useMutation} from "@blitzjs/rpc"
|
||||
import logout from "../src/auth/mutations/logout"
|
||||
import getCurrentUser from "../src/users/queries/getCurrentUser"
|
||||
import logout from "../auth/mutations/logout"
|
||||
import getCurrentUser from "../users/queries/getCurrentUser"
|
||||
import {useTransition} from "react"
|
||||
import {useRouter} from "next/navigation"
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import db from "../../../prisma"
|
||||
// import {SecurePassword} from "@blitzjs/auth"
|
||||
import {SecurePassword} from "@blitzjs/auth/secure-password"
|
||||
|
||||
export default async function signup(input: {password: string; email: string}, ctx: any) {
|
||||
const blitzContext = ctx
|
||||
// const hashedPassword = await SecurePassword.hash((input.password as string) || "test-password")
|
||||
const hashedPassword = (input.password as string) || "test-password"
|
||||
const email = (input.email as string) || "test" + Math.random() + "@test.com"
|
||||
const hashedPassword = await SecurePassword.hash((input.password as string) || "test-password")
|
||||
const email = input.email
|
||||
const user = await db.user.create({
|
||||
data: {email, hashedPassword},
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
import {api} from "../../../blitz-server"
|
||||
|
||||
export default api(rpcHandler({onError: console.log}))
|
||||
export default api(rpcHandler({onError: (error, ctx) => console.log(error)}))
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"baseUrl": ".",
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
|
||||
@@ -23,15 +23,15 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@hookform/error-message": "2.0.0",
|
||||
"@hookform/resolvers": "2.9.10",
|
||||
"@prisma/client": "4.6.1",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"next": "13.5.2",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"next": "14.0.4",
|
||||
"openid-client": "5.2.1",
|
||||
"prisma": "4.6.1",
|
||||
"react": "18.2.0",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { rpcHandler } from "@blitzjs/rpc"
|
||||
import { api } from "src/blitz-server"
|
||||
|
||||
export default api(rpcHandler({ onError: console.log }))
|
||||
export default api(rpcHandler({ onError: (error, ctx) => console.log(error) }))
|
||||
|
||||
@@ -24,15 +24,15 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@hookform/error-message": "2.0.0",
|
||||
"@hookform/resolvers": "2.9.10",
|
||||
"@prisma/client": "4.6.1",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"next": "13.5.2",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"next": "14.0.4",
|
||||
"next-auth": "4.18.7",
|
||||
"prisma": "4.6.1",
|
||||
"react": "18.2.0",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { api } from "src/blitz-server"
|
||||
import GithubProvider from "next-auth/providers/github"
|
||||
import { NextAuthAdapter } from "@blitzjs/auth/next-auth"
|
||||
import EmailProvider from "next-auth/providers/email"
|
||||
import { NextAuthAdapter, BlitzNextAuthOptions } from "@blitzjs/auth/next-auth"
|
||||
import db, { User } from "db"
|
||||
import { Role } from "types"
|
||||
|
||||
@@ -10,6 +11,10 @@ const providers = [
|
||||
clientId: process.env.GITHUB_CLIENT_ID as string,
|
||||
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
|
||||
}),
|
||||
EmailProvider({
|
||||
from: process.env.GITHUB_CLIENT_ID as string,
|
||||
server: process.env.GITHUB_CLIENT_SECRET as string,
|
||||
}),
|
||||
]
|
||||
|
||||
export default api(
|
||||
|
||||
@@ -3,8 +3,8 @@ import { api } from "src/blitz-server"
|
||||
|
||||
export default api(
|
||||
rpcHandler({
|
||||
onError: console.log,
|
||||
formatError: (error) => {
|
||||
onError: (error, ctx) => console.log(error),
|
||||
formatError: (error, ctx) => {
|
||||
error.message = `FormatError handler: ${error.message}`
|
||||
return error
|
||||
},
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useEffect, useState } from "react"
|
||||
import Layout from "src/core/layouts/Layout"
|
||||
import { LabeledTextField } from "src/core/components/LabeledTextField"
|
||||
import { Form, FORM_ERROR } from "src/core/components/Form"
|
||||
|
||||
@@ -38,10 +38,10 @@ const UserInfo = () => {
|
||||
} else {
|
||||
return (
|
||||
<>
|
||||
<Link href={"/signup"} className={styles.button}>
|
||||
<Link href={"/auth/signup"} className={styles.button}>
|
||||
<strong>Sign Up</strong>
|
||||
</Link>
|
||||
<Link href={"/login"} className={styles.loginButton}>
|
||||
<Link href={"/auth/login"} className={styles.loginButton}>
|
||||
<strong>Login</strong>
|
||||
</Link>
|
||||
<Link href="/api/auth/github/login" passHref legacyBehavior>
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/**
|
||||
* @vitest-environment jsdom
|
||||
*/
|
||||
|
||||
import { expect, vi, test } from "vitest"
|
||||
import { render } from "test/utils"
|
||||
|
||||
import Home from "../src/pages/index"
|
||||
|
||||
vi.mock("public/logo.png", () => ({
|
||||
default: { src: "/logo.png" },
|
||||
}))
|
||||
|
||||
test.skip("renders blitz documentation link", () => {
|
||||
// This is an example of how to ensure a specific item is in the document
|
||||
// But it's disabled by default (by test.skip) so the test doesn't fail
|
||||
// when you remove the default content from the page
|
||||
|
||||
// This is an example on how to mock api hooks when testing
|
||||
vi.mock("src/users/hooks/useCurrentUser", () => ({
|
||||
useCurrentUser: () => ({
|
||||
id: 1,
|
||||
name: "User",
|
||||
email: "user@email.com",
|
||||
role: "user",
|
||||
}),
|
||||
}))
|
||||
|
||||
const { getByText } = render(<Home />)
|
||||
const linkElement = getByText(/Blitz Docs/i)
|
||||
expect(linkElement).toBeInTheDocument()
|
||||
})
|
||||
@@ -1,3 +0,0 @@
|
||||
import "@testing-library/jest-dom"
|
||||
|
||||
export {}
|
||||
@@ -1,106 +0,0 @@
|
||||
import { vi } from "vitest"
|
||||
import { render as defaultRender } from "@testing-library/react"
|
||||
import { renderHook as defaultRenderHook } from "@testing-library/react-hooks"
|
||||
import { NextRouter } from "next/router"
|
||||
import { BlitzProvider, RouterContext } from "@blitzjs/next"
|
||||
import { QueryClient } from "@blitzjs/rpc"
|
||||
|
||||
export * from "@testing-library/react"
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
// This file customizes the render() and renderHook() test functions provided
|
||||
// by React testing library. It adds a router context wrapper with a mocked router.
|
||||
//
|
||||
// You should always import `render` and `renderHook` from this file
|
||||
//
|
||||
// This is the place to add any other context providers you need while testing.
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
// --------------------------------------------------
|
||||
// render()
|
||||
// --------------------------------------------------
|
||||
// Override the default test render with our own
|
||||
//
|
||||
// You can override the router mock like this:
|
||||
//
|
||||
// const { baseElement } = render(<MyComponent />, {
|
||||
// router: { pathname: '/my-custom-pathname' },
|
||||
// });
|
||||
// --------------------------------------------------
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
export function render(
|
||||
ui: RenderUI,
|
||||
{ wrapper, router, dehydratedState, ...options }: RenderOptions = {}
|
||||
) {
|
||||
if (!wrapper) {
|
||||
// Add a default context wrapper if one isn't supplied from the test
|
||||
wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<BlitzProvider dehydratedState={dehydratedState} client={queryClient}>
|
||||
<RouterContext.Provider value={{ ...mockRouter, ...router }}>
|
||||
{children}
|
||||
</RouterContext.Provider>
|
||||
</BlitzProvider>
|
||||
)
|
||||
}
|
||||
return defaultRender(ui, { wrapper, ...options })
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// renderHook()
|
||||
// --------------------------------------------------
|
||||
// Override the default test renderHook with our own
|
||||
//
|
||||
// You can override the router mock like this:
|
||||
//
|
||||
// const result = renderHook(() => myHook(), {
|
||||
// router: { pathname: '/my-custom-pathname' },
|
||||
// });
|
||||
// --------------------------------------------------
|
||||
export function renderHook(
|
||||
hook: RenderHook,
|
||||
{ wrapper, router, dehydratedState, ...options }: RenderOptions = {}
|
||||
) {
|
||||
if (!wrapper) {
|
||||
// Add a default context wrapper if one isn't supplied from the test
|
||||
wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<BlitzProvider dehydratedState={dehydratedState} client={queryClient}>
|
||||
<RouterContext.Provider value={{ ...mockRouter, ...router }}>
|
||||
{children}
|
||||
</RouterContext.Provider>
|
||||
</BlitzProvider>
|
||||
)
|
||||
}
|
||||
return defaultRenderHook(hook, { wrapper, ...options })
|
||||
}
|
||||
|
||||
export const mockRouter: NextRouter = {
|
||||
basePath: "",
|
||||
pathname: "/",
|
||||
route: "/",
|
||||
asPath: "/",
|
||||
query: {},
|
||||
isReady: true,
|
||||
isLocaleDomain: false,
|
||||
forward: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
isPreview: false,
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
reload: vi.fn(),
|
||||
back: vi.fn(),
|
||||
beforePopState: vi.fn(),
|
||||
events: {
|
||||
on: vi.fn(),
|
||||
off: vi.fn(),
|
||||
emit: vi.fn(),
|
||||
},
|
||||
isFallback: false,
|
||||
}
|
||||
|
||||
type DefaultParams = Parameters<typeof defaultRender>
|
||||
type RenderUI = DefaultParams[0]
|
||||
type RenderOptions = DefaultParams[1] & { router?: Partial<NextRouter>; dehydratedState?: unknown }
|
||||
|
||||
type DefaultHookParams = Parameters<typeof defaultRenderHook>
|
||||
type RenderHook = DefaultHookParams[0]
|
||||
@@ -16,17 +16,17 @@
|
||||
"schema": "./db/schema.prisma"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@prisma/client": "4.6.1",
|
||||
"@types/jest": "29.2.2",
|
||||
"@types/passport-twitter": "1.0.37",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"jest": "29.3.0",
|
||||
"jest-environment-jsdom": "29.3.0",
|
||||
"next": "13.5.2",
|
||||
"next": "14.0.4",
|
||||
"passport-mock-strategy": "2.0.0",
|
||||
"passport-twitter": "1.0.4",
|
||||
"prisma": "4.6.1",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
import {api} from "src/blitz-server"
|
||||
|
||||
export default api(rpcHandler({onError: console.log}))
|
||||
export default api(rpcHandler({onError: (error, ctx) => console.log(error)}))
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
"prisma:studio": "prisma studio"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@hookform/error-message": "2.0.0",
|
||||
"@hookform/resolvers": "2.9.10",
|
||||
"@prisma/client": "4.6.1",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"delay": "5.0.0",
|
||||
"next": "13.5.2",
|
||||
"next": "14.0.4",
|
||||
"prisma": "4.6.1",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
import {api} from "../../../blitz-server"
|
||||
|
||||
export default api(rpcHandler({onError: console.log}))
|
||||
export default api(rpcHandler({onError: (error, ctx) => console.log(error)}))
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
"prisma:studio": "prisma studio"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@prisma/client": "4.6.1",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"lowdb": "3.0.0",
|
||||
"next": "13.5.2",
|
||||
"next": "14.0.4",
|
||||
"prisma": "4.6.1",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
"schema": "db/schema.prisma"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@prisma/client": "4.6.1",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"lowdb": "3.0.0",
|
||||
"next": "13.5.2",
|
||||
"next": "14.0.4",
|
||||
"prisma": "4.6.1",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@next/bundle-analyzer": "12.0.8",
|
||||
"@types/express": "4.17.13",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
import {api} from "../../../app/blitz-server"
|
||||
|
||||
export default api(rpcHandler({onError: console.log}))
|
||||
export default api(rpcHandler({onError: (error, ctx) => console.log(error)}))
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf .next"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"next": "13.5.2",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"next": "14.0.4",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
},
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
|
||||
export default rpcHandler({onError: console.log})
|
||||
export default rpcHandler({onError: (error, ctx) => console.log(error)})
|
||||
|
||||
@@ -1,6 +1,2 @@
|
||||
const {withBlitz} = require("@blitzjs/next")
|
||||
module.exports = withBlitz({
|
||||
experimental: {
|
||||
appDir: true,
|
||||
},
|
||||
})
|
||||
module.exports = withBlitz({})
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
"prisma:studio": "prisma studio"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@prisma/client": "4.6.1",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"lowdb": "3.0.0",
|
||||
"next": "13.5.2",
|
||||
"next": "14.0.4",
|
||||
"prisma": "4.6.1",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
import {api} from "../../../src/blitz-server"
|
||||
|
||||
export default api(rpcHandler({onError: console.log}))
|
||||
export default api(rpcHandler({onError: (error, ctx) => console.log(error)}))
|
||||
|
||||
@@ -6,7 +6,7 @@ import {BlitzRpcPlugin} from "@blitzjs/rpc"
|
||||
export const {withBlitz, useSession, queryClient, BlitzProvider} = setupBlitzClient({
|
||||
plugins: [
|
||||
AuthClientPlugin({
|
||||
cookiePrefix: "web-cookie-prefix",
|
||||
cookiePrefix: "auth-tests-cookie-prefix",
|
||||
}),
|
||||
BlitzRpcPlugin({}),
|
||||
],
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
"prisma:studio": "prisma studio"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@prisma/client": "4.6.1",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"lowdb": "3.0.0",
|
||||
"next": "13.5.2",
|
||||
"next": "14.0.4",
|
||||
"prisma": "4.6.1",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@next/bundle-analyzer": "12.0.8",
|
||||
"@types/express": "4.17.13",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
import {api} from "../../../app/blitz-server"
|
||||
|
||||
export default api(rpcHandler({onError: console.log}))
|
||||
export default api(rpcHandler({onError: (error, ctx) => console.log(error)}))
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@prisma/client": "4.6.1",
|
||||
"@tanstack/react-query": "4.0.10",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"next": "13.5.2",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"next": "14.0.4",
|
||||
"prisma": "4.6.1",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {describe, it, expect, beforeAll, vi} from "vitest"
|
||||
import {act, screen, waitForElementToBeRemoved, waitFor} from "@testing-library/react"
|
||||
import {useQuery, useInfiniteQuery, BlitzRpcPlugin, QueryClientProvider} from "@blitzjs/rpc"
|
||||
import {act, screen, waitForElementToBeRemoved} from "@testing-library/react"
|
||||
import {useQuery, useInfiniteQuery, BlitzRpcPlugin, BlitzProvider} from "@blitzjs/rpc"
|
||||
import React from "react"
|
||||
import delay from "delay"
|
||||
import {buildMutationRpc, buildQueryRpc, mockRouter, render} from "../../utils/blitz-test-utils"
|
||||
@@ -44,9 +44,9 @@ describe("useQuery", () => {
|
||||
|
||||
const {rerender} = render(ui(), {
|
||||
wrapper: ({children}) => (
|
||||
<QueryClientProvider client={globalThis.queryClient}>
|
||||
<BlitzProvider>
|
||||
<RouterContext.Provider value={mockRouter}>{children}</RouterContext.Provider>
|
||||
</QueryClientProvider>
|
||||
</BlitzProvider>
|
||||
),
|
||||
})
|
||||
return [res, () => rerender(ui())]
|
||||
@@ -117,9 +117,9 @@ describe("useQuery", () => {
|
||||
|
||||
const {rerender} = render(ui(), {
|
||||
wrapper: ({children}) => (
|
||||
<QueryClientProvider client={globalThis.queryClient}>
|
||||
<BlitzProvider>
|
||||
<RouterContext.Provider value={mockRouter}>{children}</RouterContext.Provider>
|
||||
</QueryClientProvider>
|
||||
</BlitzProvider>
|
||||
),
|
||||
})
|
||||
})
|
||||
@@ -163,9 +163,9 @@ describe("useInfiniteQuery", () => {
|
||||
|
||||
const {rerender} = render(ui(), {
|
||||
wrapper: ({children}) => (
|
||||
<QueryClientProvider client={globalThis.queryClient}>
|
||||
<BlitzProvider>
|
||||
<RouterContext.Provider value={mockRouter}>{children}</RouterContext.Provider>
|
||||
</QueryClientProvider>
|
||||
</BlitzProvider>
|
||||
),
|
||||
})
|
||||
return [res, () => rerender(ui())]
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
"schema": "db/schema.prisma"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@prisma/client": "4.6.1",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"lowdb": "3.0.0",
|
||||
"next": "13.5.2",
|
||||
"next": "14.0.4",
|
||||
"prisma": "4.6.1",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@next/bundle-analyzer": "12.0.8",
|
||||
"@types/express": "4.17.13",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
import {api} from "../../../app/blitz-server"
|
||||
|
||||
export default api(rpcHandler({onError: console.log}))
|
||||
export default api(rpcHandler({onError: (error, ctx) => console.log(error)}))
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf .next"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"next": "13.5.2",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"next": "14.0.4",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
},
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
|
||||
export default rpcHandler({onError: console.log})
|
||||
export default rpcHandler({onError: (error, ctx) => console.log(error)})
|
||||
|
||||
1
integration-tests/rpc/next-env.d.ts
vendored
1
integration-tests/rpc/next-env.d.ts
vendored
@@ -1,5 +1,6 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
/// <reference types="next/navigation-types/compat/navigation" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf .next"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"next": "13.5.2",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"next": "14.0.4",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
},
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
|
||||
export default rpcHandler({onError: console.log})
|
||||
export default rpcHandler({onError: (error, ctx) => console.log(error)})
|
||||
|
||||
@@ -162,13 +162,6 @@ function runTests(dev = false) {
|
||||
5000 * 60 * 2,
|
||||
)
|
||||
})
|
||||
|
||||
if (!dev) {
|
||||
it("should show warning with next export", async () => {
|
||||
const {stderr} = await nextExport(appDir, {outdir: join(appDir, "out")}, {stderr: true})
|
||||
expect(stderr).toContain("https://nextjs.org/docs/messages/api-routes-static-export")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
describe("RPC", () => {
|
||||
|
||||
@@ -13,8 +13,14 @@
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve"
|
||||
"jsx": "preserve",
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"strictNullChecks": true
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "types"],
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "types", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
"schema": "db/schema.prisma"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/next": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/next": "2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@prisma/client": "4.6.1",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"lowdb": "3.0.0",
|
||||
"next": "13.5.2",
|
||||
"next": "14.0.4",
|
||||
"prisma": "4.6.1",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@next/bundle-analyzer": "12.0.8",
|
||||
"@types/express": "4.17.13",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {rpcHandler} from "@blitzjs/rpc"
|
||||
import {api} from "../../../app/blitz-server"
|
||||
|
||||
export default api(rpcHandler({onError: console.log}))
|
||||
export default api(rpcHandler({onError: (error, ctx) => console.log(error)}))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from "react"
|
||||
import {vi} from "vitest"
|
||||
import {QueryClient} from "@tanstack/react-query"
|
||||
import {BlitzRpcPlugin, QueryClientProvider} from "@blitzjs/rpc"
|
||||
import {BlitzRpcPlugin, BlitzProvider} from "@blitzjs/rpc"
|
||||
import {NextRouter} from "next/router"
|
||||
import {RouterContext} from "@blitzjs/next"
|
||||
import {render as defaultRender} from "@testing-library/react"
|
||||
@@ -40,22 +40,6 @@ export type BlitzProviderProps = {
|
||||
contextSharing?: boolean
|
||||
}
|
||||
|
||||
const BlitzProvider = ({
|
||||
client,
|
||||
contextSharing = false,
|
||||
children,
|
||||
}: BlitzProviderProps & {children: JSX.Element}) => {
|
||||
if (globalThis.queryClient) {
|
||||
return (
|
||||
<QueryClientProvider client={globalThis.queryClient} contextSharing={contextSharing}>
|
||||
{children}
|
||||
</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
|
||||
const compose =
|
||||
(...rest) =>
|
||||
(x: React.ComponentType<any>) =>
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "workspace:2.0.0-beta.36",
|
||||
"@blitzjs/next": "workspace:2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "workspace:2.0.0-beta.36",
|
||||
"@blitzjs/config": "workspace:2.0.0-beta.37",
|
||||
"@blitzjs/next": "workspace:2.0.0-beta.37",
|
||||
"@blitzjs/rpc": "workspace:2.0.0-beta.37",
|
||||
"@tanstack/react-query": "4.13.0",
|
||||
"@testing-library/react": "13.4.0",
|
||||
"@types/express": "4.17.13",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"husky": "8.0.2",
|
||||
"jsdom": "^19.0.0",
|
||||
"lint-staged": "13.0.3",
|
||||
"next": "13.5.2",
|
||||
"next": "14.0.4",
|
||||
"only-allow": "1.1.0",
|
||||
"prettier": "^2.7.1",
|
||||
"prettier-plugin-prisma": "4.4.0",
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
# @blitzjs/auth
|
||||
|
||||
## 2.0.0-beta.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- b84c5bedb: Next 14 Compatibility
|
||||
- Updated dependencies [86e8eb7c8]
|
||||
- Updated dependencies [b84c5bedb]
|
||||
- blitz@2.0.0-beta.37
|
||||
|
||||
## 2.0.0-beta.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/auth",
|
||||
"version": "2.0.0-beta.36",
|
||||
"version": "2.0.0-beta.37",
|
||||
"homepage": "https://blitzjs.com/",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -50,7 +50,7 @@
|
||||
"url": "0.11.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"next": "*",
|
||||
"next-auth": "*",
|
||||
"secure-password": "4.0.0"
|
||||
@@ -67,7 +67,7 @@
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@testing-library/react": "13.4.0",
|
||||
"@testing-library/react-hooks": "8.0.1",
|
||||
"@types/cookie": "0.4.1",
|
||||
@@ -75,8 +75,8 @@
|
||||
"@types/jsonwebtoken": "8.5.8",
|
||||
"@types/react": "18.0.25",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"next": "13.5.2",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"next": "14.0.4",
|
||||
"next-auth": "4.18.7",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {fromBase64} from "b64-lite"
|
||||
import _BadBehavior from "bad-behavior"
|
||||
import {useEffect, useState} from "react"
|
||||
import {UrlObject} from "url"
|
||||
import React, {ComponentPropsWithoutRef} from "react"
|
||||
import {
|
||||
@@ -171,9 +170,9 @@ export const useSession = (options: UseSessionOptions = {}): ClientSession => {
|
||||
initialState = {...emptyPublicData, isLoading: true}
|
||||
}
|
||||
|
||||
const [session, setSession] = useState(initialState)
|
||||
const [session, setSession] = React.useState(initialState)
|
||||
|
||||
useEffect(() => {
|
||||
React.useEffect(() => {
|
||||
// Initialize on mount
|
||||
setSession({...getPublicDataStore().getData(), isLoading: false})
|
||||
const subscription = getPublicDataStore().observable.subscribe((data) =>
|
||||
@@ -186,8 +185,8 @@ export const useSession = (options: UseSessionOptions = {}): ClientSession => {
|
||||
}
|
||||
|
||||
export const useAuthorizeIf = (condition?: boolean, role?: string | Array<string>) => {
|
||||
const [mounted, setMounted] = useState(false)
|
||||
useEffect(() => {
|
||||
const [mounted, setMounted] = React.useState(false)
|
||||
React.useEffect(() => {
|
||||
setMounted(true)
|
||||
}, [])
|
||||
|
||||
@@ -233,9 +232,9 @@ export const useAuthenticatedSession = (
|
||||
}
|
||||
|
||||
export const useRedirectAuthenticated = (to: UrlObject | string) => {
|
||||
const [mounted, setMounted] = useState(false)
|
||||
const [mounted, setMounted] = React.useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
React.useEffect(() => {
|
||||
setMounted(true)
|
||||
}, [])
|
||||
|
||||
@@ -303,9 +302,9 @@ export function getAuthValues<TProps = any>(
|
||||
function withBlitzAuthPlugin<TProps = any>(Page: ComponentType<TProps> | BlitzPage<TProps>) {
|
||||
const AuthRoot = (props: ComponentProps<any>) => {
|
||||
useSession({suspense: false})
|
||||
const [mounted, setMounted] = useState(false)
|
||||
const [mounted, setMounted] = React.useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
React.useEffect(() => {
|
||||
setMounted(true)
|
||||
}, [])
|
||||
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
# @blitzjs/next
|
||||
|
||||
## 2.0.0-beta.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- b84c5bedb: Next 14 Compatibility
|
||||
- Updated dependencies [86e8eb7c8]
|
||||
- Updated dependencies [b84c5bedb]
|
||||
- Updated dependencies [e5cd2c862]
|
||||
- @blitzjs/rpc@2.0.0-beta.37
|
||||
- blitz@2.0.0-beta.37
|
||||
|
||||
## 2.0.0-beta.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {BuildConfig} from "unbuild"
|
||||
|
||||
const config: BuildConfig = {
|
||||
entries: ["./src/index-browser", "./src/index-server"],
|
||||
entries: ["./src/index-browser", "./src/index-server", "./src/provider"],
|
||||
externals: ["index-browser.cjs", "index-browser.mjs", "blitz", ".blitz"],
|
||||
declaration: true,
|
||||
rollup: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/next",
|
||||
"version": "2.0.0-beta.36",
|
||||
"version": "2.0.0-beta.37",
|
||||
"homepage": "https://blitzjs.com/",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -29,7 +29,7 @@
|
||||
"eslint.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@blitzjs/rpc": "2.0.0-beta.36",
|
||||
"@blitzjs/rpc": "2.0.0-beta.37",
|
||||
"@types/hoist-non-react-statics": "3.3.1",
|
||||
"debug": "4.3.3",
|
||||
"fs-extra": "10.0.1",
|
||||
@@ -38,13 +38,13 @@
|
||||
"supports-color": "8.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"next": "*",
|
||||
"react": "*",
|
||||
"tslog": "4.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@testing-library/dom": "8.13.0",
|
||||
"@testing-library/jest-dom": "5.16.3",
|
||||
"@testing-library/react": "13.4.0",
|
||||
@@ -55,10 +55,10 @@
|
||||
"@types/react": "18.0.25",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"@types/testing-library__react-hooks": "4.0.0",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"cross-spawn": "7.0.3",
|
||||
"find-up": "4.1.0",
|
||||
"next": "13.5.2",
|
||||
"next": "14.0.4",
|
||||
"next-router-mock": "0.9.1",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
|
||||
@@ -212,7 +212,7 @@ test("withErrorBoundary HOC", () => {
|
||||
{
|
||||
"componentStack": "
|
||||
at __vite_ssr_import_4__.withErrorBoundary.FallbackComponent
|
||||
at ErrorBoundaryRoot
|
||||
at ErrorBoundary2
|
||||
at WithRouterWrapper
|
||||
at withErrorBoundary",
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import {RedirectError} from "blitz"
|
||||
import {NextRouter, withRouter} from "next/router"
|
||||
import {useRouter} from "next/compat/router"
|
||||
import type {NextRouter} from "next/router"
|
||||
import * as React from "react"
|
||||
import {RouterContext} from "./router-context"
|
||||
import _debug from "debug"
|
||||
import {ExcludeRouterProps} from "next/dist/client/with-router"
|
||||
import type {ExcludeRouterProps, WithRouterProps} from "next/dist/client/with-router"
|
||||
|
||||
const debug = _debug("blitz:errorboundary")
|
||||
|
||||
@@ -73,10 +74,18 @@ type ErrorBoundaryState = {error: Error | null}
|
||||
|
||||
const initialState: ErrorBoundaryState = {error: null}
|
||||
|
||||
const ErrorBoundary: React.ComponentType<
|
||||
ExcludeRouterProps<React.PropsWithChildren<ErrorBoundaryProps>>
|
||||
> = withRouter(
|
||||
class ErrorBoundaryRoot extends React.Component<
|
||||
function withRouter<P extends WithRouterProps>(
|
||||
ComposedComponent: React.ComponentType<P>,
|
||||
): React.ComponentType<ExcludeRouterProps<P>> {
|
||||
function WithRouterWrapper(props: any): JSX.Element {
|
||||
return <ComposedComponent router={useRouter()} {...props} />
|
||||
}
|
||||
|
||||
return WithRouterWrapper
|
||||
}
|
||||
|
||||
export const ErrorBoundary = withRouter(
|
||||
class ErrorBoundary extends React.Component<
|
||||
React.PropsWithRef<React.PropsWithChildren<ErrorBoundaryProps>>,
|
||||
ErrorBoundaryState
|
||||
> {
|
||||
@@ -207,7 +216,7 @@ function useErrorHandler(givenError?: unknown): (error: unknown) => void {
|
||||
return setError
|
||||
}
|
||||
|
||||
export {ErrorBoundary, withErrorBoundary, useErrorHandler}
|
||||
export {withErrorBoundary, useErrorHandler}
|
||||
export type {
|
||||
ErrorFallbackProps,
|
||||
ErrorBoundaryPropsWithComponent,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {QueryClient} from "@blitzjs/rpc"
|
||||
import type {QueryClient} from "@blitzjs/rpc"
|
||||
|
||||
declare global {
|
||||
var queryClient: QueryClient
|
||||
|
||||
@@ -24,14 +24,14 @@ import {
|
||||
stopWatcher,
|
||||
} from "blitz"
|
||||
import {
|
||||
DefaultOptions,
|
||||
dehydrate,
|
||||
getInfiniteQueryKey,
|
||||
getQueryKey,
|
||||
installWebpackConfig,
|
||||
InstallWebpackConfigOptions,
|
||||
QueryClient,
|
||||
ResolverPathOptions,
|
||||
DefaultOptions,
|
||||
dehydrate,
|
||||
QueryClient,
|
||||
} from "@blitzjs/rpc"
|
||||
import {IncomingMessage, ServerResponse} from "http"
|
||||
import {withSuperJsonProps} from "./superjson"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {QueryClientProvider, Hydrate} from "@blitzjs/rpc"
|
||||
import type {HydrateOptions, QueryClient} from "@blitzjs/rpc"
|
||||
import type {QueryClient, HydrateOptions} from "@blitzjs/rpc"
|
||||
import React from "react"
|
||||
|
||||
export type BlitzProviderProps = {
|
||||
|
||||
@@ -44,18 +44,18 @@ const mockRouter: NextRouter = {
|
||||
emit: vi.fn(),
|
||||
},
|
||||
isFallback: false,
|
||||
forward: vi.fn(),
|
||||
}
|
||||
|
||||
export function renderHook(
|
||||
hook: RenderHook,
|
||||
{wrapper, router, dehydratedState, ...options}: RenderHookOptions = {},
|
||||
{router, dehydratedState, ...options}: RenderHookOptions = {},
|
||||
) {
|
||||
if (!wrapper) {
|
||||
wrapper = ({children}) => (
|
||||
const wrapper = ({children}: {children: React.ReactNode}) =>
|
||||
(
|
||||
<RouterContext.Provider value={{...mockRouter, ...router}}>{children}</RouterContext.Provider>
|
||||
)
|
||||
wrapper.displayName = "wrapper"
|
||||
}
|
||||
) as React.ReactElement
|
||||
wrapper.displayName = "wrapper"
|
||||
|
||||
return defaultRenderHook(hook, {wrapper, ...options})
|
||||
}
|
||||
@@ -97,14 +97,14 @@ describe("useParams", () => {
|
||||
})
|
||||
|
||||
it("works without parameter", () => {
|
||||
vi.mock("next/router", () => {
|
||||
vi.mock("next/compat/router", () => {
|
||||
return {
|
||||
useRouter: vi.fn(() => ({...mockRouter, query})),
|
||||
}
|
||||
})
|
||||
|
||||
it("works with string", () => {
|
||||
vi.mock("next/router", () => {
|
||||
vi.mock("next/compat/router", () => {
|
||||
return {
|
||||
useRouter: vi.fn(() => ({...mockRouter, query})),
|
||||
}
|
||||
@@ -121,7 +121,7 @@ describe("useParams", () => {
|
||||
})
|
||||
|
||||
it("works with string", () => {
|
||||
vi.mock("next/router", () => {
|
||||
vi.mock("next/compat/router", () => {
|
||||
return {
|
||||
useRouter: vi.fn(() => ({...mockRouter, query})),
|
||||
}
|
||||
@@ -138,7 +138,7 @@ describe("useParams", () => {
|
||||
})
|
||||
|
||||
it("works with number", () => {
|
||||
vi.mock("next/router", () => {
|
||||
vi.mock("next/compat/router", () => {
|
||||
return {
|
||||
useRouter: vi.fn(() => ({...mockRouter, query})),
|
||||
}
|
||||
@@ -155,7 +155,7 @@ describe("useParams", () => {
|
||||
})
|
||||
|
||||
it("works with array", () => {
|
||||
vi.mock("next/router", () => {
|
||||
vi.mock("next/compat/router", () => {
|
||||
return {
|
||||
useRouter: vi.fn(() => ({...mockRouter, query})),
|
||||
}
|
||||
@@ -180,7 +180,7 @@ describe("useParam", () => {
|
||||
})
|
||||
|
||||
it("works without parameter", () => {
|
||||
vi.mock("next/router", () => {
|
||||
vi.mock("next/compat/router", () => {
|
||||
return {
|
||||
useRouter: vi.fn(() => ({...mockRouter, query})),
|
||||
}
|
||||
@@ -201,7 +201,7 @@ describe("useParam", () => {
|
||||
})
|
||||
|
||||
it("works with string", () => {
|
||||
vi.mock("next/router", () => {
|
||||
vi.mock("next/compat/router", () => {
|
||||
return {
|
||||
useRouter: vi.fn(() => ({...mockRouter, query})),
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {useRouter} from "next/router"
|
||||
import {useRouter} from "next/compat/router"
|
||||
import {ParsedUrlQuery} from "querystring"
|
||||
import React from "react"
|
||||
|
||||
@@ -32,14 +32,14 @@ function decode(str: string) {
|
||||
return out
|
||||
}
|
||||
|
||||
export function extractQueryFromAsPath(asPath: string) {
|
||||
return decode(asPath.split("?", 2)[1] as string)
|
||||
export function extractQueryFromAsPath(asPath?: string) {
|
||||
return decode(asPath?.split("?", 2)[1] as string)
|
||||
}
|
||||
|
||||
export function useRouterQuery() {
|
||||
const router = useRouter()
|
||||
|
||||
const query = React.useMemo(() => extractQueryFromAsPath(router.asPath), [router.asPath])
|
||||
const query = React.useMemo(() => extractQueryFromAsPath(router?.asPath), [router?.asPath])
|
||||
|
||||
return query
|
||||
}
|
||||
@@ -68,9 +68,12 @@ function areQueryValuesEqual(value1: ParsedUrlQueryValue, value2: ParsedUrlQuery
|
||||
return value1 === value2
|
||||
}
|
||||
|
||||
export function extractRouterParams(routerQuery: ParsedUrlQuery, asPathQuery: ParsedUrlQuery) {
|
||||
export function extractRouterParams(
|
||||
routerQuery: ParsedUrlQuery | undefined,
|
||||
asPathQuery: ParsedUrlQuery,
|
||||
) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(routerQuery).filter(
|
||||
Object.entries(routerQuery || {}).filter(
|
||||
([key, value]) =>
|
||||
typeof asPathQuery[key] === "undefined" || !areQueryValuesEqual(value, asPathQuery[key]),
|
||||
),
|
||||
@@ -87,7 +90,7 @@ export function useParams(returnType?: ReturnTypes | undefined) {
|
||||
const query = useRouterQuery()
|
||||
|
||||
const params = React.useMemo(() => {
|
||||
const rawParams = extractRouterParams(router.query, query)
|
||||
const rawParams = extractRouterParams(router?.query, query)
|
||||
|
||||
if (returnType === "string") {
|
||||
const parsedParams: Dict<string> = {}
|
||||
@@ -124,7 +127,7 @@ export function useParams(returnType?: ReturnTypes | undefined) {
|
||||
}
|
||||
|
||||
return rawParams
|
||||
}, [router.query, query, returnType])
|
||||
}, [router?.query, query, returnType])
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
@@ -5,11 +5,13 @@ const filesToModify = [
|
||||
"dist/index-browser.mjs",
|
||||
"dist/chunks/index-browser.cjs",
|
||||
"dist/chunks/index-browser.mjs",
|
||||
"dist/provider.mjs",
|
||||
"dist/provider.cjs",
|
||||
]
|
||||
|
||||
const addDirectives = (filePath) => {
|
||||
const fileContent = fs.readFileSync(filePath, "utf8")
|
||||
const newFileContent = "'use client';\n" + fileContent
|
||||
const newFileContent = '"use client";\n' + fileContent
|
||||
fs.writeFileSync(filePath, newFileContent)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
# @blitzjs/rpc
|
||||
|
||||
## 2.0.0-beta.37
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- e5cd2c862: expose `ctx` to `rpcHandler` error callbacks in [[...blitz]].ts files
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 86e8eb7c8: Add helpful error message when RPC resolvers have the same path
|
||||
- b84c5bedb: Next 14 Compatibility
|
||||
- Updated dependencies [86e8eb7c8]
|
||||
- Updated dependencies [b84c5bedb]
|
||||
- blitz@2.0.0-beta.37
|
||||
|
||||
## 2.0.0-beta.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/rpc",
|
||||
"version": "2.0.0-beta.36",
|
||||
"version": "2.0.0-beta.37",
|
||||
"homepage": "https://blitzjs.com/",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -37,19 +37,19 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@tanstack/query-core": "4.24.4",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"next": "*",
|
||||
"react": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/auth": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/auth": "2.0.0-beta.37",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@tanstack/query-core": "4.24.4",
|
||||
"@types/debug": "4.1.7",
|
||||
"@types/react": "18.0.25",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"next": "13.5.2",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"next": "14.0.4",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"typescript": "^4.8.4",
|
||||
|
||||
@@ -1,4 +1,32 @@
|
||||
import "./global"
|
||||
export * from "./client/index"
|
||||
export * from "./query/react-query"
|
||||
export {
|
||||
BlitzProvider,
|
||||
BlitzRpcPlugin,
|
||||
QueryClient,
|
||||
dehydrate,
|
||||
getInfiniteQueryKey,
|
||||
getQueryClient,
|
||||
getQueryData,
|
||||
getQueryKey,
|
||||
invalidateQuery,
|
||||
setQueryData,
|
||||
useInfiniteQuery,
|
||||
useMutation,
|
||||
usePaginatedQuery,
|
||||
useQuery,
|
||||
} from "./query/react-query"
|
||||
export type {
|
||||
DefaultOptions,
|
||||
HydrateOptions,
|
||||
MutateFunction,
|
||||
MutationFunction,
|
||||
MutationResultPair,
|
||||
RestPaginatedResult,
|
||||
RestQueryResult,
|
||||
} from "./query/react-query"
|
||||
export * from "./query/utils"
|
||||
|
||||
import {reactQueryClientReExports} from "./query/react-query"
|
||||
const {QueryClientProvider, Hydrate, useQueryErrorResetBoundary} = reactQueryClientReExports
|
||||
export {QueryClientProvider, Hydrate, useQueryErrorResetBoundary}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {assert, ResolverConfig} from "blitz"
|
||||
import {assert, Ctx, ResolverConfig} from "blitz"
|
||||
import {NextApiRequest, NextApiResponse} from "next"
|
||||
import {deserialize, parse, serialize as superjsonSerialize} from "superjson"
|
||||
import {resolve} from "path"
|
||||
import {LoaderOptions} from "./server/loader/utils/loader-utils"
|
||||
import {deserialize, parse, serialize as superjsonSerialize} from "superjson"
|
||||
import {RpcLogger} from "./rpc-logger"
|
||||
import {LoaderOptions} from "./server/loader/utils/loader-utils"
|
||||
import {RpcLoggerOptions} from "./server/plugin"
|
||||
|
||||
// TODO - optimize end user server bundles by not exporting all client stuff here
|
||||
@@ -32,7 +32,13 @@ function getGlobalObject<T extends Record<string, unknown>>(key: string, default
|
||||
}
|
||||
|
||||
type Resolver = (...args: unknown[]) => Promise<unknown>
|
||||
type ResolverFiles = Record<string, () => Promise<{default?: Resolver; config?: ResolverConfig}>>
|
||||
type ResolverFiles = Record<
|
||||
string,
|
||||
{
|
||||
absoluteResolverPath: string
|
||||
resolver: () => Promise<{default?: Resolver; config?: ResolverConfig}>
|
||||
}
|
||||
>
|
||||
export type ResolverPathOptions = "queries|mutations" | "root" | ((path: string) => string)
|
||||
|
||||
// We define `global.__internal_blitzRpcResolverFiles` to ensure we use the same global object.
|
||||
@@ -50,10 +56,46 @@ export function loadBlitzRpcResolverFilesWithInternalMechanism() {
|
||||
|
||||
export function __internal_addBlitzRpcResolver(
|
||||
routePath: string,
|
||||
absoluteResolverPath: string,
|
||||
resolver: () => Promise<{default?: Resolver; config?: ResolverConfig}>,
|
||||
) {
|
||||
g.blitzRpcResolverFilesLoaded = g.blitzRpcResolverFilesLoaded || {}
|
||||
g.blitzRpcResolverFilesLoaded[routePath] = resolver
|
||||
const existingResolver = g.blitzRpcResolverFilesLoaded[routePath]
|
||||
if (existingResolver && existingResolver.absoluteResolverPath !== absoluteResolverPath) {
|
||||
const logger = new RpcLogger(routePath)
|
||||
const errorMessage = `\nThe following resolver files resolve to the same path: ${routePath}\n\n1. ${absoluteResolverPath}\n2. ${
|
||||
existingResolver.absoluteResolverPath
|
||||
}\n\nPossible Solutions:\n\n1. Remove or rename one of the resolver files. \n2. Set the following in your in next.config.js to load all resolvers using their absolute paths:
|
||||
\n\n//next.config.js\nblitz:{\n resolverPath: "root",\n},\n
|
||||
\n${
|
||||
process.env.NODE_ENV === "production"
|
||||
? `Resolver in ${absoluteResolverPath} is currently being shadowed by ${existingResolver.absoluteResolverPath}`
|
||||
: ""
|
||||
}
|
||||
`
|
||||
logger.error(errorMessage)
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
g.blitzRpcResolverFilesLoaded[routePath] = {
|
||||
absoluteResolverPath,
|
||||
resolver: async () => {
|
||||
return {
|
||||
...(await resolver()),
|
||||
default: async () => {
|
||||
const error = new Error(errorMessage)
|
||||
error.name = "BlitzRPCResolverCollisionError"
|
||||
error.stack = ""
|
||||
throw error
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
} else {
|
||||
g.blitzRpcResolverFilesLoaded[routePath] = {
|
||||
absoluteResolverPath,
|
||||
resolver,
|
||||
}
|
||||
}
|
||||
return resolver
|
||||
}
|
||||
|
||||
@@ -145,13 +187,13 @@ async function getResolverMap(): Promise<ResolverFiles | null | undefined> {
|
||||
}
|
||||
|
||||
interface RpcConfig {
|
||||
onError?: (error: Error) => void
|
||||
formatError?: (error: Error) => Error
|
||||
onError?: (error: Error, ctx: Ctx) => void
|
||||
formatError?: (error: Error, ctx: Ctx) => Error
|
||||
logging?: RpcLoggerOptions
|
||||
}
|
||||
|
||||
export function rpcHandler(config: RpcConfig) {
|
||||
return async function handleRpcRequest(req: NextApiRequest, res: NextApiResponse) {
|
||||
return async function handleRpcRequest(req: NextApiRequest, res: NextApiResponse, ctx: Ctx) {
|
||||
const resolverMap = await getResolverMap()
|
||||
assert(resolverMap, "No query or mutation resolvers found")
|
||||
assert(
|
||||
@@ -164,7 +206,7 @@ export function rpcHandler(config: RpcConfig) {
|
||||
const resolverName = routePath.replace(/(\/api\/rpc)?\//, "")
|
||||
const rpcLogger = new RpcLogger(resolverName, config.logging)
|
||||
|
||||
const loadableResolver = resolverMap?.[routePath]
|
||||
const loadableResolver = resolverMap?.[routePath]?.resolver
|
||||
if (!loadableResolver) {
|
||||
throw new Error("No resolver for path: " + routePath)
|
||||
}
|
||||
@@ -237,17 +279,17 @@ export function rpcHandler(config: RpcConfig) {
|
||||
return
|
||||
} catch (error: any) {
|
||||
if (error._clearStack) {
|
||||
delete error.stack
|
||||
error.stack = ""
|
||||
}
|
||||
|
||||
config.onError?.(error)
|
||||
config.onError?.(error, ctx)
|
||||
rpcLogger.error(error)
|
||||
|
||||
if (!error.statusCode) {
|
||||
error.statusCode = 500
|
||||
}
|
||||
|
||||
const formattedError = config.formatError?.(error) ?? error
|
||||
const formattedError = config.formatError?.(error, ctx) ?? error
|
||||
const serializedError = superjsonSerialize(formattedError)
|
||||
|
||||
res.json({
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import {useQueryErrorResetBoundary, QueryClientProvider, Hydrate} from "@tanstack/react-query"
|
||||
|
||||
export {useQueryErrorResetBoundary, QueryClientProvider, Hydrate}
|
||||
|
||||
import {useInfiniteQuery as useInfiniteReactQuery} from "@tanstack/react-query"
|
||||
|
||||
import {useQuery as useReactQuery} from "@tanstack/react-query"
|
||||
|
||||
import {useMutation as useReactQueryMutation} from "@tanstack/react-query"
|
||||
|
||||
export const reactQueryClientReExports = {
|
||||
useQueryErrorResetBoundary,
|
||||
QueryClientProvider,
|
||||
Hydrate,
|
||||
}
|
||||
|
||||
import type {
|
||||
UseInfiniteQueryOptions,
|
||||
UseInfiniteQueryResult,
|
||||
@@ -28,7 +30,7 @@ import {
|
||||
sanitizeMutation,
|
||||
getInfiniteQueryKey,
|
||||
} from "../utils"
|
||||
import {useRouter} from "next/router"
|
||||
import {useRouter} from "next/compat/router"
|
||||
|
||||
type QueryLazyOptions = {suspense: unknown} | {enabled: unknown}
|
||||
type QueryNonLazyOptions =
|
||||
@@ -84,10 +86,10 @@ export function useQuery<
|
||||
const suspenseEnabled = Boolean(globalThis.__BLITZ_SUSPENSE_ENABLED)
|
||||
let enabled = isServer && suspenseEnabled ? false : options?.enabled ?? options?.enabled !== null
|
||||
let routerIsReady = false
|
||||
try {
|
||||
const router = useRouter()
|
||||
routerIsReady = router.isReady || (isServer && suspenseEnabled)
|
||||
} catch (e) {
|
||||
const router = useRouter()
|
||||
if (router) {
|
||||
routerIsReady = router?.isReady || (isServer && suspenseEnabled)
|
||||
} else {
|
||||
routerIsReady = true
|
||||
}
|
||||
const enhancedResolverRpcClient = sanitizeQuery(queryFn)
|
||||
@@ -171,10 +173,10 @@ export function usePaginatedQuery<
|
||||
const suspenseEnabled = Boolean(globalThis.__BLITZ_SUSPENSE_ENABLED)
|
||||
let enabled = isServer && suspenseEnabled ? false : options?.enabled ?? options?.enabled !== null
|
||||
let routerIsReady = false
|
||||
try {
|
||||
const router = useRouter()
|
||||
routerIsReady = router.isReady || (isServer && suspenseEnabled)
|
||||
} catch (e) {
|
||||
const router = useRouter()
|
||||
if (router) {
|
||||
routerIsReady = router?.isReady || (isServer && suspenseEnabled)
|
||||
} else {
|
||||
routerIsReady = true
|
||||
}
|
||||
const enhancedResolverRpcClient = sanitizeQuery(queryFn)
|
||||
@@ -268,10 +270,10 @@ export function useInfiniteQuery<
|
||||
const suspenseEnabled = Boolean(globalThis.__BLITZ_SUSPENSE_ENABLED)
|
||||
let enabled = isServer && suspenseEnabled ? false : options?.enabled ?? options?.enabled !== null
|
||||
let routerIsReady = false
|
||||
try {
|
||||
const router = useRouter()
|
||||
routerIsReady = router.isReady || (isServer && suspenseEnabled)
|
||||
} catch (e) {
|
||||
const router = useRouter()
|
||||
if (router) {
|
||||
routerIsReady = router?.isReady || (isServer && suspenseEnabled)
|
||||
} else {
|
||||
routerIsReady = true
|
||||
}
|
||||
const enhancedResolverRpcClient = sanitizeQuery(queryFn)
|
||||
|
||||
@@ -187,7 +187,8 @@ export function setQueryData<TInput, TResult, T extends AsyncFunc>(
|
||||
|
||||
return new Promise((res) => {
|
||||
getQueryClient().setQueryData(queryKey, newData)
|
||||
let result: void | ReturnType<ReturnType<typeof getQueryClient>["invalidateQueries"]>
|
||||
let result: void | ReturnType<ReturnType<typeof getQueryClient>["invalidateQueries"]> =
|
||||
undefined
|
||||
if (opts.refetch) {
|
||||
result = invalidateQuery(resolver, params)
|
||||
}
|
||||
|
||||
@@ -163,10 +163,11 @@ export class RpcLogger {
|
||||
newLine()
|
||||
}
|
||||
public error(e: any) {
|
||||
if (typeof e === "string") {
|
||||
if (typeof e === "string" || e instanceof Error) {
|
||||
this.#logger.error(e)
|
||||
} else {
|
||||
this.#logger.error(new Error(e))
|
||||
}
|
||||
this.#logger.error(new Error(e))
|
||||
newLine()
|
||||
}
|
||||
public warn(e: string) {
|
||||
|
||||
@@ -66,7 +66,7 @@ export async function transformBlitzRpcServer(
|
||||
|
||||
const importStrategy = options?.resolversDynamicImport ? "import" : "require"
|
||||
|
||||
code += `__internal_addBlitzRpcResolver('${routePath}',() => ${importStrategy}('${slash(
|
||||
code += `__internal_addBlitzRpcResolver('${routePath}','${resolverFilePath}',() => ${importStrategy}('${slash(
|
||||
resolverFilePath,
|
||||
)}'));`
|
||||
code += "\n"
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
createServerPlugin,
|
||||
} from "blitz"
|
||||
import {invoke} from "./invoke"
|
||||
import {RpcLogger} from "../rpc-logger"
|
||||
|
||||
export type RpcLoggerOptions = {
|
||||
/**
|
||||
@@ -47,6 +48,9 @@ export const RpcServerPlugin = createServerPlugin((options: RpcPluginOptions) =>
|
||||
} catch (error) {
|
||||
if (options.onInvokeError) {
|
||||
options.onInvokeError(error)
|
||||
} else {
|
||||
const rpcLogger = new RpcLogger((queryFn as any)._resolverName, options.logging)
|
||||
rpcLogger.error(error)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
|
||||
@@ -3,13 +3,15 @@ const fs = require("fs")
|
||||
const filesToModify = [
|
||||
"dist/chunks/utils.cjs",
|
||||
"dist/chunks/utils.mjs",
|
||||
"dist/index-browser.cjs",
|
||||
"dist/index-browser.mjs",
|
||||
"dist/index.cjs",
|
||||
"dist/index.mjs",
|
||||
]
|
||||
|
||||
const addDirectives = (filePath) => {
|
||||
const fileContent = fs.readFileSync(filePath, "utf8")
|
||||
const newFileContent = "'use client';\n" + fileContent
|
||||
const newFileContent = '"use client";\n' + fileContent
|
||||
fs.writeFileSync(filePath, newFileContent)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
# blitz
|
||||
|
||||
## 2.0.0-beta.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 86e8eb7c8: Add helpful error message when RPC resolvers have the same path
|
||||
- b84c5bedb: Next 14 Compatibility
|
||||
- Updated dependencies [6d5f9efe1]
|
||||
- @blitzjs/generator@2.0.0-beta.37
|
||||
|
||||
## 2.0.0-beta.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "blitz",
|
||||
"version": "2.0.0-beta.36",
|
||||
"version": "2.0.0-beta.37",
|
||||
"homepage": "https://blitzjs.com/",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -30,7 +30,7 @@
|
||||
"blitz": "bin/blitz"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/generator": "2.0.0-beta.36",
|
||||
"@blitzjs/generator": "2.0.0-beta.37",
|
||||
"@mrleebo/prisma-ast": "0.2.6",
|
||||
"@types/global-agent": "2.1.1",
|
||||
"arg": "5.0.1",
|
||||
@@ -80,7 +80,7 @@
|
||||
"watchpack": "2.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@types/cookie": "0.4.1",
|
||||
"@types/cross-spawn": "6.0.2",
|
||||
"@types/debug": "4.1.7",
|
||||
|
||||
@@ -3,16 +3,13 @@ import {CliCommand} from "../index"
|
||||
import prompts from "prompts"
|
||||
import {
|
||||
capitalize,
|
||||
pluralCamel,
|
||||
pluralPascal,
|
||||
singleCamel,
|
||||
singlePascal,
|
||||
uncapitalize,
|
||||
PageGenerator,
|
||||
FormGenerator,
|
||||
QueriesGenerator,
|
||||
MutationGenerator,
|
||||
MutationsGenerator,
|
||||
RouteGenerator,
|
||||
ModelGenerator,
|
||||
QueryGenerator,
|
||||
ValidationsGenerator,
|
||||
@@ -23,6 +20,7 @@ import {
|
||||
customTemplatesBlitzConfig,
|
||||
} from "@blitzjs/generator"
|
||||
import {log} from "../../logging"
|
||||
import fs from "fs-extra"
|
||||
|
||||
const getIsTypeScript = async () =>
|
||||
require("fs").existsSync(require("path").join(process.cwd(), "tsconfig.json"))
|
||||
@@ -72,18 +70,25 @@ const createCustomTemplates = async () => {
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const nextAppDirectory = fs.existsSync(require("path").join(process.cwd(), "src/app/layout.tsx"))
|
||||
? "app"
|
||||
: "pages"
|
||||
|
||||
const generatorMap = {
|
||||
[ResourceType.All]: [
|
||||
PageGenerator,
|
||||
FormGenerator,
|
||||
QueriesGenerator,
|
||||
MutationsGenerator,
|
||||
ValidationsGenerator,
|
||||
ModelGenerator,
|
||||
nextAppDirectory === "app" ? RouteGenerator : PageGenerator,
|
||||
],
|
||||
[ResourceType.Crud]: [MutationsGenerator, QueriesGenerator, ValidationsGenerator],
|
||||
[ResourceType.Model]: [ModelGenerator],
|
||||
[ResourceType.Pages]: [PageGenerator, FormGenerator],
|
||||
[ResourceType.Pages]: [
|
||||
FormGenerator,
|
||||
nextAppDirectory === "app" ? RouteGenerator : PageGenerator,
|
||||
],
|
||||
[ResourceType.Queries]: [QueriesGenerator],
|
||||
[ResourceType.Query]: [QueryGenerator],
|
||||
[ResourceType.Mutations]: [MutationsGenerator, ValidationsGenerator],
|
||||
|
||||
@@ -30,11 +30,14 @@ const installCommandMap: Record<TPkgManager, string> = {
|
||||
npm: "npm install",
|
||||
}
|
||||
|
||||
type TTemplate = "full" | "minimal"
|
||||
type TTemplate = "app" | "pages" | "minimal"
|
||||
const templates: {[key in TTemplate]: AppGeneratorOptions["template"]} = {
|
||||
full: {
|
||||
app: {
|
||||
path: "app",
|
||||
},
|
||||
pages: {
|
||||
path: "pages",
|
||||
},
|
||||
minimal: {
|
||||
path: "minimalapp",
|
||||
skipForms: true,
|
||||
@@ -75,7 +78,7 @@ let projectName: string = ""
|
||||
let projectPath: string = ""
|
||||
let projectLanguage: string | TLanguage = language.typescript
|
||||
let projectFormLib: AppGeneratorOptions["form"] = "formik"
|
||||
let projectTemplate: AppGeneratorOptions["template"] = templates.full
|
||||
let projectTemplate: AppGeneratorOptions["template"] = templates.app
|
||||
let projectPkgManger: TPkgManager = PREFERABLE_PKG_MANAGER
|
||||
let shouldInstallDeps: boolean = true
|
||||
|
||||
@@ -126,8 +129,9 @@ const determineTemplate = async () => {
|
||||
(args["--template"] && !Object.keys(templates).includes(args["--template"].toLowerCase()))
|
||||
) {
|
||||
const choices: Array<{value: keyof typeof templates; title: string}> = [
|
||||
{value: "full", title: "Full - includes DB and auth (Recommended)"},
|
||||
{value: "minimal", title: "Minimal — no DB, no auth"},
|
||||
{value: "app", title: "App Router – Full Setup: includes DB and auth (Recommended)"},
|
||||
{value: "pages", title: "Pages Router – Full Setup: includes DB and auth"},
|
||||
{value: "minimal", title: "Pages Router – Minimal setup: no DB, no auth"},
|
||||
]
|
||||
|
||||
const res = await prompts({
|
||||
@@ -270,7 +274,7 @@ const newApp: CliCommand = async () => {
|
||||
)
|
||||
}
|
||||
|
||||
postInstallSteps.push("blitz dev")
|
||||
postInstallSteps.push(`${projectPkgManger} blitz dev`)
|
||||
|
||||
console.log("\n Your new Blitz app is ready! Next steps:")
|
||||
postInstallSteps.forEach((step, index) => {
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
# @blitzjs/codemod
|
||||
|
||||
## 2.0.0-beta.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [86e8eb7c8]
|
||||
- Updated dependencies [b84c5bedb]
|
||||
- Updated dependencies [6d5f9efe1]
|
||||
- blitz@2.0.0-beta.37
|
||||
- @blitzjs/generator@2.0.0-beta.37
|
||||
|
||||
## 2.0.0-beta.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/codemod",
|
||||
"version": "2.0.0-beta.36",
|
||||
"version": "2.0.0-beta.37",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "watch unbuild src --wait=0.2",
|
||||
@@ -25,9 +25,9 @@
|
||||
"@babel/plugin-proposal-class-properties": "7.17.12",
|
||||
"@babel/plugin-syntax-jsx": "7.17.12",
|
||||
"@babel/plugin-syntax-typescript": "7.17.12",
|
||||
"@blitzjs/generator": "2.0.0-beta.36",
|
||||
"@blitzjs/generator": "2.0.0-beta.37",
|
||||
"arg": "5.0.1",
|
||||
"blitz": "2.0.0-beta.36",
|
||||
"blitz": "2.0.0-beta.37",
|
||||
"chalk": "^4.1.0",
|
||||
"cross-spawn": "7.0.3",
|
||||
"debug": "4.3.3",
|
||||
@@ -38,7 +38,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-env": "7.12.10",
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@types/jscodeshift": "0.11.2",
|
||||
"@types/node": "18.11.9",
|
||||
"ast-types": "0.14.2",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# @blitzjs/config
|
||||
|
||||
## 2.0.0-beta.37
|
||||
|
||||
## 2.0.0-beta.36
|
||||
|
||||
## 2.0.0-beta.35
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@blitzjs/config",
|
||||
"private": true,
|
||||
"version": "2.0.0-beta.36",
|
||||
"version": "2.0.0-beta.37",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "5.42.1",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @blitzjs/generator
|
||||
|
||||
## 2.0.0-beta.37
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 6d5f9efe1: new blitz app starter
|
||||
|
||||
## 2.0.0-beta.36
|
||||
|
||||
## 2.0.0-beta.35
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/generator",
|
||||
"version": "2.0.0-beta.36",
|
||||
"version": "2.0.0-beta.37",
|
||||
"homepage": "https://blitzjs.com/",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -54,7 +54,7 @@
|
||||
"zod": "3.20.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-beta.36",
|
||||
"@blitzjs/config": "2.0.0-beta.37",
|
||||
"@juanm04/cpx": "2.0.1",
|
||||
"@types/babel__core": "7.1.19",
|
||||
"@types/diff": "5.0.2",
|
||||
|
||||
@@ -7,6 +7,7 @@ import {Generator, GeneratorOptions, SourceRootType} from "../generator"
|
||||
import {baseLogger, log} from "../utils/log"
|
||||
import {fetchLatestVersionsFor} from "../utils/fetch-latest-version-for"
|
||||
import {getBlitzDependencyVersion} from "../utils/get-blitz-dependency-version"
|
||||
import fs from "fs-extra"
|
||||
|
||||
function assert(condition: any, message: string): asserts condition {
|
||||
if (!condition) throw new Error(message)
|
||||
@@ -75,6 +76,36 @@ export class AppGenerator extends Generator<AppGeneratorOptions> {
|
||||
)
|
||||
}
|
||||
|
||||
if (this.options.template.path === "app") {
|
||||
const pathsToMove = [
|
||||
"src/app/auth/components/LoginForm.tsx",
|
||||
"src/app/auth/components/LogoutButton.tsx",
|
||||
"src/app/auth/components/SignupForm.tsx",
|
||||
"src/app/auth/components/ForgotPasswordForm.tsx",
|
||||
"src/app/auth/components/ResetPasswordForm.tsx",
|
||||
"src/app/auth/mutations/login.ts",
|
||||
"src/app/auth/mutations/logout.ts",
|
||||
"src/app/auth/mutations/signup.ts",
|
||||
"src/app/auth/mutations/forgotPassword.ts",
|
||||
"src/app/auth/mutations/resetPassword.ts",
|
||||
"src/app/auth/mutations/forgotPassword.test.ts",
|
||||
"src/app/auth/mutations/resetPassword.test.ts",
|
||||
"src/app/auth/mutations/changePassword.ts",
|
||||
"src/app/auth/login/page.tsx",
|
||||
"src/app/auth/signup/page.tsx",
|
||||
"src/app/auth/forgot-password/page.tsx",
|
||||
"src/app/auth/reset-password/page.tsx",
|
||||
"src/app/auth/layout.tsx",
|
||||
"src/app/auth/validations.ts",
|
||||
]
|
||||
for (const path of pathsToMove) {
|
||||
this.fs.move(
|
||||
this.destinationPath(path),
|
||||
this.destinationPath(path.replace("auth/", "(auth)/")),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.options.template.skipForms) {
|
||||
this.updateForms()
|
||||
}
|
||||
@@ -297,14 +328,25 @@ export class AppGenerator extends Generator<AppGeneratorOptions> {
|
||||
pkg.dependencies["formik"] = "2.x"
|
||||
break
|
||||
}
|
||||
this.fs.move(
|
||||
this.destinationPath(`_forms/${type}/Form.${ext}`),
|
||||
this.destinationPath(`src/core/components/Form.${ext}`),
|
||||
)
|
||||
this.fs.move(
|
||||
this.destinationPath(`_forms/${type}/LabeledTextField.${ext}`),
|
||||
this.destinationPath(`src/core/components/LabeledTextField.${ext}`),
|
||||
)
|
||||
if (this.options.template.path === "app") {
|
||||
this.fs.move(
|
||||
this.destinationPath(`_forms/${type}/Form.${ext}`),
|
||||
this.destinationPath(`src/app/components/Form.${ext}`),
|
||||
)
|
||||
this.fs.move(
|
||||
this.destinationPath(`_forms/${type}/LabeledTextField.${ext}`),
|
||||
this.destinationPath(`src/app/components/LabeledTextField.${ext}`),
|
||||
)
|
||||
} else {
|
||||
this.fs.move(
|
||||
this.destinationPath(`_forms/${type}/Form.${ext}`),
|
||||
this.destinationPath(`src/core/components/Form.${ext}`),
|
||||
)
|
||||
this.fs.move(
|
||||
this.destinationPath(`_forms/${type}/LabeledTextField.${ext}`),
|
||||
this.destinationPath(`src/core/components/LabeledTextField.${ext}`),
|
||||
)
|
||||
}
|
||||
|
||||
this.fs.writeJSON(this.destinationPath("package.json"), pkg)
|
||||
this.fs.delete(this.destinationPath("_forms"))
|
||||
|
||||
@@ -14,14 +14,17 @@ import {
|
||||
insertLabeledSelectField,
|
||||
updateFormWithParent,
|
||||
} from "../../src/utils/codemod-utils"
|
||||
import fs from "fs-extra"
|
||||
|
||||
export interface FormGeneratorOptions extends ResourceGeneratorOptions {}
|
||||
|
||||
export class FormGenerator extends Generator<FormGeneratorOptions> {
|
||||
sourceRoot: SourceRootType
|
||||
isAppDir = false
|
||||
constructor(options: FormGeneratorOptions) {
|
||||
super(options)
|
||||
this.sourceRoot = getTemplateRoot(options.templateDir, {type: "template", path: "form"})
|
||||
this.isAppDir = fs.existsSync(require("path").join(process.cwd(), "src/app/layout.tsx"))
|
||||
}
|
||||
|
||||
static subdirectory = "queries"
|
||||
@@ -42,6 +45,10 @@ export class FormGenerator extends Generator<FormGeneratorOptions> {
|
||||
templateValues.fieldTemplateValues = [newFieldTemplateValues]
|
||||
}
|
||||
}
|
||||
templateValues = {
|
||||
...templateValues,
|
||||
coreComponentsImportPath: this.isAppDir ? "src/app/components" : "src/core/components",
|
||||
}
|
||||
return templateValues
|
||||
}
|
||||
|
||||
@@ -61,6 +68,7 @@ export class FormGenerator extends Generator<FormGeneratorOptions> {
|
||||
getTargetDirectory() {
|
||||
const context = this.options.context ? `${camelCaseToKebabCase(this.options.context)}/` : ""
|
||||
const kebabCaseModelName = camelCaseToKebabCase(this.options.modelNames)
|
||||
if (this.isAppDir) return `src/app/${context}${kebabCaseModelName}/components`
|
||||
return `src/${context}${kebabCaseModelName}/components`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {Generator, GeneratorOptions, SourceRootType} from "../generator"
|
||||
import {getTemplateRoot} from "../utils/get-template-root"
|
||||
import {camelCaseToKebabCase} from "../utils/inflector"
|
||||
import fs from "fs-extra"
|
||||
|
||||
export interface MutationGeneratorOptions extends GeneratorOptions {
|
||||
name: string
|
||||
@@ -9,9 +10,11 @@ export interface MutationGeneratorOptions extends GeneratorOptions {
|
||||
|
||||
export class MutationGenerator extends Generator<MutationGeneratorOptions> {
|
||||
sourceRoot: SourceRootType
|
||||
isAppDir = false
|
||||
constructor(options: MutationGeneratorOptions) {
|
||||
super(options)
|
||||
this.sourceRoot = getTemplateRoot(options.templateDir, {type: "template", path: "mutation"})
|
||||
this.isAppDir = fs.existsSync(require("path").join(process.cwd(), "src/app/layout.tsx"))
|
||||
}
|
||||
static subdirectory = "mutation"
|
||||
|
||||
@@ -25,6 +28,9 @@ export class MutationGenerator extends Generator<MutationGeneratorOptions> {
|
||||
|
||||
getTargetDirectory() {
|
||||
const context = this.options.context ? `${camelCaseToKebabCase(this.options.context)}` : ""
|
||||
if (this.isAppDir) {
|
||||
return `src/app/${context}/mutations`
|
||||
}
|
||||
return `src/${context}/mutations`
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user