Compare commits
9 Commits
@blitzjs/a
...
@blitzjs/a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f15a519017 | ||
|
|
cfcd3f83df | ||
|
|
adabb11a0c | ||
|
|
909dc76087 | ||
|
|
c5c727cb67 | ||
|
|
6ff9ec0d75 | ||
|
|
da17cc8a24 | ||
|
|
89bf993a1d | ||
|
|
68f129491c |
6
.changeset/big-phones-bow.md
Normal file
6
.changeset/big-phones-bow.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@blitzjs/next": patch
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
add mounted check inside withBlitz
|
||||
@@ -7,5 +7,5 @@
|
||||
"access": "restricted",
|
||||
"baseBranch": "main",
|
||||
"updateInternalDependencies": "patch",
|
||||
"ignore": ["web", "test-*"]
|
||||
"ignore": ["web", "test-*", "toolkit-app"]
|
||||
}
|
||||
|
||||
6
.changeset/hot-drinks-approve.md
Normal file
6
.changeset/hot-drinks-approve.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@blitzjs/next": patch
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
Upgrade @types/react, fix typings inside @blitzjs/next
|
||||
5
.changeset/modern-cameras-pull.md
Normal file
5
.changeset/modern-cameras-pull.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/next": patch
|
||||
---
|
||||
|
||||
Support `prefetchBlitzQuery` in gSSP and gSP
|
||||
11
.changeset/plenty-bottles-swim.md
Normal file
11
.changeset/plenty-bottles-swim.md
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
"blitz": patch
|
||||
"@blitzjs/next": patch
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
- Add mounted check to withBlitz
|
||||
- Upgrade @types/react, fix typings inside @blitzjs/next
|
||||
- Support prefetchBlitzQuery in gSP and gSSP
|
||||
- Add db seed cli command
|
||||
- Add try/catch to changePassword mutation
|
||||
5
.changeset/poor-penguins-look.md
Normal file
5
.changeset/poor-penguins-look.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"blitz": patch
|
||||
---
|
||||
|
||||
add `db seed` cli command
|
||||
@@ -13,19 +13,26 @@
|
||||
"@blitzjs/config": "0.0.0",
|
||||
"@blitzjs/generator": "2.0.0-alpha.0",
|
||||
"template": "0.0.0",
|
||||
"toolkit-app": "1.0.0"
|
||||
"toolkit-app": "1.0.0",
|
||||
"test-qm": "0.0.0"
|
||||
},
|
||||
"changesets": [
|
||||
"big-phones-bow",
|
||||
"breezy-cameras-double",
|
||||
"dirty-monkeys-greet",
|
||||
"empty-berries-rule",
|
||||
"fair-wombats-sneeze",
|
||||
"flat-bees-approve",
|
||||
"great-months-train",
|
||||
"hot-drinks-approve",
|
||||
"lovely-colts-share",
|
||||
"modern-cameras-pull",
|
||||
"nice-starfishes-live",
|
||||
"nine-onions-admire",
|
||||
"ninety-pets-heal",
|
||||
"plenty-bottles-swim",
|
||||
"poor-peas-lick",
|
||||
"poor-penguins-look",
|
||||
"poor-shrimps-think",
|
||||
"quiet-feet-travel",
|
||||
"sharp-falcons-begin",
|
||||
@@ -33,6 +40,7 @@
|
||||
"stupid-walls-sell",
|
||||
"swift-drinks-dress",
|
||||
"ten-rivers-burn",
|
||||
"tender-pianos-check",
|
||||
"thirty-countries-build",
|
||||
"twenty-beans-pump",
|
||||
"two-kiwis-help",
|
||||
|
||||
7
.changeset/tender-pianos-check.md
Normal file
7
.changeset/tender-pianos-check.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"blitz": patch
|
||||
"@blitzjs/next": patch
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
various improvements and fixes
|
||||
@@ -1,4 +1,4 @@
|
||||
// import db from "./index"
|
||||
import { db } from "./index"
|
||||
|
||||
/*
|
||||
* This seed function is executed when you run `blitz db seed`.
|
||||
@@ -7,9 +7,15 @@
|
||||
* to easily generate realistic data.
|
||||
*/
|
||||
const seed = async () => {
|
||||
// for (let i = 0; i < 5; i++) {
|
||||
// await db.project.create({ data: { name: "Project " + i } })
|
||||
// }
|
||||
await db.$reset()
|
||||
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await db.user.create({
|
||||
data: {
|
||||
email: "test@test.com",
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default seed
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"@blitzjs/rpc": "workspace:*",
|
||||
"@hookform/resolvers": "2.8.8",
|
||||
"@prisma/client": "3.9.0",
|
||||
"blitz": "workspace:2.0.0-alpha.21",
|
||||
"blitz": "workspace:2.0.0-alpha.23",
|
||||
"next": "12.1.6-canary.17",
|
||||
"prisma": "3.9.0",
|
||||
"react": "18.0.0",
|
||||
@@ -45,7 +45,7 @@
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/node": "17.0.16",
|
||||
"@types/preview-email": "2.0.1",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"eslint": "7.32.0",
|
||||
"husky": "7.0.4",
|
||||
"jest": "27.5.1",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ErrorFallbackProps, ErrorComponent, ErrorBoundary } from "@blitzjs/next"
|
||||
import { AuthenticationError, AuthorizationError } from "blitz"
|
||||
import type { AppProps } from "next/app"
|
||||
import React, { Suspense } from "react"
|
||||
import React from "react"
|
||||
import { withBlitz } from "app/blitz-client"
|
||||
|
||||
function RootErrorFallback({ error }: ErrorFallbackProps) {
|
||||
@@ -27,9 +27,7 @@ function RootErrorFallback({ error }: ErrorFallbackProps) {
|
||||
function MyApp({ Component, pageProps }: AppProps) {
|
||||
return (
|
||||
<ErrorBoundary FallbackComponent={RootErrorFallback}>
|
||||
<Suspense fallback="Loading...">
|
||||
<Component {...pageProps} />
|
||||
</Suspense>
|
||||
<Component {...pageProps} />
|
||||
</ErrorBoundary>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@next/bundle-analyzer": "12.0.8",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"eslint": "7.32.0",
|
||||
"typescript": "^4.5.3"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {ErrorFallbackProps, ErrorComponent, ErrorBoundary} from "@blitzjs/next"
|
||||
import {AuthenticationError, AuthorizationError} from "blitz"
|
||||
import type {AppProps} from "next/app"
|
||||
import React, {Suspense} from "react"
|
||||
import React from "react"
|
||||
import {withBlitz} from "app/blitz-client"
|
||||
|
||||
function RootErrorFallback({error}: ErrorFallbackProps) {
|
||||
@@ -27,9 +27,7 @@ function RootErrorFallback({error}: ErrorFallbackProps) {
|
||||
function MyApp({Component, pageProps}: AppProps) {
|
||||
return (
|
||||
<ErrorBoundary FallbackComponent={RootErrorFallback}>
|
||||
<Suspense fallback="Loading...">
|
||||
<Component {...pageProps} />
|
||||
</Suspense>
|
||||
<Component {...pageProps} />
|
||||
</ErrorBoundary>
|
||||
)
|
||||
}
|
||||
|
||||
28
apps/web/pages/page-with-prefetch.tsx
Normal file
28
apps/web/pages/page-with-prefetch.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import {useQuery} from "@blitzjs/rpc"
|
||||
import {gSSP} from "app/blitz-server"
|
||||
import getUsers from "app/queries/getUsers"
|
||||
|
||||
export const getServerSideProps = gSSP(async ({ctx}) => {
|
||||
const {prefetchBlitzQuery} = ctx
|
||||
|
||||
await prefetchBlitzQuery(getUsers, {})
|
||||
return {props: {}}
|
||||
})
|
||||
|
||||
function PageWithGssp(props) {
|
||||
const [users] = useQuery(getUsers, {})
|
||||
return (
|
||||
<div>
|
||||
{users.map((u) => (
|
||||
<div key={u.createdAt.toDateString()}>
|
||||
<p>name: {u.name}</p>
|
||||
<p>role: {u.role}</p>
|
||||
<p>email: {u.email}</p>
|
||||
<hr />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default PageWithGssp
|
||||
@@ -29,7 +29,7 @@
|
||||
"@types/express": "4.17.13",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
"@types/node-fetch": "2.6.1",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"b64-lite": "1.4.0",
|
||||
"eslint": "7.32.0",
|
||||
"fs-extra": "10.0.1",
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
"prisma": "3.9.0",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
"react-query": "3.21.1"
|
||||
"react-query": "3.39.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/react": "13.0.0",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"@vitejs/plugin-react": "1.3.0",
|
||||
"delay": "5.0.0",
|
||||
"eslint": "7.32.0",
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
"@types/express": "4.17.13",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
"@types/node-fetch": "2.6.1",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"b64-lite": "1.4.0",
|
||||
"eslint": "7.32.0",
|
||||
"fs-extra": "10.0.1",
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"@types/express": "4.17.13",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
"@types/node-fetch": "2.6.1",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"@types/rimraf": "3.0.2",
|
||||
"@types/selenium-webdriver": "4.0.18",
|
||||
"chromedriver": "100.0.0",
|
||||
@@ -21,7 +21,7 @@
|
||||
"node-fetch": "3.2.3",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
"react-query": "3.21.1",
|
||||
"react-query": "3.39.0",
|
||||
"rimraf": "3.0.2",
|
||||
"selenium-webdriver": "4.1.1",
|
||||
"tree-kill": "1.2.2",
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
"test": "turbo run test",
|
||||
"clean": "turbo run clean && rm -rf node_modules",
|
||||
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
|
||||
"pre-publish": "pnpm i && changeset add && changeset version && pnpm build && git add . && git commit -v",
|
||||
"pre-publish": "changeset add && changeset version && pnpm build && git add . && git commit -v",
|
||||
"publish-release": "changeset publish && git push --follow-tags"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
# @blitzjs/auth
|
||||
|
||||
## 2.0.0-alpha.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- blitz@2.0.0-alpha.23
|
||||
|
||||
## 2.0.0-alpha.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- Updated dependencies [89bf993a]
|
||||
- blitz@2.0.0-alpha.22
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/auth",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"version": "2.0.0-alpha.23",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"predev": "wait-on -d 250 ../blitz/dist/index-server.d.ts",
|
||||
@@ -24,7 +24,7 @@
|
||||
"@types/secure-password": "3.1.1",
|
||||
"b64-lite": "1.4.0",
|
||||
"bad-behavior": "1.0.1",
|
||||
"blitz": "2.0.0-alpha.21",
|
||||
"blitz": "2.0.0-alpha.23",
|
||||
"cookie": "0.4.1",
|
||||
"debug": "4.3.3",
|
||||
"http": "0.0.1-security",
|
||||
@@ -35,13 +35,13 @@
|
||||
"url": "0.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.21",
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.23",
|
||||
"@testing-library/react": "13.0.0",
|
||||
"@testing-library/react-hooks": "7.0.2",
|
||||
"@types/cookie": "0.4.1",
|
||||
"@types/debug": "4.1.7",
|
||||
"@types/jsonwebtoken": "8.5.8",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
# @blitzjs/next
|
||||
|
||||
## 2.0.0-alpha.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- various improvements and fixes
|
||||
- @blitzjs/rpc@2.0.0-alpha.23
|
||||
|
||||
## 2.0.0-alpha.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- c5c727cb: add mounted check inside withBlitz
|
||||
- 6ff9ec0d: Upgrade @types/react, fix typings inside @blitzjs/next
|
||||
- da17cc8a: Support `prefetchBlitzQuery` in gSSP and gSP
|
||||
- - Add mounted check to withBlitz
|
||||
- Upgrade @types/react, fix typings inside @blitzjs/next
|
||||
- Support prefetchBlitzQuery in gSP and gSSP
|
||||
- Add db seed cli command
|
||||
- Add try/catch to changePassword mutation
|
||||
- @blitzjs/rpc@2.0.0-alpha.22
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/next",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"version": "2.0.0-alpha.23",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "pnpm predev && pnpm watch unbuild src --wait=0.2",
|
||||
@@ -23,16 +23,16 @@
|
||||
"eslint.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@blitzjs/rpc": "2.0.0-alpha.21",
|
||||
"@blitzjs/rpc": "2.0.0-alpha.23",
|
||||
"@types/hoist-non-react-statics": "3.3.1",
|
||||
"debug": "4.3.3",
|
||||
"fs-extra": "10.0.1",
|
||||
"hoist-non-react-statics": "3.3.2",
|
||||
"react-query": "3.21.1",
|
||||
"react-query": "3.39.0",
|
||||
"superjson": "1.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.21",
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.23",
|
||||
"@testing-library/dom": "8.13.0",
|
||||
"@testing-library/jest-dom": "5.16.3",
|
||||
"@testing-library/react": "13.0.0",
|
||||
@@ -40,10 +40,10 @@
|
||||
"@testing-library/user-event": "13.5.0",
|
||||
"@types/lodash.frompairs": "4.0.6",
|
||||
"@types/node": "17.0.16",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"@types/testing-library__react-hooks": "4.0.0",
|
||||
"blitz": "2.0.0-alpha.21",
|
||||
"blitz": "2.0.0-alpha.23",
|
||||
"cross-spawn": "7.0.3",
|
||||
"find-up": "4.1.0",
|
||||
"lodash.frompairs": "4.0.1",
|
||||
|
||||
@@ -31,8 +31,12 @@ const buildWithBlitz = <TPlugins extends readonly ClientPlugin<object>[]>(plugin
|
||||
const BlitzOuterRoot = (props: AppProps) => {
|
||||
const component = React.useMemo(() => withPlugins(props.Component), [props.Component])
|
||||
|
||||
// supress first render flicker
|
||||
const [mounted, setMounted] = React.useState(false)
|
||||
|
||||
React.useEffect(() => {
|
||||
// Current workaround to fix react 18 suspense error issue
|
||||
setMounted(true)
|
||||
// supress first render flicker
|
||||
setTimeout(() => {
|
||||
document.documentElement.classList.add("blitz-first-render-complete")
|
||||
})
|
||||
@@ -43,7 +47,11 @@ const buildWithBlitz = <TPlugins extends readonly ClientPlugin<object>[]>(plugin
|
||||
<>
|
||||
{/* @ts-ignore todo */}
|
||||
{props.Component.suppressFirstRenderFlicker && <NoPageFlicker />}
|
||||
<UserAppRoot {...props} Component={component} />
|
||||
{mounted && (
|
||||
<React.Suspense fallback="Loading...">
|
||||
<UserAppRoot {...props} Component={component} />
|
||||
</React.Suspense>
|
||||
)}
|
||||
</>
|
||||
</BlitzProvider>
|
||||
)
|
||||
@@ -53,6 +61,7 @@ const buildWithBlitz = <TPlugins extends readonly ClientPlugin<object>[]>(plugin
|
||||
}
|
||||
|
||||
export type BlitzProviderProps = {
|
||||
children: JSX.Element
|
||||
client?: QueryClient
|
||||
contextSharing?: boolean
|
||||
dehydratedState?: unknown
|
||||
@@ -65,7 +74,7 @@ const BlitzProvider = ({
|
||||
dehydratedState,
|
||||
hydrateOptions,
|
||||
children,
|
||||
}: BlitzProviderProps & {children: JSX.Element}) => {
|
||||
}: BlitzProviderProps) => {
|
||||
if (globalThis.queryClient) {
|
||||
return (
|
||||
<QueryClientProvider
|
||||
|
||||
@@ -1,7 +1,21 @@
|
||||
import {GetServerSideProps, GetStaticProps, NextApiRequest, NextApiResponse} from "next"
|
||||
import type {Ctx as BlitzCtx, BlitzServerPlugin, Middleware, MiddlewareResponse} from "blitz"
|
||||
import {
|
||||
GetServerSideProps,
|
||||
GetServerSidePropsResult,
|
||||
GetStaticProps,
|
||||
GetStaticPropsResult,
|
||||
NextApiRequest,
|
||||
NextApiResponse,
|
||||
} from "next"
|
||||
import type {
|
||||
Ctx as BlitzCtx,
|
||||
BlitzServerPlugin,
|
||||
Middleware,
|
||||
MiddlewareResponse,
|
||||
AsyncFunc,
|
||||
FirstParam,
|
||||
} from "blitz"
|
||||
import {handleRequestWithMiddleware} from "blitz"
|
||||
import {withSuperJSONPropsGsp, withSuperJSONPropsGssp} from "./superjson"
|
||||
import {withSuperJsonProps} from "./superjson"
|
||||
|
||||
export * from "./index-browser"
|
||||
|
||||
@@ -43,21 +57,43 @@ export const setupBlitzServer = ({plugins}: SetupBlitzOptions) => {
|
||||
const middlewares = plugins.flatMap((p) => p.middlewares)
|
||||
const contextMiddleware = plugins.flatMap((p) => p.contextMiddleware).filter(Boolean)
|
||||
|
||||
const gSSP = <TProps>(handler: BlitzGSSPHandler<TProps>): GetServerSideProps<TProps> =>
|
||||
withSuperJSONPropsGssp<TProps>(async ({req, res, ...rest}) => {
|
||||
const gSSP =
|
||||
<TProps>(handler: BlitzGSSPHandler<TProps>): GetServerSideProps<TProps> =>
|
||||
async ({req, res, ...rest}) => {
|
||||
await handleRequestWithMiddleware(req, res, middlewares)
|
||||
const ctx = contextMiddleware.reduceRight(
|
||||
(y, f) => (f ? f(y) : y),
|
||||
(res as MiddlewareResponse).blitzCtx,
|
||||
)
|
||||
return handler({req, res, ctx, ...rest})
|
||||
})
|
||||
let queryClient: null | QueryClient = null
|
||||
|
||||
const gSP = <TProps>(handler: BlitzGSPHandler<TProps>): GetStaticProps<TProps> =>
|
||||
withSuperJSONPropsGsp<TProps>(async (context) => {
|
||||
ctx.prefetchBlitzQuery = async (fn, input, defaultOptions = {}) => {
|
||||
queryClient = new QueryClient({defaultOptions})
|
||||
|
||||
const queryKey = getQueryKey(fn, input)
|
||||
await queryClient.prefetchQuery(queryKey, () => fn(input, ctx))
|
||||
}
|
||||
|
||||
const result = await handler({req, res, ctx, ...rest})
|
||||
return withSuperJsonProps(withDehydratedState(result, queryClient))
|
||||
}
|
||||
|
||||
const gSP =
|
||||
<TProps>(handler: BlitzGSPHandler<TProps>): GetStaticProps<TProps> =>
|
||||
async (context) => {
|
||||
const ctx = contextMiddleware.reduceRight((y, f) => (f ? f(y) : y), {} as Ctx)
|
||||
return handler({...context, ctx: ctx})
|
||||
})
|
||||
let queryClient: null | QueryClient = null
|
||||
|
||||
ctx.prefetchBlitzQuery = async (fn, input, defaultOptions = {}) => {
|
||||
queryClient = new QueryClient({defaultOptions})
|
||||
|
||||
const queryKey = getQueryKey(fn, input)
|
||||
await queryClient.prefetchQuery(queryKey, () => fn(input, ctx))
|
||||
}
|
||||
|
||||
const result = await handler({...context, ctx: ctx})
|
||||
return withSuperJsonProps(withDehydratedState(result, queryClient))
|
||||
}
|
||||
|
||||
const api =
|
||||
(handler: BlitzAPIHandler): NextApiHandler =>
|
||||
@@ -74,7 +110,9 @@ export const setupBlitzServer = ({plugins}: SetupBlitzOptions) => {
|
||||
}
|
||||
|
||||
import type {NextConfig} from "next"
|
||||
import {installWebpackConfig} from "@blitzjs/rpc"
|
||||
import {getQueryKey, installWebpackConfig} from "@blitzjs/rpc"
|
||||
import {dehydrate} from "@blitzjs/rpc"
|
||||
import {DefaultOptions, QueryClient} from "react-query"
|
||||
|
||||
export function withBlitz(nextConfig: NextConfig = {}) {
|
||||
return Object.assign({}, nextConfig, {
|
||||
@@ -87,3 +125,25 @@ export function withBlitz(nextConfig: NextConfig = {}) {
|
||||
},
|
||||
} as NextConfig)
|
||||
}
|
||||
|
||||
type PrefetchQueryFn = <T extends AsyncFunc, TInput = FirstParam<T>>(
|
||||
resolver: T,
|
||||
params: TInput,
|
||||
options?: DefaultOptions,
|
||||
) => Promise<void>
|
||||
|
||||
type Result = Partial<GetServerSidePropsResult<any> & GetStaticPropsResult<any>>
|
||||
|
||||
function withDehydratedState<T extends Result>(result: T, queryClient: QueryClient | null) {
|
||||
if (!queryClient) {
|
||||
return result
|
||||
}
|
||||
const dehydratedProps = dehydrate(queryClient)
|
||||
return {...result, props: {...("props" in result ? result.props : undefined), dehydratedProps}}
|
||||
}
|
||||
|
||||
declare module "blitz" {
|
||||
export interface Ctx {
|
||||
prefetchBlitzQuery: PrefetchQueryFn
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import hoistNonReactStatics from "hoist-non-react-statics"
|
||||
import type {
|
||||
GetServerSideProps,
|
||||
GetServerSidePropsResult,
|
||||
GetStaticProps,
|
||||
GetStaticPropsResult,
|
||||
} from "next"
|
||||
import type {GetServerSidePropsResult, GetStaticPropsResult} from "next"
|
||||
import * as React from "react"
|
||||
import SuperJSON from "superjson"
|
||||
|
||||
@@ -12,10 +7,9 @@ export type SuperJSONProps<P = any> = P & {
|
||||
_superjson?: any
|
||||
}
|
||||
|
||||
function excludeProps<P>(
|
||||
result: GetServerSidePropsResult<P> | GetStaticPropsResult<P>,
|
||||
exclude: string[] = [],
|
||||
) {
|
||||
type Result = Partial<GetServerSidePropsResult<any> & GetStaticPropsResult<any>>
|
||||
|
||||
export function withSuperJsonProps<T extends Result>(result: T, exclude: string[] = []) {
|
||||
if (!("props" in result)) {
|
||||
return result
|
||||
}
|
||||
@@ -50,27 +44,6 @@ function excludeProps<P>(
|
||||
}
|
||||
}
|
||||
|
||||
export function withSuperJSONPropsGssp<P>(
|
||||
handler: GetServerSideProps<P>,
|
||||
exclude: string[] = [],
|
||||
): GetServerSideProps<SuperJSONProps<P>> {
|
||||
return async function withSuperJSON(...args) {
|
||||
const result = await handler(...args)
|
||||
return excludeProps(result, exclude)
|
||||
}
|
||||
}
|
||||
|
||||
export function withSuperJSONPropsGsp<P>(
|
||||
handler: GetStaticProps<P>,
|
||||
exclude: string[] = [],
|
||||
): GetStaticProps<P> {
|
||||
return async function withSuperJSON(...args) {
|
||||
const result = await handler(...args)
|
||||
|
||||
return excludeProps<any>(result, exclude)
|
||||
}
|
||||
}
|
||||
|
||||
export function deserializeProps<P>(serializedProps: SuperJSONProps<P>): P {
|
||||
const {_superjson, ...props} = serializedProps
|
||||
return SuperJSON.deserialize({json: props as any, meta: _superjson})
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
# @blitzjs/rpc
|
||||
|
||||
## 2.0.0-alpha.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- blitz@2.0.0-alpha.23
|
||||
- @blitzjs/auth@2.0.0-alpha.23
|
||||
|
||||
## 2.0.0-alpha.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- Updated dependencies [89bf993a]
|
||||
- blitz@2.0.0-alpha.22
|
||||
- @blitzjs/auth@2.0.0-alpha.22
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/rpc",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"version": "2.0.0-alpha.23",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"predev": "wait-on -d 250 ../blitz/dist/index-server.d.ts && wait-on -d 250 ../blitz-auth/dist/index-browser.d.ts",
|
||||
@@ -20,21 +20,21 @@
|
||||
"dist/**"
|
||||
],
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-alpha.21",
|
||||
"@blitzjs/auth": "2.0.0-alpha.23",
|
||||
"b64-lite": "1.4.0",
|
||||
"bad-behavior": "1.0.1",
|
||||
"chalk": "^4.1.0",
|
||||
"debug": "4.3.3",
|
||||
"react-query": "3.21.1",
|
||||
"react-query": "3.39.0",
|
||||
"superjson": "1.8.0",
|
||||
"zod": "3.10.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.21",
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.23",
|
||||
"@types/debug": "4.1.7",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"blitz": "2.0.0-alpha.21",
|
||||
"blitz": "2.0.0-alpha.23",
|
||||
"next": "12.1.6-canary.17",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
@@ -43,7 +43,7 @@
|
||||
"watch": "1.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"blitz": "2.0.0-alpha.21",
|
||||
"blitz": "2.0.0-alpha.23",
|
||||
"next": "*"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
||||
@@ -1,5 +1,29 @@
|
||||
# blitz
|
||||
|
||||
## 2.0.0-alpha.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- various improvements and fixes
|
||||
- Updated dependencies
|
||||
- @blitzjs/generator@2.0.0-alpha.23
|
||||
|
||||
## 2.0.0-alpha.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- - Add mounted check to withBlitz
|
||||
- Upgrade @types/react, fix typings inside @blitzjs/next
|
||||
- Support prefetchBlitzQuery in gSP and gSSP
|
||||
- Add db seed cli command
|
||||
- Add try/catch to changePassword mutation
|
||||
- 89bf993a: add `db seed` cli command
|
||||
- Updated dependencies [c5c727cb]
|
||||
- Updated dependencies [6ff9ec0d]
|
||||
- Updated dependencies [81b4b41a]
|
||||
- Updated dependencies
|
||||
- @blitzjs/generator@2.0.0-alpha.22
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "blitz",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"version": "2.0.0-alpha.23",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "watch unbuild src --wait=0.2",
|
||||
@@ -23,7 +23,7 @@
|
||||
"blitz": "bin/blitz"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/generator": "2.0.0-alpha.21",
|
||||
"@blitzjs/generator": "2.0.0-alpha.23",
|
||||
"arg": "5.0.1",
|
||||
"chalk": "^4.1.0",
|
||||
"console-table-printer": "2.10.0",
|
||||
@@ -44,10 +44,12 @@
|
||||
"resolve-cwd": "3.0.0",
|
||||
"resolve-from": "5.0.0",
|
||||
"superjson": "1.8.0",
|
||||
"ts-node": "10.7.0",
|
||||
"tsconfig-paths": "4.0.0",
|
||||
"tslog": "3.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.21",
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.23",
|
||||
"@types/cookie": "0.4.1",
|
||||
"@types/cross-spawn": "6.0.2",
|
||||
"@types/debug": "4.1.7",
|
||||
@@ -58,7 +60,7 @@
|
||||
"@types/node-fetch": "2.6.1",
|
||||
"@types/npm-which": "3.0.1",
|
||||
"@types/prompts": "2.0.14",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"@types/test-listen": "1.1.0",
|
||||
"express": "4.17.3",
|
||||
|
||||
90
packages/blitz/src/cli/commands/db.ts
Normal file
90
packages/blitz/src/cli/commands/db.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import {CliCommand} from "../index"
|
||||
import arg from "arg"
|
||||
import {join} from "path"
|
||||
import {REGISTER_INSTANCE} from "ts-node"
|
||||
import chalk from "chalk"
|
||||
|
||||
const args = arg(
|
||||
{
|
||||
// Types
|
||||
"--help": Boolean,
|
||||
"--env": String,
|
||||
"--file": String,
|
||||
|
||||
// Aliases
|
||||
"-h": "--help",
|
||||
"-e": "--env",
|
||||
"-f": "--file",
|
||||
},
|
||||
{
|
||||
permissive: true,
|
||||
},
|
||||
)
|
||||
|
||||
const runSeed = async (seedBasePath: string) => {
|
||||
if (!process[REGISTER_INSTANCE]) {
|
||||
// During blitz interal dev, oclif automaticaly sets up ts-node so we have to check
|
||||
require("ts-node").register({compilerOptions: {module: "commonjs"}})
|
||||
}
|
||||
require("tsconfig-paths/register")
|
||||
|
||||
const seedPath = join(process.cwd(), seedBasePath)
|
||||
const dbPath = join(process.cwd(), "db/index")
|
||||
console.log(chalk.magenta("Seeding database"))
|
||||
|
||||
let seeds: Function | undefined
|
||||
try {
|
||||
seeds = require(seedPath).default
|
||||
if (seeds === undefined) {
|
||||
throw new Error(`Couldn't find default export from ${seedBasePath}`)
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(chalk.red(`Couldn't import default from ${seedBasePath}`))
|
||||
throw err
|
||||
}
|
||||
|
||||
try {
|
||||
console.log("\n" + "Seeding...")
|
||||
seeds && (await seeds())
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
|
||||
const db = require(dbPath).db
|
||||
await db.$disconnect()
|
||||
console.log("Done Seeding")
|
||||
}
|
||||
|
||||
const db: CliCommand = async () => {
|
||||
let filePath = "db/seeds"
|
||||
|
||||
if (args["--file"]) {
|
||||
filePath = args["--file"]
|
||||
}
|
||||
|
||||
if (args["--help"]) {
|
||||
console.log(`Run database commands
|
||||
${chalk.bold("seed")} Generated seeded data in database via Prisma.
|
||||
`)
|
||||
}
|
||||
|
||||
if (args["_"].slice(1)[0] && args["_"].slice(1)[0] === "seed") {
|
||||
try {
|
||||
return await runSeed(filePath)
|
||||
} catch (err) {
|
||||
console.log(chalk.red("Could not seed database:"))
|
||||
console.log(err)
|
||||
process.exit(1)
|
||||
}
|
||||
} else {
|
||||
if (!args["--help"]) {
|
||||
console.log("\nThat command is no longer available..")
|
||||
console.log("For any prisma related commands, use the `blitz prisma` command instead:")
|
||||
console.log("\n `blitz prisma COMMAND`\n")
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
export {db}
|
||||
@@ -27,6 +27,7 @@ const commands: {[command: string]: () => Promise<CliCommand>} = {
|
||||
new: () => import("./commands/new").then((i) => i.newApp),
|
||||
generate: () => import("./commands/generate").then((i) => i.generate),
|
||||
codegen: () => import("./commands/codegen").then((i) => i.codegen),
|
||||
db: () => import("./commands/db").then((i) => i.db),
|
||||
}
|
||||
|
||||
const args = arg(commonArgs, {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
startCustomServer,
|
||||
buildCustomServer,
|
||||
} from "./next-utils"
|
||||
import {readBlitzConfig} from "../../server-utils"
|
||||
|
||||
export async function build(config: ServerConfig) {
|
||||
const {rootFolder, nextBin, watch} = await normalize(config)
|
||||
@@ -21,11 +22,8 @@ export async function dev(config: ServerConfig) {
|
||||
if (customServerExists()) {
|
||||
console.log("Using your custom server")
|
||||
|
||||
// todo
|
||||
// const {loadConfigProduction} = await import("next/dist/server/config-shared")
|
||||
// const blitzConfig = loadConfigProduction(config.rootFolder)
|
||||
// const watch = blitzConfig.customServer?.hotReload ?? true
|
||||
const watch = true
|
||||
const blitzConfig = readBlitzConfig(rootFolder)
|
||||
const watch = blitzConfig.customServer?.hotReload ?? true
|
||||
|
||||
await startCustomServer(rootFolder, config, {watch})
|
||||
} else {
|
||||
|
||||
12
packages/blitz/src/server-utils.ts
Normal file
12
packages/blitz/src/server-utils.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
|
||||
export function readBlitzConfig(rootFolder: string = process.cwd()) {
|
||||
const packageJsonFile = fs.readFileSync(path.join(rootFolder, "package.json"), {
|
||||
encoding: "utf8",
|
||||
flag: "r",
|
||||
})
|
||||
const packageJson = JSON.parse(packageJsonFile)
|
||||
|
||||
return packageJson.blitz || {}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import {Middleware} from "./index-server"
|
||||
import * as path from "path"
|
||||
import * as fs from "fs"
|
||||
|
||||
export function assert(condition: any, message: string): asserts condition {
|
||||
if (!condition) throw new Error(message)
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# @blitzjs/config
|
||||
|
||||
## 2.0.0-alpha.23
|
||||
|
||||
## 2.0.0-alpha.22
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
## 2.0.0-alpha.20
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@blitzjs/config",
|
||||
"private": true,
|
||||
"version": "2.0.0-alpha.21",
|
||||
"version": "2.0.0-alpha.23",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "5.9.1",
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
# @blitzjs/generator
|
||||
|
||||
## 2.0.0-alpha.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- various improvements and fixes
|
||||
|
||||
## 2.0.0-alpha.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- c5c727cb: add mounted check inside withBlitz
|
||||
- 6ff9ec0d: Upgrade @types/react, fix typings inside @blitzjs/next
|
||||
- 81b4b41a: add mounted check to app generator template
|
||||
- - Add mounted check to withBlitz
|
||||
- Upgrade @types/react, fix typings inside @blitzjs/next
|
||||
- Support prefetchBlitzQuery in gSP and gSSP
|
||||
- Add db seed cli command
|
||||
- Add try/catch to changePassword mutation
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/generator",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"version": "2.0.0-alpha.23",
|
||||
"scripts": {
|
||||
"dev": "watch unbuild src --wait=0.2",
|
||||
"build": "unbuild && pnpm build:templates",
|
||||
@@ -45,7 +45,7 @@
|
||||
"vinyl": "2.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-alpha.21",
|
||||
"@blitzjs/config": "2.0.0-alpha.23",
|
||||
"@juanm04/cpx": "2.0.1",
|
||||
"@types/babel__core": "7.1.19",
|
||||
"@types/diff": "5.0.2",
|
||||
@@ -55,7 +55,7 @@
|
||||
"@types/mem-fs-editor": "7.0.1",
|
||||
"@types/pluralize": "0.0.29",
|
||||
"@types/prettier": "2.4.4",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"@types/vinyl": "2.0.6",
|
||||
"@typescript-eslint/eslint-plugin": "5.9.1",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NotFoundError } from "blitz"
|
||||
import { NotFoundError, AuthenticationError } from "blitz"
|
||||
import { db } from "db"
|
||||
import { authenticateUser } from "./login"
|
||||
import { ChangePassword } from "../validations"
|
||||
@@ -12,7 +12,14 @@ export default resolver.pipe(
|
||||
const user = await db.user.findFirst({ where: { id: ctx.session.userId as number } })
|
||||
if (!user) throw new NotFoundError()
|
||||
|
||||
await authenticateUser(user.email, currentPassword)
|
||||
try {
|
||||
await authenticateUser(user.email, currentPassword)
|
||||
} catch (error: any) {
|
||||
if (error instanceof AuthenticationError) {
|
||||
throw new Error("Invalid Password")
|
||||
}
|
||||
throw error
|
||||
}
|
||||
|
||||
const hashedPassword = await SecurePassword.hash(newPassword.trim())
|
||||
await db.user.update({
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/node": "17.0.16",
|
||||
"@types/preview-email": "2.0.1",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"eslint": "7.32.0",
|
||||
"husky": "7.0.4",
|
||||
"jest": "27.5.1",
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/node": "17.0.16",
|
||||
"@types/preview-email": "2.0.1",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"eslint": "7.32.0",
|
||||
"husky": "7.0.4",
|
||||
"jest": "27.5.1",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {ErrorFallbackProps, ErrorComponent, ErrorBoundary} from "@blitzjs/next"
|
||||
import {AuthenticationError, AuthorizationError} from "blitz"
|
||||
import type {AppProps} from "next/app"
|
||||
import React, {Suspense} from "react"
|
||||
import React from "react"
|
||||
import {withBlitz} from "app/blitz-client"
|
||||
|
||||
function RootErrorFallback({error}: ErrorFallbackProps) {
|
||||
@@ -25,15 +25,9 @@ function RootErrorFallback({error}: ErrorFallbackProps) {
|
||||
}
|
||||
|
||||
function MyApp({Component, pageProps}: AppProps) {
|
||||
const [mounted, setMounted] = React.useState(false)
|
||||
React.useEffect(() => {
|
||||
setMounted(true)
|
||||
}, [])
|
||||
return (
|
||||
<ErrorBoundary FallbackComponent={RootErrorFallback}>
|
||||
{mounted && <Suspense fallback="Loading...">
|
||||
<Component {...pageProps} />
|
||||
</Suspense> }
|
||||
<Component {...pageProps} />
|
||||
</ErrorBoundary>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"@next/bundle-analyzer": "12.0.8",
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/node": "17.0.16",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"eslint": "7.32.0",
|
||||
"husky": "7.0.4",
|
||||
"jest": "27.5.1",
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
"@next/bundle-analyzer": "12.0.8",
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/node": "17.0.16",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react": "18.0.1",
|
||||
"eslint": "7.32.0",
|
||||
"husky": "7.0.4",
|
||||
"jest": "27.5.1",
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
"@typescript-eslint/parser": "5.9.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-alpha.21",
|
||||
"@types/react": "17.0.43",
|
||||
"@blitzjs/config": "2.0.0-alpha.23",
|
||||
"@types/react": "18.0.1",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"react": "18.0.0",
|
||||
"typescript": "^4.5.3",
|
||||
|
||||
679
pnpm-lock.yaml
generated
679
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user