├── .husky ├── .gitignore └── pre-commit ├── apps ├── web │ ├── test │ │ ├── setup.ts │ │ └── hello.unit.test.ts │ ├── .eslintrc.js │ ├── .gitignore │ ├── app │ │ ├── mutations │ │ │ ├── setBasic.ts │ │ │ └── createUser.ts │ │ ├── queries │ │ │ ├── getBasic.ts │ │ │ ├── v2 │ │ │ │ └── getV2Basic.ts │ │ │ ├── getUsersAuth.ts │ │ │ ├── getUsers.ts │ │ │ └── getInfiniteUsers.ts │ │ ├── blitz-server.ts │ │ └── blitz-client.ts │ ├── pages │ │ ├── [postId] │ │ │ └── index.tsx │ │ ├── api │ │ │ ├── rpc │ │ │ │ └── [[...blitz]].ts │ │ │ ├── logout.ts │ │ │ ├── is-authorized.ts │ │ │ ├── revoke-all-sessions.ts │ │ │ ├── get-user.ts │ │ │ ├── multiply.ts │ │ │ ├── set-public-data.ts │ │ │ └── signup.ts │ │ ├── page-with-use-authorize.tsx │ │ ├── page-with-use-session.tsx │ │ ├── page-without-flicker.tsx │ │ ├── page-with-use-authorize-if.tsx │ │ ├── page-with-use-auth-session.tsx │ │ ├── page-with-use-redirect-auth.tsx │ │ ├── authenticated-page.tsx │ │ ├── index.tsx │ │ ├── page-with-gsp.tsx │ │ ├── page-with-auth-redirect.tsx │ │ ├── page-with-redirect.tsx │ │ ├── users.tsx │ │ ├── page-with-gssp.tsx │ │ ├── page-with-get-query-data.tsx │ │ ├── page-with-gssp-redirect.tsx │ │ ├── page-with-prefetch.tsx │ │ ├── page-with-invoke-ctx.tsx │ │ └── page-with-inf-prefetch.tsx │ ├── db │ │ ├── migrations │ │ │ └── migration_lock.toml │ │ └── index.ts │ ├── next-env.d.ts │ ├── .npmrc │ ├── tsconfig.json │ ├── jest.config.js │ ├── types.ts │ └── next.config.js └── toolkit-app │ ├── mailers │ └── .keep │ ├── db │ ├── migrations │ │ ├── .keep │ │ └── migration_lock.toml │ ├── index.ts │ └── seeds.ts │ ├── integrations │ └── .keep │ ├── .eslintrc.js │ ├── jsconfig.json │ ├── public │ ├── logo.png │ └── favicon.ico │ ├── .prettierignore │ ├── app │ ├── auth │ │ ├── mutations │ │ │ ├── logout.ts │ │ │ ├── signup.ts │ │ │ └── changePassword.ts │ │ └── validations.ts │ ├── core │ │ ├── hooks │ │ │ └── useCurrentUser.ts │ │ └── layouts │ │ │ └── Layout.tsx │ ├── blitz-client.ts │ ├── users │ │ └── queries │ │ │ └── getCurrentUser.ts │ └── blitz-server.ts │ ├── pages │ ├── api │ │ └── rpc │ │ │ └── [[...blitz]].ts │ ├── auth │ │ ├── signup.tsx │ │ └── login.tsx │ ├── _document.tsx │ └── 404.tsx │ ├── test │ └── setup.ts │ ├── .env │ ├── next-env.d.ts │ ├── .editorconfig │ ├── .npmrc │ ├── jest.config.js │ ├── types.ts │ ├── next.config.js │ ├── tsconfig.json │ └── .gitignore ├── .node-version ├── .gitattributes ├── .eslintignore ├── packages ├── generator │ ├── .eslintignore │ ├── templates │ │ ├── app │ │ │ ├── mailers │ │ │ │ └── .keep │ │ │ ├── db │ │ │ │ ├── migrations │ │ │ │ │ └── .keep │ │ │ │ ├── index.ts │ │ │ │ └── seeds.ts │ │ │ ├── integrations │ │ │ │ └── .keep │ │ │ ├── .eslintrc.js │ │ │ ├── jsconfig.json │ │ │ ├── .husky │ │ │ │ ├── pre-push-js │ │ │ │ ├── pre-push-ts │ │ │ │ └── pre-commit │ │ │ ├── public │ │ │ │ ├── logo.png │ │ │ │ └── favicon.ico │ │ │ ├── .prettierignore │ │ │ ├── app │ │ │ │ ├── auth │ │ │ │ │ ├── mutations │ │ │ │ │ │ ├── logout.ts │ │ │ │ │ │ └── signup.ts │ │ │ │ │ └── validations.ts │ │ │ │ ├── core │ │ │ │ │ ├── hooks │ │ │ │ │ │ └── useCurrentUser.ts │ │ │ │ │ └── layouts │ │ │ │ │ │ └── Layout.tsx │ │ │ │ ├── users │ │ │ │ │ └── queries │ │ │ │ │ │ └── getCurrentUser.ts │ │ │ │ ├── blitz-client.ts │ │ │ │ └── blitz-server.ts │ │ │ ├── pages │ │ │ │ ├── api │ │ │ │ │ └── rpc │ │ │ │ │ │ └── blitzrpcroute.ts │ │ │ │ ├── auth │ │ │ │ │ ├── signup.tsx │ │ │ │ │ └── login.tsx │ │ │ │ ├── _document.tsx │ │ │ │ └── 404.tsx │ │ │ ├── test │ │ │ │ └── setup.ts │ │ │ ├── .env │ │ │ ├── next.config.js │ │ │ ├── .vscode │ │ │ │ ├── settings.json │ │ │ │ └── extensions.json │ │ │ ├── .editorconfig │ │ │ ├── next-env.d.ts │ │ │ ├── jest.config.js │ │ │ ├── .env.test │ │ │ ├── npmrc │ │ │ ├── types.ts │ │ │ ├── .env.local │ │ │ ├── tsconfig.json │ │ │ └── gitignore │ │ ├── minimalapp │ │ │ ├── .eslintrc.js │ │ │ ├── jsconfig.json │ │ │ ├── .env.test.local │ │ │ ├── .husky │ │ │ │ ├── pre-push-js │ │ │ │ ├── pre-push-ts │ │ │ │ └── pre-commit │ │ │ ├── public │ │ │ │ ├── logo.png │ │ │ │ └── favicon.ico │ │ │ ├── types.ts │ │ │ ├── .env.local │ │ │ ├── app │ │ │ │ └── blitz-client.ts │ │ │ ├── .prettierignore │ │ │ ├── test │ │ │ │ └── setup.ts │ │ │ ├── .env │ │ │ ├── next.config.js │ │ │ ├── .vscode │ │ │ │ ├── settings.json │ │ │ │ └── extensions.json │ │ │ ├── next-env.d.ts │ │ │ ├── .editorconfig │ │ │ ├── jest.config.js │ │ │ ├── .env.test │ │ │ ├── npmrc │ │ │ ├── pages │ │ │ │ ├── index.test.tsx │ │ │ │ ├── _document.tsx │ │ │ │ ├── 404.tsx │ │ │ │ └── _app.tsx │ │ │ ├── tsconfig.json │ │ │ └── gitignore │ │ ├── query │ │ │ └── __name__.ts │ │ ├── mutation │ │ │ └── __name__.ts │ │ ├── form │ │ │ └── __ModelName__Form.tsx │ │ ├── mutations │ │ │ ├── delete__ModelName__.ts │ │ │ ├── update__ModelName__.ts │ │ │ └── create__ModelName__.ts │ │ └── queries │ │ │ ├── get__ModelName__.ts │ │ │ └── get__ModelNames__.ts │ ├── .eslintrc.js │ ├── src │ │ ├── utils │ │ │ ├── fallbackable.ts │ │ │ ├── module.ts │ │ │ ├── pipe.ts │ │ │ ├── match-between.ts │ │ │ ├── get-blitz-dependency-version.ts │ │ │ ├── get-template-root.ts │ │ │ ├── readdir-recursive.ts │ │ │ ├── npm-fetch.ts │ │ │ └── inflector.ts │ │ ├── errors │ │ │ └── prompt-aborted.ts │ │ ├── index.ts │ │ └── generators │ │ │ └── query-generator.ts │ ├── types │ │ └── jsx.d.ts │ ├── build.config.ts │ ├── .gitignore │ ├── tsconfig.json │ └── test │ │ └── prisma │ │ ├── __snapshots__ │ │ └── model.test.ts.snap │ │ └── model.test.ts ├── pkg-template │ ├── src │ │ ├── index-browser.tsx │ │ └── index-server.ts │ ├── .eslintrc.js │ ├── tsconfig.json │ ├── build.config.ts │ └── test │ │ └── sample.test.ts ├── blitz │ ├── .eslintrc.js │ ├── bin │ │ └── blitz │ ├── src │ │ ├── global.ts │ │ ├── cli │ │ │ ├── commands │ │ │ │ ├── next │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── build.ts │ │ │ │ │ ├── dev.ts │ │ │ │ │ └── start.ts │ │ │ │ ├── codegen.ts │ │ │ │ └── prisma.ts │ │ │ └── utils │ │ │ │ ├── constants.ts │ │ │ │ ├── get-package-json.ts │ │ │ │ └── helpers.ts │ │ └── utils │ │ │ ├── server.ts │ │ │ └── run-prisma.ts │ ├── tsconfig.json │ └── build.config.ts ├── blitz-auth │ ├── .eslintrc.js │ ├── src │ │ ├── shared │ │ │ └── index.ts │ │ ├── index-server.ts │ │ ├── index-browser.tsx │ │ ├── server │ │ │ └── index.ts │ │ └── global.ts │ ├── tsconfig.json │ └── build.config.ts ├── blitz-next │ ├── .eslintrc.js │ ├── jest │ │ ├── client │ │ │ └── setup-after-env.js │ │ ├── image-mock.js │ │ └── server │ │ │ └── setup-after-env.js │ ├── src │ │ ├── global.ts │ │ └── router-context.ts │ ├── scripts │ │ ├── default-index.js │ │ ├── default-index-browser.js │ │ └── default-index.d.ts │ ├── tsconfig.json │ ├── build.config.ts │ └── eslint.js ├── blitz-rpc │ ├── .eslintrc.js │ ├── src │ │ ├── global.ts │ │ ├── data-client │ │ │ ├── invokeWithCtx.ts │ │ │ ├── index.ts │ │ │ └── invoke.ts │ │ └── loader-utils.test.ts │ ├── tsconfig.json │ ├── test │ │ ├── sample.test.ts │ │ └── blitz-test-utils.ts │ └── build.config.ts ├── codemod │ ├── .eslintrc.js │ ├── bin │ │ └── @blitzjs │ │ │ └── codemod │ ├── build.config.ts │ ├── tsconfig.json │ └── src │ │ ├── index.test.ts │ │ └── index.ts └── config │ ├── README.md │ ├── tsconfig.library.json │ ├── package.json │ ├── tsconfig.nextjs.json │ ├── tsconfig.base.json │ └── eslint.js ├── assets ├── andreas.jpg ├── meetkai.png ├── rit_logo.png ├── usertrack.png ├── flightcontrol.png ├── Fauna_Logo_Blue.png └── render-logo-color2.png ├── integration-tests ├── qm │ ├── .eslintrc.js │ ├── .gitignore │ ├── next.config.js │ ├── next-env.d.ts │ ├── vitest.config.ts │ ├── tsconfig.json │ ├── test │ │ └── __snapshots__ │ │ │ ├── use-mutation.test.tsx.snap │ │ │ └── use-query.test.tsx.snap │ └── package.json ├── auth │ ├── .eslintrc.js │ ├── .env │ ├── .gitignore │ ├── next.config.js │ ├── pages │ │ ├── api │ │ │ ├── noauth.ts │ │ │ └── logout.ts │ │ ├── index.tsx │ │ └── authenticated-page.tsx │ ├── prisma │ │ ├── migrations │ │ │ └── migration_lock.toml │ │ ├── index.ts │ │ └── seed.ts │ ├── next-env.d.ts │ ├── app │ │ ├── blitz-client.ts │ │ └── blitz-server.ts │ ├── tsconfig.json │ └── types.ts ├── middleware │ ├── .eslintrc.js │ ├── .env │ ├── .gitignore │ ├── next.config.js │ ├── app │ │ ├── queries │ │ │ └── getBasic.ts │ │ ├── blitz-client.ts │ │ └── blitz-server.ts │ ├── pages │ │ ├── api │ │ │ ├── rpc │ │ │ │ └── [[...blitz]].ts │ │ │ └── test.ts │ │ └── index.tsx │ ├── middleware.ts │ ├── next-env.d.ts │ ├── tsconfig.json │ └── package.json ├── no-suspense │ ├── .eslintrc.js │ ├── .env │ ├── .gitignore │ ├── next.config.js │ ├── app │ │ ├── queries │ │ │ └── getBasic.ts │ │ ├── blitz-client.ts │ │ └── blitz-server.ts │ ├── prisma │ │ ├── seed.ts │ │ ├── migrations │ │ │ └── migration_lock.toml │ │ └── index.ts │ ├── pages │ │ ├── api │ │ │ └── rpc │ │ │ │ └── [[...blitz]].ts │ │ └── use-query.tsx │ ├── next-env.d.ts │ ├── tsconfig.json │ └── types.ts ├── react-query-utils │ ├── .eslintrc.js │ ├── .env │ ├── .gitignore │ ├── next.config.js │ ├── app │ │ ├── queries │ │ │ └── getBasic.ts │ │ ├── blitz-client.ts │ │ └── blitz-server.ts │ ├── db │ │ ├── seed.ts │ │ ├── migrations │ │ │ └── migration_lock.toml │ │ └── index.ts │ ├── pages │ │ ├── api │ │ │ └── rpc │ │ │ │ └── [[...blitz]].ts │ │ └── page-with-get-query-data.tsx │ ├── next-env.d.ts │ ├── tsconfig.json │ └── types.ts ├── trailing-slash │ ├── .eslintrc.js │ ├── .env │ ├── .gitignore │ ├── app │ │ ├── queries │ │ │ └── getBasic.ts │ │ ├── blitz-client.ts │ │ └── blitz-server.ts │ ├── next.config.js │ ├── db │ │ ├── seed.ts │ │ ├── migrations │ │ │ └── migration_lock.toml │ │ └── index.ts │ ├── pages │ │ ├── api │ │ │ └── rpc │ │ │ │ └── [[...blitz]].ts │ │ └── use-query.tsx │ ├── next-env.d.ts │ ├── tsconfig.json │ └── types.ts ├── rpc │ ├── app │ │ ├── queries │ │ │ ├── v2 │ │ │ │ └── getNestedBasic.js │ │ │ ├── getFailure.js │ │ │ └── getBasic.js │ │ └── mutations │ │ │ └── setBasic.js │ ├── pages │ │ ├── index.js │ │ ├── api │ │ │ └── rpc │ │ │ │ └── [[...blitz]].ts │ │ └── query.js │ ├── next.config.js │ ├── vitest.config.ts │ ├── next-env.d.ts │ ├── tsconfig.json │ └── package.json └── utils │ ├── tsconfig.json │ ├── next-webdriver.d.ts │ └── package.json ├── .changeset ├── ten-rivers-burn.md ├── two-kiwis-help.md ├── fair-wombats-sneeze.md ├── healthy-rice-shout.md ├── hungry-baboons-swim.md ├── lovely-colts-share.md ├── moody-squids-cheer.md ├── poor-penguins-look.md ├── ninety-lies-press.md ├── tame-keys-reply.md ├── tough-toes-pull.md ├── cool-doors-invent.md ├── hot-cups-rhyme.md ├── silent-colts-reply.md ├── tall-meals-learn.md ├── three-lies-pull.md ├── two-tigers-type.md ├── curly-seas-serve.md ├── fast-trainers-kneel.md ├── kind-walls-suffer.md ├── nine-onions-admire.md ├── perfect-eyes-repeat.md ├── poor-peas-lick.md ├── poor-shrimps-think.md ├── quick-cycles-confess.md ├── quiet-feet-travel.md ├── thirty-countries-build.md ├── weak-suns-shave.md ├── bright-mangos-run.md ├── gentle-dogs-reply.md ├── green-pillows-hammer.md ├── nice-deers-dream.md ├── small-socks-confess.md ├── sweet-kiwis-cross.md ├── swift-drinks-dress.md ├── ten-hairs-listen.md ├── few-dogs-fetch.md ├── four-sheep-judge.md ├── fuzzy-bees-warn.md ├── olive-bees-buy.md ├── shaggy-carpets-brake.md ├── sharp-falcons-begin.md ├── smooth-rice-clap.md ├── violet-bags-leave.md ├── eleven-humans-sort.md ├── empty-berries-rule.md ├── modern-cameras-pull.md ├── tasty-news-collect.md ├── calm-horses-tie.md ├── four-meals-fry.md ├── gorgeous-buses-scream.md ├── heavy-apes-judge.md ├── late-steaks-give.md ├── moody-bags-walk.md ├── nice-starfishes-live.md ├── olive-sheep-rhyme.md ├── popular-teachers-pay.md ├── pretty-games-march.md ├── shy-pumpkins-try.md ├── silly-apricots-share.md ├── smooth-tools-train.md ├── thick-parrots-float.md ├── calm-tomatoes-drive.md ├── chilled-carrots-own.md ├── empty-turkeys-wave.md ├── famous-kings-explain.md ├── good-insects-wink.md ├── soft-adults-smell.md ├── strong-apes-reply.md ├── unlucky-papayas-sleep.md ├── wicked-ghosts-cough.md ├── big-phones-bow.md ├── blue-pigs-tan.md ├── clever-radios-lie.md ├── curly-rules-speak.md ├── dirty-planets-chew.md ├── good-apes-drum.md ├── long-bees-hope.md ├── quiet-pans-hunt.md ├── six-apricots-kick.md ├── tidy-clouds-smoke.md ├── two-eyes-knock.md ├── unlucky-avocados-fix.md ├── wise-frogs-give.md ├── cuddly-pugs-crash.md ├── fair-carrots-guess.md ├── lemon-seas-push.md ├── modern-ligers-behave.md ├── nervous-beds-travel.md ├── nervous-dolls-rule.md ├── olive-feet-rhyme.md ├── shy-olives-hang.md ├── spotty-dingos-stare.md ├── flat-bees-approve.md ├── great-candles-stare.md ├── green-papayas-do.md ├── rich-chairs-invent.md ├── stale-jobs-drum.md ├── wicked-rings-walk.md ├── great-terms-rescue.md ├── lemon-games-press.md ├── new-coats-turn.md ├── ninety-rice-tickle.md ├── rotten-rocks-remember.md ├── slimy-humans-impress.md ├── smooth-planets-admire.md ├── twelve-hornets-sip.md ├── violet-lions-help.md ├── brown-avocados-wink.md ├── calm-carpets-deny.md ├── polite-lizards-love.md ├── tender-pianos-check.md ├── twelve-lemons-smile.md ├── two-carpets-rhyme.md ├── four-brooms-juggle.md ├── fuzzy-jars-admire.md ├── happy-hotels-visit.md ├── hot-drinks-approve.md ├── light-donkeys-double.md ├── lucky-cows-try.md ├── slimy-needles-taste.md ├── tasty-maps-fetch.md ├── clean-walls-wink.md ├── gorgeous-games-obey.md ├── nine-birds-confess.md ├── smooth-stingrays-drum.md ├── stupid-walls-sell.md ├── clean-hats-pump.md ├── dirty-monkeys-greet.md ├── cool-horses-check.md ├── breezy-cameras-double.md ├── red-badgers-retire.md ├── sour-mails-lick.md ├── rich-queens-travel.md ├── slow-walls-poke.md ├── ninety-pets-heal.md ├── perfect-trains-double.md ├── spicy-beds-float.md ├── great-months-train.md ├── purple-singers-greet.md ├── breezy-moose-behave.md ├── twenty-beans-pump.md ├── wise-rabbits-complain.md ├── calm-nails-wait.md ├── lovely-berries-sell.md ├── quiet-sloths-rule.md ├── poor-walls-relax.md ├── wise-eels-visit.md ├── plenty-bottles-swim.md ├── config.json ├── README.md ├── mean-gorillas-reply.md └── sour-lemons-hunt.md ├── pnpm-workspace.yaml ├── .github ├── FUNDING.yml ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── config.yml │ └── feature_request.md └── PULL_REQUEST_TEMPLATE.md ├── prettier.config.js ├── CODE_OF_CONDUCT.md ├── SECURITY.md ├── .npmrc ├── CONTRIBUTOR_STATS.md ├── .prettierignore ├── turbo.json └── tsconfig.json /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /apps/web/test/setup.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.node-version: -------------------------------------------------------------------------------- 1 | 16.13.2 2 | -------------------------------------------------------------------------------- /apps/toolkit-app/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /apps/toolkit-app/db/migrations/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /apps/toolkit-app/integrations/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | **/package.json 2 | *.d.ts 3 | -------------------------------------------------------------------------------- /packages/generator/.eslintignore: -------------------------------------------------------------------------------- 1 | templates/ 2 | -------------------------------------------------------------------------------- /packages/generator/templates/app/mailers/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/generator/templates/app/db/migrations/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/generator/templates/app/integrations/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /packages/pkg-template/src/index-browser.tsx: -------------------------------------------------------------------------------- 1 | export const todo = true 2 | -------------------------------------------------------------------------------- /apps/web/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /apps/toolkit-app/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/next/eslint") 2 | -------------------------------------------------------------------------------- /packages/blitz/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /packages/blitz/bin/blitz: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require("blitz/dist/index.cjs") -------------------------------------------------------------------------------- /assets/andreas.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/assets/andreas.jpg -------------------------------------------------------------------------------- /assets/meetkai.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/assets/meetkai.png -------------------------------------------------------------------------------- /assets/rit_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/assets/rit_logo.png -------------------------------------------------------------------------------- /assets/usertrack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/assets/usertrack.png -------------------------------------------------------------------------------- /integration-tests/qm/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /packages/blitz-auth/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /packages/blitz-next/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /packages/blitz-rpc/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /packages/codemod/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /packages/generator/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /integration-tests/auth/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /packages/blitz-next/jest/client/setup-after-env.js: -------------------------------------------------------------------------------- 1 | require("@testing-library/jest-dom") 2 | -------------------------------------------------------------------------------- /packages/pkg-template/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /.changeset/ten-rivers-burn.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | fix more cli problems 6 | -------------------------------------------------------------------------------- /.changeset/two-kiwis-help.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | fix generate cli command 6 | -------------------------------------------------------------------------------- /assets/flightcontrol.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/assets/flightcontrol.png -------------------------------------------------------------------------------- /integration-tests/auth/.env: -------------------------------------------------------------------------------- 1 | SESSION_SECRET_KEY=hsdenhJfpLHrGjgdgg3jdF8g2bYD2PaQ 2 | HEADLESS=true -------------------------------------------------------------------------------- /integration-tests/middleware/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /packages/config/README.md: -------------------------------------------------------------------------------- 1 | # `config` 2 | 3 | Config files for use throughout our monorepo 4 | -------------------------------------------------------------------------------- /packages/generator/templates/app/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/next/eslint") 2 | -------------------------------------------------------------------------------- /.changeset/fair-wombats-sneeze.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | added superjson 6 | -------------------------------------------------------------------------------- /.changeset/healthy-rice-shout.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | detailed print env info 6 | -------------------------------------------------------------------------------- /.changeset/hungry-baboons-swim.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Improve codemod utilities 6 | -------------------------------------------------------------------------------- /.changeset/lovely-colts-share.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | fix broken cli versioning 6 | -------------------------------------------------------------------------------- /.changeset/moody-squids-cheer.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | test automated publish 6 | -------------------------------------------------------------------------------- /.changeset/poor-penguins-look.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | add `db seed` cli command 6 | -------------------------------------------------------------------------------- /apps/toolkit-app/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "." 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /assets/Fauna_Logo_Blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/assets/Fauna_Logo_Blue.png -------------------------------------------------------------------------------- /integration-tests/middleware/.env: -------------------------------------------------------------------------------- 1 | SESSION_SECRET_KEY=hsdenhJfpLHrGjgdgg3jdF8g2bYD2PaQ 2 | HEADLESS=true -------------------------------------------------------------------------------- /integration-tests/no-suspense/.env: -------------------------------------------------------------------------------- 1 | SESSION_SECRET_KEY=hsdenhJfpLHrGjgdgg3jdF8g2bYD2PaQ 2 | HEADLESS=true -------------------------------------------------------------------------------- /integration-tests/react-query-utils/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = require("@blitzjs/config/eslint") 2 | -------------------------------------------------------------------------------- /packages/blitz-auth/src/shared/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./constants" 2 | export * from "./types" 3 | -------------------------------------------------------------------------------- /packages/codemod/bin/@blitzjs/codemod: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require("@blitzjs/codemod/dist/index.cjs") -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - "apps/*" 3 | - "packages/*" 4 | - "integration-tests/*" 5 | -------------------------------------------------------------------------------- /.changeset/ninety-lies-press.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Temporarily skip version check 6 | -------------------------------------------------------------------------------- /.changeset/tame-keys-reply.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Add aliases for Blitz CLI commands 6 | -------------------------------------------------------------------------------- /.changeset/tough-toes-pull.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | --- 4 | 5 | Remove debug console.log 6 | -------------------------------------------------------------------------------- /assets/render-logo-color2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/assets/render-logo-color2.png -------------------------------------------------------------------------------- /integration-tests/trailing-slash/.env: -------------------------------------------------------------------------------- 1 | SESSION_SECRET_KEY=hsdenhJfpLHrGjgdgg3jdF8g2bYD2PaQ 2 | HEADLESS=true -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ["blitz"], 3 | } 4 | -------------------------------------------------------------------------------- /.changeset/cool-doors-invent.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | --- 4 | 5 | Add invokeWithCtx function 6 | -------------------------------------------------------------------------------- /.changeset/hot-cups-rhyme.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Fix blitz codegen to work with monorepos 6 | -------------------------------------------------------------------------------- /.changeset/silent-colts-reply.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | added index.cjs to blitz externals 6 | -------------------------------------------------------------------------------- /.changeset/tall-meals-learn.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Upgrade Prisma to v4.0.0 6 | -------------------------------------------------------------------------------- /.changeset/three-lies-pull.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | --- 4 | 5 | moves zod to devDependencies 6 | -------------------------------------------------------------------------------- /.changeset/two-tigers-type.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Fix running bin commands with Blitz CLI 6 | -------------------------------------------------------------------------------- /apps/toolkit-app/public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/apps/toolkit-app/public/logo.png -------------------------------------------------------------------------------- /integration-tests/react-query-utils/.env: -------------------------------------------------------------------------------- 1 | SESSION_SECRET_KEY=hsdenhJfpLHrGjgdgg3jdF8g2bYD2PaQ 2 | HEADLESS=true -------------------------------------------------------------------------------- /packages/blitz/src/global.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | var _blitz_prismaClient: any 3 | } 4 | 5 | export {} 6 | -------------------------------------------------------------------------------- /.changeset/curly-seas-serve.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Check for new versions when running CLI 6 | -------------------------------------------------------------------------------- /.changeset/fast-trainers-kneel.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Export Zod utils from blitz core package 6 | -------------------------------------------------------------------------------- /.changeset/kind-walls-suffer.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Run codegen tasks on blitz dev command 6 | -------------------------------------------------------------------------------- /.changeset/nine-onions-admire.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | downgrade pkg-dir to non-esm only version 6 | -------------------------------------------------------------------------------- /.changeset/perfect-eyes-repeat.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | --- 4 | 5 | Fix pipe resolver return type 6 | -------------------------------------------------------------------------------- /.changeset/poor-peas-lick.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | fix generator npm package dist 6 | -------------------------------------------------------------------------------- /.changeset/poor-shrimps-think.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Setup SuperJson for GSSP and GSP 6 | -------------------------------------------------------------------------------- /.changeset/quick-cycles-confess.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | fixes blitz not loading custom server 6 | -------------------------------------------------------------------------------- /.changeset/quiet-feet-travel.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | fix source path for templates 6 | -------------------------------------------------------------------------------- /.changeset/thirty-countries-build.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | add @blitzjs/generator as external 6 | -------------------------------------------------------------------------------- /.changeset/weak-suns-shave.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Move blitz config to next.config.js 6 | -------------------------------------------------------------------------------- /apps/toolkit-app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/apps/toolkit-app/public/favicon.ico -------------------------------------------------------------------------------- /apps/web/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | # Keep environment variables out of version control 3 | .env 4 | *.sqlite 5 | -------------------------------------------------------------------------------- /integration-tests/qm/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | # Keep environment variables out of version control 3 | *.sqlite 4 | -------------------------------------------------------------------------------- /packages/generator/templates/app/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "." 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/pkg-template/src/index-server.ts: -------------------------------------------------------------------------------- 1 | export * from "./index-browser" 2 | 3 | export const todoServer = true 4 | -------------------------------------------------------------------------------- /.changeset/bright-mangos-run.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | --- 4 | 5 | Add queryClient to RPC Plugin exports 6 | -------------------------------------------------------------------------------- /.changeset/gentle-dogs-reply.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Update queryClient import in codemod 6 | -------------------------------------------------------------------------------- /.changeset/green-pillows-hammer.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Runs the codegen on the blitz build command 6 | -------------------------------------------------------------------------------- /.changeset/nice-deers-dream.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Export BlitzProvider from @blitzjs/next 6 | -------------------------------------------------------------------------------- /.changeset/small-socks-confess.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/auth": patch 3 | --- 4 | 5 | Add passport adapter to @blitzjs/auth 6 | -------------------------------------------------------------------------------- /.changeset/sweet-kiwis-cross.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | --- 4 | 5 | Fix queries/mutations lookup on Windows 6 | -------------------------------------------------------------------------------- /.changeset/swift-drinks-dress.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Fix postinstall script not being found 6 | -------------------------------------------------------------------------------- /.changeset/ten-hairs-listen.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Allow customizing PreviewData in gSSP 6 | -------------------------------------------------------------------------------- /integration-tests/auth/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | # Keep environment variables out of version control 3 | *.sqlite 4 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "." 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.changeset/few-dogs-fetch.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Use correct path for log utilities import 6 | -------------------------------------------------------------------------------- /.changeset/four-sheep-judge.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Export router-context from browser entrypoint 6 | -------------------------------------------------------------------------------- /.changeset/fuzzy-bees-warn.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Fix APP_ENV not being set before loading env config 6 | -------------------------------------------------------------------------------- /.changeset/olive-bees-buy.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Fix templates source in RPC codemod step 6 | -------------------------------------------------------------------------------- /.changeset/shaggy-carpets-brake.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Fix template path for the generator 6 | -------------------------------------------------------------------------------- /.changeset/sharp-falcons-begin.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Use routes manifest in template app 6 | -------------------------------------------------------------------------------- /.changeset/smooth-rice-clap.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Fix typo in a next.config.js file name 6 | -------------------------------------------------------------------------------- /.changeset/violet-bags-leave.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Update templates directory for codemod 6 | -------------------------------------------------------------------------------- /integration-tests/middleware/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | # Keep environment variables out of version control 3 | *.sqlite 4 | -------------------------------------------------------------------------------- /integration-tests/middleware/next.config.js: -------------------------------------------------------------------------------- 1 | const {withBlitz} = require("@blitzjs/next") 2 | module.exports = withBlitz({}) 3 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | # Keep environment variables out of version control 3 | *.sqlite 4 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/next.config.js: -------------------------------------------------------------------------------- 1 | const {withBlitz} = require("@blitzjs/next") 2 | module.exports = withBlitz({}) 3 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.env.test.local: -------------------------------------------------------------------------------- 1 | # THIS FILE SHOULD NOT BE CHECKED INTO YOUR VERSION CONTROL SYSTEM 2 | -------------------------------------------------------------------------------- /.changeset/eleven-humans-sort.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | "@blitzjs/generator": patch 4 | --- 5 | 6 | codemod fixes 7 | -------------------------------------------------------------------------------- /.changeset/empty-berries-rule.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | fix app generator for pnpm unmet dependency 6 | -------------------------------------------------------------------------------- /.changeset/modern-cameras-pull.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Support `prefetchBlitzQuery` in gSSP and gSP 6 | -------------------------------------------------------------------------------- /.changeset/tasty-news-collect.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/codemod": patch 4 | --- 5 | 6 | init codemod generator 7 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | # Keep environment variables out of version control 3 | *.sqlite 4 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | # Keep environment variables out of version control 3 | *.sqlite 4 | -------------------------------------------------------------------------------- /packages/blitz-auth/src/index-server.ts: -------------------------------------------------------------------------------- 1 | import "./global" 2 | 3 | export * from "./index-browser" 4 | export * from "./server" 5 | -------------------------------------------------------------------------------- /packages/generator/src/utils/fallbackable.ts: -------------------------------------------------------------------------------- 1 | export interface Fallbackable { 2 | value: T 3 | isFallback?: boolean 4 | } 5 | -------------------------------------------------------------------------------- /.changeset/calm-horses-tie.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/generator": patch 4 | --- 5 | 6 | Add back blitz generate command 7 | -------------------------------------------------------------------------------- /.changeset/four-meals-fry.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | export BlitzPage & BlitzLayout types from @blitzjs/next 6 | -------------------------------------------------------------------------------- /.changeset/gorgeous-buses-scream.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Allow prefetching multiple queries in gSSP and gSP 6 | -------------------------------------------------------------------------------- /.changeset/heavy-apes-judge.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Show all blitz packages when running `blitz version` command 6 | -------------------------------------------------------------------------------- /.changeset/late-steaks-give.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | "@blitzjs/rpc": patch 4 | --- 5 | 6 | Support RPC error middleware 7 | -------------------------------------------------------------------------------- /.changeset/moody-bags-walk.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | "blitz": patch 4 | --- 5 | 6 | Fix redirectAuthenticatedTo errors 7 | -------------------------------------------------------------------------------- /.changeset/nice-starfishes-live.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | add mounted check to app generator template 6 | -------------------------------------------------------------------------------- /.changeset/olive-sheep-rhyme.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Add missing lint deps to the new app templates 6 | -------------------------------------------------------------------------------- /.changeset/popular-teachers-pay.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Handle next/dynamic default import in codemod 6 | -------------------------------------------------------------------------------- /.changeset/pretty-games-march.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Import ErrorComponent as DefaultErrorComponent 6 | -------------------------------------------------------------------------------- /.changeset/shy-pumpkins-try.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | "@blitzjs/rpc": patch 4 | --- 5 | 6 | Upgrade react-query to v4 7 | -------------------------------------------------------------------------------- /.changeset/silly-apricots-share.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Avoid reassigning queryClient in prefetch methods 6 | -------------------------------------------------------------------------------- /.changeset/smooth-tools-train.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Add ts-jest to dependencies in new app templates 6 | -------------------------------------------------------------------------------- /.changeset/thick-parrots-float.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | allow extension catch in getAllFiles codemod util 6 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: blitz-js 2 | custom: ["https://paypal.me/thebayers"] 3 | open_collective: blitzjs 4 | patreon: flybayer 5 | -------------------------------------------------------------------------------- /integration-tests/middleware/app/queries/getBasic.ts: -------------------------------------------------------------------------------- 1 | export default async function getBasic() { 2 | return {success: true} 3 | } 4 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/app/queries/getBasic.ts: -------------------------------------------------------------------------------- 1 | export default async function getBasic() { 2 | return "basic-result" 3 | } 4 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/next.config.js: -------------------------------------------------------------------------------- 1 | const {withBlitz} = require("@blitzjs/next") 2 | module.exports = withBlitz({}) 3 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/app/queries/getBasic.ts: -------------------------------------------------------------------------------- 1 | export default async function getBasic() { 2 | return "basic-result" 3 | } 4 | -------------------------------------------------------------------------------- /packages/blitz-next/jest/image-mock.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | src: "/public/test.png", 3 | width: 100, 4 | height: 100, 5 | } 6 | -------------------------------------------------------------------------------- /.changeset/calm-tomatoes-drive.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Include `.env.test` file to the generator templates 6 | -------------------------------------------------------------------------------- /.changeset/chilled-carrots-own.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Add `BlitzPage` type to Home pages in app templates 6 | -------------------------------------------------------------------------------- /.changeset/empty-turkeys-wave.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Use `useRouter` from next/router in useParams function 6 | -------------------------------------------------------------------------------- /.changeset/famous-kings-explain.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | updated nextjs version in generator & npmrc file 6 | -------------------------------------------------------------------------------- /.changeset/good-insects-wink.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Allow passing optional type argument for ParamsType in GSSP 6 | -------------------------------------------------------------------------------- /.changeset/soft-adults-smell.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/auth": patch 3 | --- 4 | 5 | Fix `Page.authenticate` not working for layout components 6 | -------------------------------------------------------------------------------- /.changeset/strong-apes-reply.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Remove as any assertion for the PrismaStorage argument 6 | -------------------------------------------------------------------------------- /.changeset/unlucky-papayas-sleep.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | remove console logs inside onPostInstall in the new cli command 6 | -------------------------------------------------------------------------------- /.changeset/wicked-ghosts-cough.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | fix template sourcepath because of new env variable 6 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | pnpm manypkg check 5 | pnpm lint 6 | pnpm pretty-quick --staged 7 | -------------------------------------------------------------------------------- /integration-tests/qm/next.config.js: -------------------------------------------------------------------------------- 1 | const {withBlitz} = require("@blitzjs/next") 2 | module.exports = withBlitz({ 3 | // update me 4 | }) 5 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/app/queries/getBasic.ts: -------------------------------------------------------------------------------- 1 | export default async function getBasic() { 2 | return "basic-result" 3 | } 4 | -------------------------------------------------------------------------------- /integration-tests/rpc/app/queries/v2/getNestedBasic.js: -------------------------------------------------------------------------------- 1 | export default async function getNestedBasic() { 2 | return "nested-basic" 3 | } 4 | -------------------------------------------------------------------------------- /packages/generator/templates/app/.husky/pre-push-js: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npm run lint 5 | npm run test 6 | -------------------------------------------------------------------------------- /packages/generator/types/jsx.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace JSX { 2 | interface IntrinsicElements { 3 | [elemName: string]: any 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.changeset/big-phones-bow.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | "@blitzjs/generator": patch 4 | --- 5 | 6 | add mounted check inside withBlitz 7 | -------------------------------------------------------------------------------- /.changeset/blue-pigs-tan.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Throw error if cookiePrefix is undefined when running codemod 6 | -------------------------------------------------------------------------------- /.changeset/clever-radios-lie.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | Add DocumentProps & DocumentContext to the codemod import map 5 | 6 | -------------------------------------------------------------------------------- /.changeset/curly-rules-speak.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Comment out generate command import until we add the full support back 6 | -------------------------------------------------------------------------------- /.changeset/dirty-planets-chew.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/auth": patch 3 | --- 4 | 5 | Update `deleteSession` return type — allow undefined values 6 | -------------------------------------------------------------------------------- /.changeset/good-apes-drum.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Fixes wrong import of the db module in `blitz db seed` command function 6 | -------------------------------------------------------------------------------- /.changeset/long-bees-hope.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Add type checking to next.config.js files in new app templates 6 | -------------------------------------------------------------------------------- /.changeset/quiet-pans-hunt.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Removes the suspense wrapper from withBlitz since it's not needed 6 | -------------------------------------------------------------------------------- /.changeset/six-apricots-kick.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Infer result type in the `api` handler and allow customizing it 6 | -------------------------------------------------------------------------------- /.changeset/tidy-clouds-smoke.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Fix routes manifest showing duplicates for non queries|resolvers reso… 6 | -------------------------------------------------------------------------------- /.changeset/two-eyes-knock.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Update new app templates to use blitz-rpc's resolver function 6 | -------------------------------------------------------------------------------- /.changeset/unlucky-avocados-fix.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Add `@testing-library/jest-dom` to new app dependecies 6 | -------------------------------------------------------------------------------- /.changeset/wise-frogs-give.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | use latest tag for generator template on rpc & auth packages 6 | -------------------------------------------------------------------------------- /apps/web/app/mutations/setBasic.ts: -------------------------------------------------------------------------------- 1 | export default function setBasic(input, ctx) { 2 | console.log("SET BASIC input", input) 3 | return 4 | } 5 | -------------------------------------------------------------------------------- /integration-tests/auth/next.config.js: -------------------------------------------------------------------------------- 1 | const {withBlitz} = require("@blitzjs/next") 2 | module.exports = withBlitz({ 3 | // update me 4 | }) 5 | -------------------------------------------------------------------------------- /integration-tests/rpc/pages/index.js: -------------------------------------------------------------------------------- 1 | const Page = () => { 2 | return
Hello World
3 | } 4 | export default Page 5 | -------------------------------------------------------------------------------- /packages/generator/templates/app/public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/packages/generator/templates/app/public/logo.png -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.husky/pre-push-js: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npm run lint 5 | npm run test 6 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | semi: false, 3 | printWidth: 100, 4 | bracketSpacing: false, 5 | trailingComma: "all", 6 | } 7 | -------------------------------------------------------------------------------- /.changeset/cuddly-pugs-crash.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Wrap middlewares with BlitzServerMiddleware function with codemod 6 | -------------------------------------------------------------------------------- /.changeset/fair-carrots-guess.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Fixes loading production env variables by default for blitz build command 6 | -------------------------------------------------------------------------------- /.changeset/lemon-seas-push.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Don't try to copy RPC API endpoint in templates that don't have it 6 | -------------------------------------------------------------------------------- /.changeset/modern-ligers-behave.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Add hoist pattern entry for react-query in new app templates 6 | -------------------------------------------------------------------------------- /.changeset/nervous-beds-travel.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | useParam & useParams functions now accessible from @blitzjs/next 6 | -------------------------------------------------------------------------------- /.changeset/nervous-dolls-rule.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Move middlewares from blitz config to blitz server with codemod 6 | -------------------------------------------------------------------------------- /.changeset/olive-feet-rhyme.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Add codemod to upgrade from legacy framework to the Blitz Toolkit 6 | -------------------------------------------------------------------------------- /.changeset/shy-olives-hang.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | "@blitzjs/generator": patch 4 | --- 5 | 6 | Update RPC plugin setup in templates 7 | -------------------------------------------------------------------------------- /.changeset/spotty-dingos-stare.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | --- 4 | 5 | Add `getQueryData` utility to get an existing query's cached data 6 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # The Blitz Community Code of Conduct 2 | 3 | [Read the Code of Conduct at Blitzjs.com](https://blitzjs.com/docs/code-of-conduct) 4 | -------------------------------------------------------------------------------- /apps/toolkit-app/.prettierignore: -------------------------------------------------------------------------------- 1 | .gitkeep 2 | .env* 3 | *.ico 4 | *.lock 5 | db/migrations 6 | .next 7 | .yarn 8 | .pnp.* 9 | node_modules 10 | -------------------------------------------------------------------------------- /apps/web/pages/[postId]/index.tsx: -------------------------------------------------------------------------------- 1 | export default function Post() { 2 | return ( 3 |
4 |

Post

5 |
6 | ) 7 | } 8 | -------------------------------------------------------------------------------- /integration-tests/rpc/app/queries/getFailure.js: -------------------------------------------------------------------------------- 1 | export default async function getFailure() { 2 | throw new Error("error on purpose for test") 3 | } 4 | -------------------------------------------------------------------------------- /packages/generator/templates/app/.husky/pre-push-ts: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx tsc 5 | npm run lint 6 | npm run test 7 | -------------------------------------------------------------------------------- /packages/generator/templates/app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/packages/generator/templates/app/public/favicon.ico -------------------------------------------------------------------------------- /.changeset/flat-bees-approve.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | set default enviornment variable to development unless build and start command 6 | -------------------------------------------------------------------------------- /.changeset/great-candles-stare.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | "blitz": patch 4 | --- 5 | 6 | Use internal branded blitz logger for @blitzjs/rpc 7 | -------------------------------------------------------------------------------- /.changeset/green-papayas-do.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Update codemod and template with a new queryClient import location 6 | -------------------------------------------------------------------------------- /.changeset/rich-chairs-invent.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Rename prefetchBlitzQuery to prefetchQuery, add prefetchInfiniteQuery 6 | -------------------------------------------------------------------------------- /.changeset/stale-jobs-drum.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Set correct packages versions in package.json with upgrade-legacy codemod 6 | -------------------------------------------------------------------------------- /.changeset/wicked-rings-walk.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Set prefix in moduleNameWrapper's options in Blitz's jest configuration 6 | -------------------------------------------------------------------------------- /integration-tests/rpc/pages/api/rpc/[[...blitz]].ts: -------------------------------------------------------------------------------- 1 | import {rpcHandler} from "@blitzjs/rpc" 2 | 3 | export default rpcHandler({onError: console.log}) 4 | -------------------------------------------------------------------------------- /packages/blitz-next/src/global.ts: -------------------------------------------------------------------------------- 1 | import {QueryClient} from "@tanstack/react-query" 2 | 3 | declare global { 4 | var queryClient: QueryClient 5 | } 6 | -------------------------------------------------------------------------------- /packages/generator/templates/app/.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | npx pretty-quick --staged 6 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.husky/pre-push-ts: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx tsc 5 | npm run lint 6 | npm run test 7 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/packages/generator/templates/minimalapp/public/logo.png -------------------------------------------------------------------------------- /.changeset/great-terms-rescue.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Add BlitzServerMiddleware utility function to wrap middleware in blitz server file 6 | -------------------------------------------------------------------------------- /.changeset/lemon-games-press.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | "@blitzjs/generator": patch 4 | --- 5 | 6 | Update Next.js version and addBasePath location 7 | -------------------------------------------------------------------------------- /.changeset/new-coats-turn.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/codemod": patch 4 | --- 5 | 6 | Handle duplicate imports with Blitz upgrade-legacy codemod 7 | -------------------------------------------------------------------------------- /.changeset/ninety-rice-tickle.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/generator": patch 4 | --- 5 | 6 | Improve `blitz new` messaging and fix minor issues 7 | -------------------------------------------------------------------------------- /.changeset/rotten-rocks-remember.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Run codegen tasks after creating a new app if user chose yarn as a package manager 6 | -------------------------------------------------------------------------------- /.changeset/slimy-humans-impress.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Remove trailing comma from tsconfig.json file in the new app template" 6 | -------------------------------------------------------------------------------- /.changeset/smooth-planets-admire.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Add missing \_document.tsx and 404.tsx pages to the new app templates 6 | -------------------------------------------------------------------------------- /.changeset/twelve-hornets-sip.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Fix codemod to accept a self closing `DocumentHead` in the `_document` page 6 | -------------------------------------------------------------------------------- /.changeset/violet-lions-help.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | --- 4 | 5 | Add resolverBasePath to Blitz config to change the way rpc routes are generated 6 | -------------------------------------------------------------------------------- /apps/web/app/queries/getBasic.ts: -------------------------------------------------------------------------------- 1 | export default async function getBasic(input, ctx) { 2 | console.log("INPUT", input) 3 | 4 | return "basic-result" 5 | } 6 | -------------------------------------------------------------------------------- /apps/web/app/queries/v2/getV2Basic.ts: -------------------------------------------------------------------------------- 1 | export default function getV2Basic(input, ctx) { 2 | console.log("INPUT", input) 3 | 4 | return "basic-result" 5 | } 6 | -------------------------------------------------------------------------------- /integration-tests/middleware/pages/api/rpc/[[...blitz]].ts: -------------------------------------------------------------------------------- 1 | import {rpcHandler} from "@blitzjs/rpc" 2 | 3 | export default rpcHandler({onError: console.log}) 4 | -------------------------------------------------------------------------------- /integration-tests/rpc/app/mutations/setBasic.js: -------------------------------------------------------------------------------- 1 | export default async function setBasic(input, ctx) { 2 | global.basic = input 3 | return global.basic 4 | } 5 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/next.config.js: -------------------------------------------------------------------------------- 1 | const {withBlitz} = require("@blitzjs/next") 2 | module.exports = withBlitz({ 3 | trailingSlash: true, 4 | }) 5 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | npx pretty-quick --staged 6 | -------------------------------------------------------------------------------- /.changeset/brown-avocados-wink.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Print model added or updated in schema.prisma after running model generator 6 | -------------------------------------------------------------------------------- /.changeset/calm-carpets-deny.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Fixes the db seed command so that the database can disconnect after running the seed file. 6 | -------------------------------------------------------------------------------- /.changeset/polite-lizards-love.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Passes the correct arguments (without flags) to any bin command ran with the blitz cli 6 | -------------------------------------------------------------------------------- /.changeset/tender-pianos-check.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/next": patch 4 | "@blitzjs/generator": patch 5 | --- 6 | 7 | various improvements and fixes 8 | -------------------------------------------------------------------------------- /.changeset/twelve-lemons-smile.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Fix prefetching multiple queries causes only the last one to be passed to page 6 | -------------------------------------------------------------------------------- /.changeset/two-carpets-rhyme.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | During `blitz new` if project name argument is set to "." change it to current folder name 6 | -------------------------------------------------------------------------------- /apps/web/test/hello.unit.test.ts: -------------------------------------------------------------------------------- 1 | function sum(a, b) { 2 | return a + b 3 | } 4 | 5 | test("adds 1 + 2 to equal 3", () => { 6 | expect(sum(1, 2)).toBe(3) 7 | }) 8 | -------------------------------------------------------------------------------- /packages/generator/src/errors/prompt-aborted.ts: -------------------------------------------------------------------------------- 1 | export class PromptAbortedError extends Error { 2 | constructor() { 3 | super("Prompt aborted") 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fcoury/blitz/main/packages/generator/templates/minimalapp/public/favicon.ico -------------------------------------------------------------------------------- /.changeset/four-brooms-juggle.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/auth": patch 3 | "@blitzjs/next": patch 4 | --- 5 | 6 | Add missing RouteUrlObject on Page.authenticate.redirectTo 7 | -------------------------------------------------------------------------------- /.changeset/fuzzy-jars-admire.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | fix codemod for wrapping \_app arrow function & fix codemod for nested pages directory 6 | -------------------------------------------------------------------------------- /.changeset/happy-hotels-visit.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Add missing value to "skip" option when choosing a package manager during new app scaffolding 6 | -------------------------------------------------------------------------------- /.changeset/hot-drinks-approve.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | "@blitzjs/generator": patch 4 | --- 5 | 6 | Upgrade @types/react, fix typings inside @blitzjs/next 7 | -------------------------------------------------------------------------------- /.changeset/light-donkeys-double.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Run `prisma generate` as a `blitz codegen` step if "prisma" is found in project's dependencies 6 | -------------------------------------------------------------------------------- /.changeset/lucky-cows-try.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/auth": patch 4 | "@blitzjs/next": patch 5 | --- 6 | 7 | rename middleware type for blitz server plugin 8 | -------------------------------------------------------------------------------- /.changeset/slimy-needles-taste.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | "@blitzjs/generator": patch 4 | --- 5 | 6 | Add jest.config.js to newly generated typescript apps 7 | -------------------------------------------------------------------------------- /.changeset/tasty-maps-fetch.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Fix `enhancePrisma is undefined` errors by moving the utility function to a browser entrypoint 6 | -------------------------------------------------------------------------------- /integration-tests/rpc/next.config.js: -------------------------------------------------------------------------------- 1 | const {withBlitz} = require("@blitzjs/next") 2 | module.exports = withBlitz({ 3 | target: "experimental-serverless-trace", 4 | }) 5 | -------------------------------------------------------------------------------- /packages/blitz-auth/src/index-browser.tsx: -------------------------------------------------------------------------------- 1 | import "./global" 2 | 3 | export * from "./client" 4 | export * from "./shared/constants" 5 | export * from "./shared/types" 6 | -------------------------------------------------------------------------------- /packages/blitz-next/scripts/default-index.js: -------------------------------------------------------------------------------- 1 | exports.Routes = { 2 | ThisFileHasNotYetBeenGeneratedPleaseRunBlitzCodeGen: (query) => ({pathname: "⚡️", query}), 3 | } 4 | -------------------------------------------------------------------------------- /.changeset/clean-walls-wink.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | --- 4 | 5 | Pass `signal` from useQuery to Blitz internal rpc client to be able to cancel queries on unmount 6 | -------------------------------------------------------------------------------- /.changeset/gorgeous-games-obey.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Avoid `invalid config detected` warnings by deleting `"blitz"` key from next config object 6 | -------------------------------------------------------------------------------- /.changeset/nine-birds-confess.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | "@blitzjs/rpc": patch 4 | "blitz": patch 5 | --- 6 | 7 | Fix SSP / SP not prefetching queries correctly 8 | -------------------------------------------------------------------------------- /.changeset/smooth-stingrays-drum.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Updates the error messages based on if it's a babel parse error or an unexpected error 6 | -------------------------------------------------------------------------------- /.changeset/stupid-walls-sell.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/auth": patch 4 | "@blitzjs/next": patch 5 | "@blitzjs/rpc": patch 6 | --- 7 | 8 | testing set dist-tag 9 | -------------------------------------------------------------------------------- /apps/web/db/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" 4 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/prisma/seed.ts: -------------------------------------------------------------------------------- 1 | import prisma from "./index" 2 | 3 | const seed = async () => { 4 | await prisma.$reset() 5 | } 6 | 7 | export default seed 8 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/db/seed.ts: -------------------------------------------------------------------------------- 1 | import prisma from "./index" 2 | 3 | const seed = async () => { 4 | await prisma.$reset() 5 | } 6 | 7 | export default seed 8 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/db/seed.ts: -------------------------------------------------------------------------------- 1 | import prisma from "./index" 2 | 3 | const seed = async () => { 4 | await prisma.$reset() 5 | } 6 | 7 | export default seed 8 | -------------------------------------------------------------------------------- /packages/blitz-next/scripts/default-index-browser.js: -------------------------------------------------------------------------------- 1 | exports.Routes = { 2 | ThisFileHasNotYetBeenGeneratedPleaseRunBlitzCodeGen: (query) => ({pathname: "⚡️", query}), 3 | } 4 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/types.ts: -------------------------------------------------------------------------------- 1 | import { DefaultCtx } from "blitz" 2 | 3 | declare module "blitz" { 4 | export interface Ctx extends DefaultCtx {} 5 | } 6 | -------------------------------------------------------------------------------- /.changeset/clean-hats-pump.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Allow using `RouteUrlObject` as `redirect.destination` in `getStaticProps` and `getServerSideProps` 6 | -------------------------------------------------------------------------------- /.changeset/dirty-monkeys-greet.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/generator": patch 4 | --- 5 | 6 | Use alpha version for blitz dependency, fix package manager selection 7 | -------------------------------------------------------------------------------- /apps/toolkit-app/db/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /integration-tests/auth/pages/api/noauth.ts: -------------------------------------------------------------------------------- 1 | import {api} from "../../app/blitz-server" 2 | 3 | export default api(async (_req, res, ctx) => { 4 | res.status(200).end() 5 | }) 6 | -------------------------------------------------------------------------------- /packages/blitz-auth/src/server/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./auth-sessions" 2 | export * from "./auth-utils" 3 | export * from "./auth-plugin" 4 | export * from "./passport-adapter" 5 | -------------------------------------------------------------------------------- /packages/blitz/src/cli/commands/next/index.ts: -------------------------------------------------------------------------------- 1 | import {dev} from "./dev" 2 | import {build} from "./build" 3 | import {start} from "./start" 4 | 5 | export {dev, build, start} 6 | -------------------------------------------------------------------------------- /packages/generator/templates/app/.prettierignore: -------------------------------------------------------------------------------- 1 | .gitkeep 2 | .env* 3 | *.ico 4 | *.lock 5 | db/migrations 6 | .next 7 | .yarn 8 | .pnp.* 9 | node_modules 10 | README.md 11 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.env.local: -------------------------------------------------------------------------------- 1 | # This env file should NOT be checked into source control 2 | # This is the place for values that changed for every developer 3 | -------------------------------------------------------------------------------- /packages/pkg-template/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.library.json", 3 | "include": ["."], 4 | "exclude": ["dist", "build", "node_modules"] 5 | } 6 | -------------------------------------------------------------------------------- /.changeset/cool-horses-check.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | --- 4 | 5 | Fixes issue when generating a new blitz app with the form flag that ends up installing the wrong form library 6 | -------------------------------------------------------------------------------- /apps/web/pages/api/rpc/[[...blitz]].ts: -------------------------------------------------------------------------------- 1 | import {rpcHandler} from "@blitzjs/rpc" 2 | import {api} from "app/blitz-server" 3 | 4 | export default api(rpcHandler({onError: console.log})) 5 | -------------------------------------------------------------------------------- /integration-tests/middleware/app/blitz-client.ts: -------------------------------------------------------------------------------- 1 | import {setupBlitzClient} from "@blitzjs/next" 2 | 3 | const {withBlitz} = setupBlitzClient({plugins: []}) 4 | 5 | export {withBlitz} 6 | -------------------------------------------------------------------------------- /.changeset/breezy-cameras-double.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/next": patch 4 | "@blitzjs/generator": patch 5 | --- 6 | 7 | Fix codegen and postinstall to make work with pnpm 8 | -------------------------------------------------------------------------------- /.changeset/red-badgers-retire.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/next": patch 4 | "@blitzjs/rpc": patch 5 | "@blitzjs/generator": patch 6 | --- 7 | 8 | Fixes peer dependency warnings 9 | -------------------------------------------------------------------------------- /.changeset/sour-mails-lick.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Allow codemod to finish if `cookiePrefix` is undefined. Then show error at the end of running the codemod. 6 | -------------------------------------------------------------------------------- /apps/toolkit-app/app/auth/mutations/logout.ts: -------------------------------------------------------------------------------- 1 | import { Ctx } from "blitz" 2 | 3 | export default async function logout(_: any, ctx: Ctx) { 4 | return await ctx.session.$revoke() 5 | } 6 | -------------------------------------------------------------------------------- /integration-tests/auth/prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /integration-tests/middleware/pages/api/test.ts: -------------------------------------------------------------------------------- 1 | import {api} from "../../app/blitz-server" 2 | 3 | export default api((_req, res) => { 4 | res.status(200).json({success: true}) 5 | }) 6 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/app/blitz-client.ts: -------------------------------------------------------------------------------- 1 | import {setupBlitzClient} from "@blitzjs/next" 2 | 3 | export const {withBlitz} = setupBlitzClient({ 4 | plugins: [] 5 | }) 6 | -------------------------------------------------------------------------------- /.changeset/rich-queens-travel.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/auth": patch 4 | "@blitzjs/next": patch 5 | "@blitzjs/rpc": patch 6 | --- 7 | 8 | Remove references to the logging package 9 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /integration-tests/trailing-slash/db/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /packages/blitz-rpc/src/global.ts: -------------------------------------------------------------------------------- 1 | import {QueryClient} from "@tanstack/react-query" 2 | 3 | declare global { 4 | var queryClient: QueryClient 5 | var __BLITZ_SUSPENSE_ENABLED: boolean 6 | } 7 | -------------------------------------------------------------------------------- /apps/toolkit-app/pages/api/rpc/[[...blitz]].ts: -------------------------------------------------------------------------------- 1 | import { rpcHandler } from "@blitzjs/rpc" 2 | import { api } from "app/blitz-server" 3 | 4 | export default api(rpcHandler({ onError: console.log })) 5 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/db/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.prettierignore: -------------------------------------------------------------------------------- 1 | .gitkeep 2 | .env* 3 | *.ico 4 | *.lock 5 | .next 6 | .blitz 7 | .yarn 8 | .pnp.* 9 | node_modules 10 | .blitz.config.compiled.js 11 | -------------------------------------------------------------------------------- /.changeset/slow-walls-poke.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | "@blitzjs/rpc": patch 4 | --- 5 | 6 | Allow resolverPath to be a function which is ran for every file path that is converted to RPC Route 7 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners 2 | 3 | * @beerose @dillonraphael 4 | 5 | packages/generator/templates**/* @flybayer 6 | -------------------------------------------------------------------------------- /apps/toolkit-app/test/setup.ts: -------------------------------------------------------------------------------- 1 | // This is the jest 'setupFilesAfterEnv' setup file 2 | // It's a good place to set globals, add global before/after hooks, etc 3 | 4 | export {} // so TS doesn't complain 5 | -------------------------------------------------------------------------------- /packages/generator/templates/app/app/auth/mutations/logout.ts: -------------------------------------------------------------------------------- 1 | import { Ctx } from "blitz" 2 | 3 | export default async function logout(_: any, ctx: Ctx) { 4 | return await ctx.session.$revoke() 5 | } 6 | -------------------------------------------------------------------------------- /.changeset/ninety-pets-heal.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/auth": patch 4 | "@blitzjs/next": patch 5 | "@blitzjs/rpc": patch 6 | "@blitzjs/generator": patch 7 | --- 8 | 9 | initial publish 10 | -------------------------------------------------------------------------------- /integration-tests/middleware/app/blitz-server.ts: -------------------------------------------------------------------------------- 1 | import {setupBlitzServer} from "@blitzjs/next" 2 | 3 | const {gSSP, gSP, api} = setupBlitzServer({ 4 | plugins: [], 5 | }) 6 | 7 | export {gSSP, gSP, api} 8 | -------------------------------------------------------------------------------- /.changeset/perfect-trains-double.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Wrap `blitz.config.ts` with the `withBlitz` function during the codemod step instead of creating a blank `next.config.js` file. 6 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/pages/api/rpc/[[...blitz]].ts: -------------------------------------------------------------------------------- 1 | import {rpcHandler} from "@blitzjs/rpc" 2 | import {api} from "../../../app/blitz-server" 3 | 4 | export default api(rpcHandler({onError: console.log})) 5 | -------------------------------------------------------------------------------- /packages/generator/templates/app/pages/api/rpc/blitzrpcroute.ts: -------------------------------------------------------------------------------- 1 | import { rpcHandler } from "@blitzjs/rpc" 2 | import { api } from "app/blitz-server" 3 | 4 | export default api(rpcHandler({ onError: console.log })) 5 | -------------------------------------------------------------------------------- /.changeset/spicy-beds-float.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/auth": patch 3 | "@blitzjs/next": patch 4 | "@blitzjs/rpc": patch 5 | "blitz": patch 6 | "@blitzjs/generator": patch 7 | --- 8 | Fixes the supports-color warning for pnpm 9 | -------------------------------------------------------------------------------- /apps/toolkit-app/.env: -------------------------------------------------------------------------------- 1 | # This env file should be checked into source control 2 | # This is the place for default values for all environments 3 | # Values in `.env.local` and `.env.production` will override these values 4 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/pages/api/rpc/[[...blitz]].ts: -------------------------------------------------------------------------------- 1 | import {rpcHandler} from "@blitzjs/rpc" 2 | import {api} from "../../../app/blitz-server" 3 | 4 | export default api(rpcHandler({onError: console.log})) 5 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/pages/api/rpc/[[...blitz]].ts: -------------------------------------------------------------------------------- 1 | import {rpcHandler} from "@blitzjs/rpc" 2 | import {api} from "../../../app/blitz-server" 3 | 4 | export default api(rpcHandler({onError: console.log})) 5 | -------------------------------------------------------------------------------- /packages/generator/templates/app/test/setup.ts: -------------------------------------------------------------------------------- 1 | // This is the jest 'setupFilesAfterEnv' setup file 2 | // It's a good place to set globals, add global before/after hooks, etc 3 | 4 | export {} // so TS doesn't complain 5 | -------------------------------------------------------------------------------- /.changeset/great-months-train.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/next": patch 4 | "@blitzjs/auth": patch 5 | "@blitzjs/rpc": patch 6 | "@blitzjs/generator": patch 7 | --- 8 | 9 | fix route manifest codegen 10 | -------------------------------------------------------------------------------- /.changeset/purple-singers-greet.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/rpc": patch 3 | "@blitzjs/codemod": patch 4 | "@blitzjs/generator": patch 5 | --- 6 | 7 | getQueryClient function & queryClient codemod updates & shared plugin config 8 | -------------------------------------------------------------------------------- /integration-tests/rpc/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import {defineConfig} from "vitest/config" 2 | 3 | export default defineConfig({ 4 | test: { 5 | testTimeout: 5000 * 60 * 2, 6 | hookTimeout: 5000 * 60 * 2, 7 | }, 8 | }) 9 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | TODO 6 | 7 | ## Reporting a Vulnerability 8 | 9 | Email Brandon Bayer at b@bayer.ws to report a vulnerablity, and he will follow up with you asap. 10 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-use-authorize.tsx: -------------------------------------------------------------------------------- 1 | import {useAuthorize} from "@blitzjs/auth" 2 | 3 | export default function PgaeWithUseAuthorize() { 4 | useAuthorize() 5 | return
This page is using useAuthorize
6 | } 7 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/test/setup.ts: -------------------------------------------------------------------------------- 1 | // This is the jest 'setupFilesAfterEnv' setup file 2 | // It's a good place to set globals, add global before/after hooks, etc 3 | 4 | export {} // so TS doesn't complain 5 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-use-session.tsx: -------------------------------------------------------------------------------- 1 | import {useSession} from "@blitzjs/auth" 2 | 3 | export default function PgaeWithUseSession() { 4 | const data = useSession() 5 | return
{JSON.stringify({data}, null, 2)}
6 | } 7 | -------------------------------------------------------------------------------- /integration-tests/rpc/pages/query.js: -------------------------------------------------------------------------------- 1 | import getBasic from "../app/queries/getBasic" 2 | 3 | const Page = () => { 4 | getBasic().then(console.log) 5 | return
Hello World
6 | } 7 | export default Page 8 | -------------------------------------------------------------------------------- /packages/generator/templates/app/.env: -------------------------------------------------------------------------------- 1 | # This env file should be checked into source control 2 | # This is the place for default values for all environments 3 | # Values in `.env.local` and `.env.production` will override these values 4 | -------------------------------------------------------------------------------- /.changeset/breezy-moose-behave.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": minor 3 | "@blitzjs/auth": patch 4 | --- 5 | 6 | Truncate errors from `api/auth//callback` request to 100 characters before passing them to the `?authError=` query parameter 7 | -------------------------------------------------------------------------------- /apps/web/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /apps/web/pages/page-without-flicker.tsx: -------------------------------------------------------------------------------- 1 | const PageWithoutFlicker = ({data}) => { 2 | return
{JSON.stringify(data)}
3 | } 4 | 5 | PageWithoutFlicker.suppressFirstRenderFlicker = true 6 | 7 | export default PageWithoutFlicker 8 | -------------------------------------------------------------------------------- /.changeset/twenty-beans-pump.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/auth": patch 4 | "@blitzjs/next": patch 5 | "@blitzjs/rpc": patch 6 | "@blitzjs/config": patch 7 | "@blitzjs/generator": patch 8 | --- 9 | 10 | new app template 11 | -------------------------------------------------------------------------------- /.changeset/wise-rabbits-complain.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/generator": patch 3 | --- 4 | 5 | Mocks @blitzjs/auth instead of blitz inside the forgotPassword mutation test & hardcodes blitz package version types instead of just using the alpha tag. 6 | -------------------------------------------------------------------------------- /packages/blitz-auth/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.library.json", 3 | "compilerOptions": { 4 | "lib": ["DOM", "ES2015"] 5 | }, 6 | "include": ["."], 7 | "exclude": ["dist", "build", "node_modules"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/blitz-rpc/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.library.json", 3 | "compilerOptions": { 4 | "lib": ["DOM", "ES2015"] 5 | }, 6 | "include": ["."], 7 | "exclude": ["dist", "build", "node_modules"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.env: -------------------------------------------------------------------------------- 1 | # This env file should be checked into source control 2 | # This is the place for default values for all environments 3 | # Values in `.env.local` and `.env.production` will override these values 4 | -------------------------------------------------------------------------------- /apps/toolkit-app/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /apps/web/app/queries/getUsersAuth.ts: -------------------------------------------------------------------------------- 1 | import {resolver} from "@blitzjs/rpc" 2 | import db from "db" 3 | 4 | export default resolver.pipe(resolver.authorize(), async () => { 5 | const users = await db.user.findMany() 6 | 7 | return users 8 | }) 9 | -------------------------------------------------------------------------------- /integration-tests/auth/pages/index.tsx: -------------------------------------------------------------------------------- 1 | export const getServerSideProps = () => { 2 | return {props: {}} 3 | } 4 | 5 | export default function Web() { 6 | return ( 7 |
8 |

Web

9 |
10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/auth/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /integration-tests/middleware/middleware.ts: -------------------------------------------------------------------------------- 1 | import {NextResponse} from "next/server" 2 | 3 | export function middleware() { 4 | const response = NextResponse.next() 5 | response.headers.set("global-middleware", "true") 6 | return response 7 | } 8 | -------------------------------------------------------------------------------- /integration-tests/middleware/pages/index.tsx: -------------------------------------------------------------------------------- 1 | export const getServerSideProps = () => { 2 | return {props: {}} 3 | } 4 | 5 | export default function Web() { 6 | return ( 7 |
8 |

Web

9 |
10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/qm/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /integration-tests/rpc/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /packages/blitz-auth/src/global.ts: -------------------------------------------------------------------------------- 1 | import {SessionConfig} from "./shared/types" 2 | 3 | declare global { 4 | var sessionConfig: SessionConfig 5 | var __BLITZ_SESSION_COOKIE_PREFIX: string | undefined 6 | var __BLITZ_SUSPENSE_ENABLED: boolean 7 | } 8 | -------------------------------------------------------------------------------- /packages/blitz-next/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.library.json", 3 | "compilerOptions": { 4 | "lib": ["DOM", "ES2015", "es2019"] 5 | }, 6 | "include": ["."], 7 | "exclude": ["dist", "build", "node_modules"] 8 | } 9 | -------------------------------------------------------------------------------- /.changeset/calm-nails-wait.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | These are various changes to will make the codemod more dynamic and work with a larger variety of codebases. These fixes are implemented to make the codemod work with flightdeck. 6 | -------------------------------------------------------------------------------- /.changeset/lovely-berries-sell.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | --- 4 | 5 | Remove trailing comma when removing BlitzConfig from next.config.js & Fix codemod so if route (eg. `app/auth/pages`) convert to (eg. `pages/`) instead of (eg. `pages/auth`) 6 | -------------------------------------------------------------------------------- /apps/toolkit-app/.editorconfig: -------------------------------------------------------------------------------- 1 | # https://EditorConfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 2 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-use-authorize-if.tsx: -------------------------------------------------------------------------------- 1 | import {useAuthorizeIf} from "@blitzjs/auth" 2 | 3 | export default function PageWithUseAuthorizeIf() { 4 | useAuthorizeIf(Math.random() > 0.5) 5 | return
This page is using useAuthorizeIf
6 | } 7 | -------------------------------------------------------------------------------- /integration-tests/middleware/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /packages/generator/templates/app/next.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | const {withBlitz} = require("@blitzjs/next") 3 | 4 | /** 5 | * @type {import('@blitzjs/next').BlitzConfig} 6 | **/ 7 | const config = {} 8 | 9 | module.exports = withBlitz(config) 10 | -------------------------------------------------------------------------------- /.changeset/quiet-sloths-rule.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/next": patch 3 | --- 4 | 5 | Removes the check for when withBlitz is mounted before rendering the users app. We had this previously to avoid the react 18 suspense error being showin in development with nextjs. 6 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-use-auth-session.tsx: -------------------------------------------------------------------------------- 1 | import {useAuthenticatedSession} from "@blitzjs/auth" 2 | 3 | export default function PageWithUseAuthSession() { 4 | useAuthenticatedSession() 5 | return
This page is using useAuthenticatedSession
6 | } 7 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /.changeset/poor-walls-relax.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/codemod": patch 3 | "@blitzjs/generator": patch 4 | "@blitzjs/auth": patch 5 | "@blitzjs/next": patch 6 | "@blitzjs/rpc": patch 7 | "@blitzjs/config": patch 8 | --- 9 | 10 | Set current Blitz tag to latest 11 | -------------------------------------------------------------------------------- /.changeset/wise-eels-visit.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/auth": patch 4 | "@blitzjs/next": patch 5 | "@blitzjs/rpc": patch 6 | "@blitzjs/codemod": patch 7 | "@blitzjs/config": patch 8 | "@blitzjs/generator": patch 9 | --- 10 | 11 | Beta release 12 | -------------------------------------------------------------------------------- /apps/web/.npmrc: -------------------------------------------------------------------------------- 1 | save-exact=true 2 | legacy-peer-deps=true 3 | 4 | public-hoist-pattern[]=@tanstack/react-query 5 | public-hoist-pattern[]=next 6 | public-hoist-pattern[]=secure-password 7 | public-hoist-pattern[]=*jest* 8 | public-hoist-pattern[]=@testing-library/* 9 | -------------------------------------------------------------------------------- /apps/web/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.nextjs.json", 3 | "compilerOptions": { 4 | "baseUrl": "." 5 | }, 6 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "jest.config.js"], 7 | "exclude": ["node_modules", "test"] 8 | } 9 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /packages/generator/src/utils/module.ts: -------------------------------------------------------------------------------- 1 | const invalidateCache = (module: string) => { 2 | delete require.cache[require.resolve(module)] 3 | } 4 | 5 | export const forceRequire = (module: string) => { 6 | invalidateCache(module) 7 | return require(module) 8 | } 9 | -------------------------------------------------------------------------------- /packages/generator/src/utils/pipe.ts: -------------------------------------------------------------------------------- 1 | export function pipe(...fns: Function[]): (initial: any, ...args: any[]) => any { 2 | return function piper(initial: any, ...args: any[]): any { 3 | return fns.reduce((acc, val) => val(acc, ...args), initial) 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/generator/templates/app/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.defaultFormatter": "esbenp.prettier-vscode", 3 | "editor.formatOnSave": true, 4 | "editor.codeActionsOnSave": { 5 | "source.fixAll.eslint": true 6 | }, 7 | "jest.autoRun": "off" 8 | } 9 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/next.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | const {withBlitz} = require("@blitzjs/next") 3 | 4 | /** 5 | * @type {import('@blitzjs/next').BlitzConfig} 6 | **/ 7 | const config = {} 8 | 9 | module.exports = withBlitz(config) 10 | -------------------------------------------------------------------------------- /apps/toolkit-app/.npmrc: -------------------------------------------------------------------------------- 1 | save-exact=true 2 | legacy-peer-deps=true 3 | 4 | public-hoist-pattern[]=@tanstack/react-query 5 | public-hoist-pattern[]=next 6 | public-hoist-pattern[]=secure-password 7 | public-hoist-pattern[]=*jest* 8 | public-hoist-pattern[]=@testing-library/* 9 | -------------------------------------------------------------------------------- /apps/toolkit-app/db/index.ts: -------------------------------------------------------------------------------- 1 | import { enhancePrisma } from "blitz" 2 | import { PrismaClient } from "@prisma/client" 3 | 4 | const EnhancedPrisma = enhancePrisma(PrismaClient) 5 | 6 | export * from "@prisma/client" 7 | const db = new EnhancedPrisma() 8 | export default db 9 | -------------------------------------------------------------------------------- /apps/web/db/index.ts: -------------------------------------------------------------------------------- 1 | import {enhancePrisma} from "blitz" 2 | import {PrismaClient} from "@prisma/client" 3 | 4 | const EnhancedPrisma = enhancePrisma(PrismaClient) 5 | 6 | export * from "@prisma/client" 7 | const prisma = new EnhancedPrisma() 8 | export default prisma 9 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-use-redirect-auth.tsx: -------------------------------------------------------------------------------- 1 | import {useRedirectAuthenticated} from "@blitzjs/auth" 2 | 3 | export default function PageWithUseRedirectAuth() { 4 | useRedirectAuthenticated("/") 5 | return
This page is using useRedirectAuthenticated
6 | } 7 | -------------------------------------------------------------------------------- /packages/blitz-next/scripts/default-index.d.ts: -------------------------------------------------------------------------------- 1 | import type {ParsedUrlQueryInput} from "querystring" 2 | import type {UrlObject} from "url" 3 | 4 | export const Routes: { 5 | ThisFileHasNotYetBeenGeneratedPleaseRunBlitzCodeGen(query?: ParsedUrlQueryInput): UrlObject 6 | } 7 | -------------------------------------------------------------------------------- /packages/generator/templates/app/.editorconfig: -------------------------------------------------------------------------------- 1 | # https://EditorConfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 2 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.defaultFormatter": "esbenp.prettier-vscode", 3 | "editor.formatOnSave": true, 4 | "editor.codeActionsOnSave": { 5 | "source.fixAll.eslint": true 6 | }, 7 | "jest.autoRun": "off" 8 | } 9 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /apps/toolkit-app/app/core/hooks/useCurrentUser.ts: -------------------------------------------------------------------------------- 1 | import { useQuery } from "@blitzjs/rpc" 2 | import getCurrentUser from "app/users/queries/getCurrentUser" 3 | 4 | export const useCurrentUser = () => { 5 | const [user] = useQuery(getCurrentUser, null) 6 | return user 7 | } 8 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | save-exact=true 2 | strict-peer-dependencies=false 3 | 4 | public-hoist-pattern[]=secure-password 5 | public-hoist-pattern[]=*types* 6 | public-hoist-pattern[]=*eslint* 7 | public-hoist-pattern[]=@prettier/plugin-* 8 | public-hoist-pattern[]=*prettier-plugin-* 9 | 10 | -------------------------------------------------------------------------------- /CONTRIBUTOR_STATS.md: -------------------------------------------------------------------------------- 1 | # Contributor over time 2 | 3 | [![Contributor over time](https://contributor-graph-api.apiseven.com/contributors-svg?chart=contributorOverTime&repo=blitz-js/blitz)](https://www.apiseven.com/en/contributor-graph?chart=contributorOverTime&repo=blitz-js/blitz) 4 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.editorconfig: -------------------------------------------------------------------------------- 1 | # https://EditorConfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 2 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | -------------------------------------------------------------------------------- /apps/web/pages/api/logout.ts: -------------------------------------------------------------------------------- 1 | import {api} from "app/blitz-server" 2 | 3 | export default api(async (_req, res, ctx) => { 4 | const blitzContext = ctx 5 | 6 | await blitzContext.session.$revoke() 7 | 8 | res.status(200).json({userId: blitzContext.session.userId}) 9 | }) 10 | -------------------------------------------------------------------------------- /integration-tests/auth/prisma/index.ts: -------------------------------------------------------------------------------- 1 | import {enhancePrisma} from "blitz" 2 | import {PrismaClient} from "@prisma/client" 3 | 4 | const EnhancedPrisma = enhancePrisma(PrismaClient) 5 | 6 | export * from "@prisma/client" 7 | const prisma = new EnhancedPrisma() 8 | export default prisma 9 | -------------------------------------------------------------------------------- /packages/generator/build.config.ts: -------------------------------------------------------------------------------- 1 | import {BuildConfig} from "unbuild" 2 | 3 | const config: BuildConfig = { 4 | entries: ["./src/index"], 5 | externals: ["react"], 6 | declaration: true, 7 | rollup: { 8 | emitCJS: true, 9 | }, 10 | } 11 | export default config 12 | -------------------------------------------------------------------------------- /apps/web/pages/api/is-authorized.ts: -------------------------------------------------------------------------------- 1 | import {api} from "app/blitz-server" 2 | 3 | export default api(async (_req, res, ctx) => { 4 | const {session} = ctx 5 | 6 | const authorized = session.$isAuthorized() 7 | 8 | res.status(200).json({ 9 | authorized, 10 | }) 11 | }) 12 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/db/index.ts: -------------------------------------------------------------------------------- 1 | import {enhancePrisma} from "blitz" 2 | import {PrismaClient} from "@prisma/client" 3 | 4 | const EnhancedPrisma = enhancePrisma(PrismaClient) 5 | 6 | export * from "@prisma/client" 7 | const prisma = new EnhancedPrisma() 8 | export default prisma 9 | -------------------------------------------------------------------------------- /packages/blitz/src/cli/utils/constants.ts: -------------------------------------------------------------------------------- 1 | export const NON_STANDARD_NODE_ENV = `You are using a non-standard "NODE_ENV" value in your environment. This creates inconsistencies in the project and is strongly advised against. Read more: https://nextjs.org/docs/messages/non-standard-node-env` 2 | -------------------------------------------------------------------------------- /packages/generator/templates/app/app/core/hooks/useCurrentUser.ts: -------------------------------------------------------------------------------- 1 | import { useQuery } from "@blitzjs/rpc" 2 | import getCurrentUser from "app/users/queries/getCurrentUser" 3 | 4 | export const useCurrentUser = () => { 5 | const [user] = useQuery(getCurrentUser, null) 6 | return user 7 | } 8 | -------------------------------------------------------------------------------- /packages/generator/templates/app/db/index.ts: -------------------------------------------------------------------------------- 1 | import { enhancePrisma } from "blitz" 2 | import { PrismaClient } from "@prisma/client" 3 | 4 | const EnhancedPrisma = enhancePrisma(PrismaClient) 5 | 6 | export * from "@prisma/client" 7 | const db = new EnhancedPrisma() 8 | export default db 9 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/prisma/index.ts: -------------------------------------------------------------------------------- 1 | import {enhancePrisma} from "blitz" 2 | import {PrismaClient} from "@prisma/client" 3 | 4 | const EnhancedPrisma = enhancePrisma(PrismaClient) 5 | 6 | export * from "@prisma/client" 7 | const prisma = new EnhancedPrisma() 8 | export default prisma 9 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/db/index.ts: -------------------------------------------------------------------------------- 1 | import {enhancePrisma} from "blitz" 2 | import {PrismaClient} from "@prisma/client" 3 | 4 | const EnhancedPrisma = enhancePrisma(PrismaClient) 5 | 6 | export * from "@prisma/client" 7 | const prisma = new EnhancedPrisma() 8 | export default prisma 9 | -------------------------------------------------------------------------------- /packages/codemod/build.config.ts: -------------------------------------------------------------------------------- 1 | import {BuildConfig} from "unbuild" 2 | 3 | const config: BuildConfig = { 4 | entries: ["./src/index"], 5 | externals: ["index.cjs", "blitz"], 6 | declaration: true, 7 | rollup: { 8 | emitCJS: true, 9 | }, 10 | } 11 | export default config 12 | -------------------------------------------------------------------------------- /apps/web/app/queries/getUsers.ts: -------------------------------------------------------------------------------- 1 | import {Ctx} from "blitz" 2 | import db, {User} from "db" 3 | 4 | export default async function getUsers(_input: {}, ctx: Ctx): Promise { 5 | ctx.session.$authorize() 6 | 7 | const users = await db.user.findMany() 8 | 9 | return users 10 | } 11 | -------------------------------------------------------------------------------- /apps/web/jest.config.js: -------------------------------------------------------------------------------- 1 | const nextJest = require("@blitzjs/next/jest") 2 | 3 | const createJestConfig = nextJest({ 4 | dir: "./", 5 | }) 6 | 7 | const customJestConfig = { 8 | testEnvironment: "jest-environment-jsdom", 9 | } 10 | 11 | module.exports = createJestConfig(customJestConfig) 12 | -------------------------------------------------------------------------------- /packages/blitz-next/src/router-context.ts: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import {NextRouter} from "next/router" 3 | 4 | export const RouterContext = React.createContext(null as any) 5 | 6 | if (process.env.NODE_ENV !== "production") { 7 | RouterContext.displayName = "RouterContext" 8 | } 9 | -------------------------------------------------------------------------------- /integration-tests/auth/pages/api/logout.ts: -------------------------------------------------------------------------------- 1 | import {api} from "../../app/blitz-server" 2 | 3 | export default api(async (_req, res, ctx) => { 4 | const blitzContext = ctx 5 | 6 | await blitzContext.session.$revoke() 7 | 8 | res.status(200).json({userId: blitzContext.session.userId}) 9 | }) 10 | -------------------------------------------------------------------------------- /apps/toolkit-app/jest.config.js: -------------------------------------------------------------------------------- 1 | const nextJest = require("@blitzjs/next/jest") 2 | 3 | const createJestConfig = nextJest({ 4 | dir: "./", 5 | }) 6 | 7 | const customJestConfig = { 8 | testEnvironment: "jest-environment-jsdom", 9 | } 10 | 11 | module.exports = createJestConfig(customJestConfig) 12 | -------------------------------------------------------------------------------- /packages/generator/src/utils/match-between.ts: -------------------------------------------------------------------------------- 1 | export function matchBetween(test: string, start: string, end: string) { 2 | const re = new RegExp(`${start}([\\s\\S]*?)${end}`, "g") 3 | const match = test.match(re) 4 | 5 | if (match) { 6 | return match[0] 7 | } 8 | 9 | return match 10 | } 11 | -------------------------------------------------------------------------------- /packages/generator/templates/app/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | 5 | // NOTE: This file should not be edited 6 | // see https://nextjs.org/docs/basic-features/typescript for more information. 7 | -------------------------------------------------------------------------------- /packages/blitz/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.library.json", 3 | "compilerOptions": { 4 | "lib": ["DOM", "ES2015"], 5 | "esModuleInterop": true, 6 | "resolveJsonModule": true 7 | }, 8 | "include": ["."], 9 | "exclude": ["dist", "build", "node_modules"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/codemod/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.library.json", 3 | "compilerOptions": { 4 | "lib": ["DOM", "ES2015"], 5 | "esModuleInterop": true, 6 | "resolveJsonModule": true 7 | }, 8 | "include": ["."], 9 | "exclude": ["dist", "build", "node_modules"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/generator/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | .DS_Store 3 | node_modules 4 | .rts2_cache_cjs 5 | .rts2_cache_esm 6 | .rts2_cache_umd 7 | .rts2_cache_system 8 | dist 9 | tmp 10 | .blitz 11 | 12 | # good directory to use for testing app generation 13 | _app 14 | 15 | !templates/**/.env* 16 | !templates/**/.vscode 17 | -------------------------------------------------------------------------------- /packages/config/tsconfig.library.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Library", 4 | "extends": "./tsconfig.base.json", 5 | "compilerOptions": { 6 | "lib": ["ES2015"], 7 | "module": "ESNext", 8 | "target": "ES6", 9 | "jsx": "react" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/generator/templates/app/jest.config.js: -------------------------------------------------------------------------------- 1 | const nextJest = require("@blitzjs/next/jest") 2 | 3 | const createJestConfig = nextJest({ 4 | dir: "./", 5 | }) 6 | 7 | const customJestConfig = { 8 | testEnvironment: "jest-environment-jsdom", 9 | } 10 | 11 | module.exports = createJestConfig(customJestConfig) 12 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/jest.config.js: -------------------------------------------------------------------------------- 1 | const nextJest = require("@blitzjs/next/jest") 2 | 3 | const createJestConfig = nextJest({ 4 | dir: "./", 5 | }) 6 | 7 | const customJestConfig = { 8 | testEnvironment: "jest-environment-jsdom", 9 | } 10 | 11 | module.exports = createJestConfig(customJestConfig) 12 | -------------------------------------------------------------------------------- /integration-tests/qm/vitest.config.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { defineConfig } from 'vitest/config' 4 | import react from '@vitejs/plugin-react' 5 | 6 | // https://vitejs.dev/config/ 7 | export default defineConfig({ 8 | plugins: [react()], 9 | test: { 10 | environment: 'jsdom', 11 | }, 12 | }) -------------------------------------------------------------------------------- /integration-tests/auth/app/blitz-client.ts: -------------------------------------------------------------------------------- 1 | import {AuthClientPlugin} from "@blitzjs/auth" 2 | import {setupBlitzClient} from "@blitzjs/next" 3 | 4 | const {withBlitz} = setupBlitzClient({ 5 | plugins: [ 6 | AuthClientPlugin({ 7 | cookiePrefix: "auth-tests-cookie-prefix", 8 | }), 9 | ], 10 | }) 11 | 12 | export {withBlitz} 13 | -------------------------------------------------------------------------------- /integration-tests/auth/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.nextjs.json", 3 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "types"], 4 | "compilerOptions": { 5 | "paths": { 6 | "react": ["./node_modules/@types/react"] 7 | } 8 | }, 9 | "exclude": ["node_modules"], 10 | "baseUrl": "." 11 | } 12 | -------------------------------------------------------------------------------- /packages/generator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.library.json", 3 | "compilerOptions": { 4 | "lib": ["ES2019"], 5 | "declaration": true, 6 | "baseUrl": ".", 7 | "preserveSymlinks": true 8 | }, 9 | "include": ["."], 10 | "exclude": ["dist", "build", "node_modules", "./templates/**"] 11 | } 12 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | **/migrations/** 2 | .blitz 3 | .next 4 | .log 5 | .DS_Store 6 | .jest-* 7 | packages/cli/lib 8 | node_modules 9 | reports 10 | *.log 11 | **/.env* 12 | .nyc_output 13 | **/coverage 14 | .yarn 15 | .yarnrc 16 | tsconfig.tsbuildinfo 17 | dist 18 | bin 19 | .github/ISSUE_TEMPLATE/bug_report.md 20 | packages/generator/templates/** 21 | -------------------------------------------------------------------------------- /integration-tests/middleware/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.nextjs.json", 3 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "types"], 4 | "compilerOptions": { 5 | "paths": { 6 | "react": ["./node_modules/@types/react"] 7 | } 8 | }, 9 | "exclude": ["node_modules"], 10 | "baseUrl": "." 11 | } 12 | -------------------------------------------------------------------------------- /.changeset/plenty-bottles-swim.md: -------------------------------------------------------------------------------- 1 | --- 2 | "blitz": patch 3 | "@blitzjs/next": patch 4 | "@blitzjs/generator": patch 5 | --- 6 | 7 | - Add mounted check to withBlitz 8 | - Upgrade @types/react, fix typings inside @blitzjs/next 9 | - Support prefetchBlitzQuery in gSP and gSSP 10 | - Add db seed cli command 11 | - Add try/catch to changePassword mutation 12 | -------------------------------------------------------------------------------- /integration-tests/auth/pages/authenticated-page.tsx: -------------------------------------------------------------------------------- 1 | import {useAuthorize} from "@blitzjs/auth" 2 | 3 | export const getServerSideProps = () => { 4 | return {props: {}} 5 | } 6 | 7 | export default function AuthenticatedQuery() { 8 | useAuthorize() 9 | return ( 10 |
11 |

AuthenticatedQuery

12 |
13 | ) 14 | } 15 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.nextjs.json", 3 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "types"], 4 | "compilerOptions": { 5 | "paths": { 6 | "react": ["./node_modules/@types/react"] 7 | } 8 | }, 9 | "exclude": ["node_modules"], 10 | "baseUrl": "." 11 | } 12 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.nextjs.json", 3 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "types"], 4 | "compilerOptions": { 5 | "paths": { 6 | "react": ["./node_modules/@types/react"] 7 | } 8 | }, 9 | "exclude": ["node_modules"], 10 | "baseUrl": "." 11 | } 12 | -------------------------------------------------------------------------------- /packages/pkg-template/build.config.ts: -------------------------------------------------------------------------------- 1 | import {BuildConfig} from "unbuild" 2 | 3 | const config: BuildConfig = { 4 | entries: ["./src/index-browser", "./src/index-server"], 5 | externals: ["index-browser.cjs", "index-browser.mjs", "react"], 6 | declaration: true, 7 | rollup: { 8 | emitCJS: true, 9 | }, 10 | } 11 | export default config 12 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.nextjs.json", 3 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "types"], 4 | "compilerOptions": { 5 | "paths": { 6 | "react": ["./node_modules/@types/react"] 7 | } 8 | }, 9 | "exclude": ["node_modules"], 10 | "baseUrl": "." 11 | } 12 | -------------------------------------------------------------------------------- /packages/blitz-auth/build.config.ts: -------------------------------------------------------------------------------- 1 | import {BuildConfig} from "unbuild" 2 | 3 | const config: BuildConfig = { 4 | entries: ["./src/index-browser", "./src/index-server"], 5 | externals: ["index-browser.cjs", "index-browser.mjs", "react", "next"], 6 | declaration: true, 7 | rollup: { 8 | emitCJS: true, 9 | }, 10 | } 11 | export default config 12 | -------------------------------------------------------------------------------- /packages/generator/templates/app/.env.test: -------------------------------------------------------------------------------- 1 | # SQLite is ready to go out of the box, but you can switch to Postgres 2 | # by first changing the provider from "sqlite" to "postgres" in the Prisma 3 | # schema file and by second swapping the DATABASE_URL below. 4 | DATABASE_URL="file:./db_test.sqlite" 5 | # DATABASE_URL=postgresql://__username__@localhost:5432/__name___test -------------------------------------------------------------------------------- /packages/codemod/src/index.test.ts: -------------------------------------------------------------------------------- 1 | import {expect, describe, it} from "vitest" 2 | import spawn from "cross-spawn" 3 | 4 | describe("codemod cli", () => { 5 | it("errors without codemod name", async () => { 6 | const run = spawn.sync("node", ["dist/index.cjs"], {encoding: "utf8"}) 7 | expect(run.stdout).toContain("Codemod not found") 8 | }) 9 | }) 10 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.env.test: -------------------------------------------------------------------------------- 1 | # SQLite is ready to go out of the box, but you can switch to Postgres 2 | # by first changing the provider from "sqlite" to "postgres" in the Prisma 3 | # schema file and by second swapping the DATABASE_URL below. 4 | DATABASE_URL="file:./db_test.sqlite" 5 | # DATABASE_URL=postgresql://__username__@localhost:5432/__name___test -------------------------------------------------------------------------------- /apps/web/pages/api/revoke-all-sessions.ts: -------------------------------------------------------------------------------- 1 | import {api} from "app/blitz-server" 2 | import db from "db" 3 | 4 | export default api(async (_req, res) => { 5 | const sessions = await db.session.deleteMany() 6 | const sessionsCount = await db.session.count() 7 | 8 | res.status(200).json({ 9 | activeSessions: sessions, 10 | sessionsCount, 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /packages/blitz/src/cli/commands/codegen.ts: -------------------------------------------------------------------------------- 1 | import {CliCommand} from "../index" 2 | import {codegenTasks} from "../utils/codegen-tasks" 3 | 4 | const codegen: CliCommand = async () => { 5 | try { 6 | await codegenTasks() 7 | process.exit(0) 8 | } catch (err) { 9 | console.log(err) 10 | process.exit(1) 11 | } 12 | } 13 | 14 | export {codegen} 15 | -------------------------------------------------------------------------------- /packages/blitz/src/cli/utils/get-package-json.ts: -------------------------------------------------------------------------------- 1 | import {existsSync} from "fs" 2 | import {readJSON} from "fs-extra" 3 | import {join} from "path" 4 | 5 | export const getPackageJson = async () => { 6 | const pkgJsonPath = join(process.cwd(), "package.json") 7 | if (existsSync(pkgJsonPath)) { 8 | return readJSON(pkgJsonPath) 9 | } 10 | return {} 11 | } 12 | -------------------------------------------------------------------------------- /packages/generator/templates/app/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "dbaeumer.vscode-eslint", 4 | "editorconfig.editorconfig", 5 | "esbenp.prettier-vscode", 6 | "mikestead.dotenv", 7 | "mgmcdermott.vscode-language-babel", 8 | "orta.vscode-jest", 9 | "prisma.prisma" 10 | ], 11 | "unwantedRecommendations": [] 12 | } 13 | -------------------------------------------------------------------------------- /apps/web/pages/authenticated-page.tsx: -------------------------------------------------------------------------------- 1 | const AuthPage = () => { 2 | return ( 3 |
4 | {JSON.stringify( 5 | { 6 | message: "This is a page that requires authentication", 7 | }, 8 | null, 9 | 2, 10 | )} 11 |
12 | ) 13 | } 14 | 15 | AuthPage.authenticate = true 16 | 17 | export default AuthPage 18 | -------------------------------------------------------------------------------- /integration-tests/utils/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.nextjs.json", 3 | "include": ["*.ts", "*.tsx"], 4 | "compilerOptions": { 5 | "declaration": true, 6 | "declarationMap": true, 7 | "paths": { 8 | "react": ["./node_modules/@types/react"] 9 | } 10 | }, 11 | "exclude": ["node_modules"], 12 | "baseUrl": "." 13 | } 14 | -------------------------------------------------------------------------------- /packages/blitz-next/build.config.ts: -------------------------------------------------------------------------------- 1 | import {BuildConfig} from "unbuild" 2 | 3 | const config: BuildConfig = { 4 | entries: ["./src/index-browser", "./src/index-server"], 5 | externals: ["index-browser.cjs", "index-browser.mjs", "blitz", ".blitz", "next", "react"], 6 | declaration: true, 7 | rollup: { 8 | emitCJS: true, 9 | }, 10 | } 11 | export default config 12 | -------------------------------------------------------------------------------- /packages/blitz-rpc/test/sample.test.ts: -------------------------------------------------------------------------------- 1 | import {assert, expect, test} from "vitest" 2 | 3 | test("JSON", () => { 4 | const input = { 5 | foo: "hello", 6 | bar: "world", 7 | } 8 | 9 | const output = JSON.stringify(input) 10 | 11 | expect(output).eq('{"foo":"hello","bar":"world"}') 12 | assert.deepEqual(JSON.parse(output), input, "matches original") 13 | }) 14 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "dbaeumer.vscode-eslint", 4 | "editorconfig.editorconfig", 5 | "esbenp.prettier-vscode", 6 | "mikestead.dotenv", 7 | "mgmcdermott.vscode-language-babel", 8 | "orta.vscode-jest", 9 | "prisma.prisma" 10 | ], 11 | "unwantedRecommendations": [] 12 | } 13 | -------------------------------------------------------------------------------- /packages/generator/templates/query/__name__.ts: -------------------------------------------------------------------------------- 1 | import { resolver } from "@blitzjs/rpc" 2 | import db from "db" 3 | import {z} from "zod" 4 | 5 | const __Name__ = z.object({ 6 | id: z.number(), 7 | }) 8 | 9 | export default resolver.pipe( 10 | resolver.zod(__Name__), 11 | resolver.authorize(), 12 | async (input) => { 13 | 14 | // Do your stuff :) 15 | 16 | } 17 | ) -------------------------------------------------------------------------------- /packages/blitz/build.config.ts: -------------------------------------------------------------------------------- 1 | import {BuildConfig} from "unbuild" 2 | 3 | const config: BuildConfig = { 4 | entries: ["./src/index-browser", "./src/index-server", "./src/cli/index"], 5 | externals: ["index-browser.cjs", "index-browser.mjs", "index.cjs", "zod", "react"], 6 | declaration: true, 7 | rollup: { 8 | emitCJS: true, 9 | }, 10 | } 11 | export default config 12 | -------------------------------------------------------------------------------- /packages/generator/templates/mutation/__name__.ts: -------------------------------------------------------------------------------- 1 | import { resolver } from "@blitzjs/rpc" 2 | import db from "db" 3 | import {z} from "zod" 4 | 5 | const __Name__ = z.object({ 6 | id: z.number(), 7 | }) 8 | 9 | export default resolver.pipe( 10 | resolver.zod(__Name__), 11 | resolver.authorize(), 12 | async (input) => { 13 | 14 | // Do your stuff :) 15 | 16 | }, 17 | ) -------------------------------------------------------------------------------- /packages/pkg-template/test/sample.test.ts: -------------------------------------------------------------------------------- 1 | import {assert, expect, test} from "vitest" 2 | 3 | test("JSON", () => { 4 | const input = { 5 | foo: "hello", 6 | bar: "world", 7 | } 8 | 9 | const output = JSON.stringify(input) 10 | 11 | expect(output).eq('{"foo":"hello","bar":"world"}') 12 | assert.deepEqual(JSON.parse(output), input, "matches original") 13 | }) 14 | -------------------------------------------------------------------------------- /apps/web/app/mutations/createUser.ts: -------------------------------------------------------------------------------- 1 | import {Ctx} from "blitz" 2 | import db, {User} from "db" 3 | 4 | export default async function createUser( 5 | input: {name: string; email: string}, 6 | ctx: Ctx, 7 | ): Promise { 8 | ctx.session.$authorize() 9 | 10 | const user = await db.user.create({data: {name: input.name, email: input.email}}) 11 | 12 | return user 13 | } 14 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "fixed": [["blitz"], ["@blitzjs/*"]], 6 | "linked": [], 7 | "access": "restricted", 8 | "baseBranch": "main", 9 | "updateInternalDependencies": "patch", 10 | "ignore": ["web", "test-*", "toolkit-app"] 11 | } 12 | -------------------------------------------------------------------------------- /apps/toolkit-app/app/blitz-client.ts: -------------------------------------------------------------------------------- 1 | import { AuthClientPlugin } from "@blitzjs/auth" 2 | import { setupBlitzClient } from "@blitzjs/next" 3 | import { BlitzRpcPlugin } from "@blitzjs/rpc" 4 | 5 | export const { withBlitz } = setupBlitzClient({ 6 | plugins: [ 7 | AuthClientPlugin({ 8 | cookiePrefix: "web-cookie-prefix", 9 | }), 10 | BlitzRpcPlugin({}), 11 | ], 12 | }) 13 | -------------------------------------------------------------------------------- /apps/web/types.ts: -------------------------------------------------------------------------------- 1 | import {SimpleRolesIsAuthorized} from "@blitzjs/auth" 2 | import {User} from "db" 3 | 4 | export type Role = "ADMIN" | "USER" 5 | 6 | declare module "@blitzjs/auth" { 7 | export interface Session { 8 | isAuthorized: SimpleRolesIsAuthorized 9 | PublicData: { 10 | userId: User["id"] 11 | role: Role 12 | views?: number 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /apps/web/next.config.js: -------------------------------------------------------------------------------- 1 | const withBundleAnalyzer = require("@next/bundle-analyzer")({ 2 | enabled: process.env.ANALYZE === "true", 3 | }) 4 | const {withBlitz} = require("@blitzjs/next") 5 | 6 | module.exports = withBlitz( 7 | withBundleAnalyzer({ 8 | reactStrictMode: true, 9 | blitz: { 10 | customServer: { 11 | hotReload: false, 12 | }, 13 | }, 14 | }), 15 | ) 16 | -------------------------------------------------------------------------------- /apps/web/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import {invoke} from "@blitzjs/rpc" 2 | import getBasic from "app/queries/getBasic" 3 | 4 | export const getServerSideProps = () => { 5 | return {props: {}} 6 | } 7 | 8 | export default function Web() { 9 | return ( 10 |
11 |

Web

12 | 13 |
14 | ) 15 | } 16 | -------------------------------------------------------------------------------- /integration-tests/rpc/app/queries/getBasic.js: -------------------------------------------------------------------------------- 1 | if (typeof window !== "undefined") { 2 | throw new Error("This should not be loaded on the client") 3 | } 4 | 5 | export default async function getBasic() { 6 | if (typeof window !== "undefined") { 7 | throw new Error("This should not be loaded on the client") 8 | } 9 | 10 | global.basic ??= "basic-result" 11 | return global.basic 12 | } 13 | -------------------------------------------------------------------------------- /packages/blitz/src/utils/server.ts: -------------------------------------------------------------------------------- 1 | import * as fs from "fs" 2 | import * as path from "path" 3 | 4 | export function readBlitzConfig(rootFolder: string = process.cwd()) { 5 | const nextConfigFile = fs.readFileSync(path.join(rootFolder, "next.config.js"), { 6 | encoding: "utf8", 7 | flag: "r", 8 | }) 9 | const nextConfig = eval(nextConfigFile) 10 | 11 | return nextConfig.blitz || {} 12 | } 13 | -------------------------------------------------------------------------------- /apps/toolkit-app/types.ts: -------------------------------------------------------------------------------- 1 | import { SimpleRolesIsAuthorized } from "@blitzjs/auth" 2 | import { User } from "db" 3 | 4 | export type Role = "ADMIN" | "USER" 5 | 6 | declare module "@blitzjs/auth" { 7 | export interface Session { 8 | isAuthorized: SimpleRolesIsAuthorized 9 | PublicData: { 10 | userId: User["id"] 11 | role: Role 12 | views?: number 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /apps/toolkit-app/next.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | const withBundleAnalyzer = require("@next/bundle-analyzer")({ 4 | enabled: process.env.ANALYZE === "true", 5 | }) 6 | const { withBlitz } = require("@blitzjs/next") 7 | 8 | /** 9 | * @type {import('@blitzjs/next').BlitzConfig} 10 | **/ 11 | const config = { 12 | reactStrictMode: true, 13 | } 14 | 15 | module.exports = withBlitz(withBundleAnalyzer(config)) 16 | -------------------------------------------------------------------------------- /integration-tests/auth/types.ts: -------------------------------------------------------------------------------- 1 | import {SimpleRolesIsAuthorized} from "@blitzjs/auth" 2 | import {User} from "./prisma" 3 | 4 | export type Role = "ADMIN" | "USER" 5 | 6 | declare module "@blitzjs/auth" { 7 | export interface Session { 8 | isAuthorized: SimpleRolesIsAuthorized 9 | PublicData: { 10 | userId: User["id"] 11 | role: Role 12 | views?: number 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/types.ts: -------------------------------------------------------------------------------- 1 | import {SimpleRolesIsAuthorized} from "@blitzjs/auth" 2 | import {User} from "./db" 3 | 4 | export type Role = "ADMIN" | "USER" 5 | 6 | declare module "@blitzjs/auth" { 7 | export interface Session { 8 | isAuthorized: SimpleRolesIsAuthorized 9 | PublicData: { 10 | userId: User["id"] 11 | role: Role 12 | views?: number 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/types.ts: -------------------------------------------------------------------------------- 1 | import {SimpleRolesIsAuthorized} from "@blitzjs/auth" 2 | import {User} from "./prisma" 3 | 4 | export type Role = "ADMIN" | "USER" 5 | 6 | declare module "@blitzjs/auth" { 7 | export interface Session { 8 | isAuthorized: SimpleRolesIsAuthorized 9 | PublicData: { 10 | userId: User["id"] 11 | role: Role 12 | views?: number 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /integration-tests/qm/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@blitzjs/config/tsconfig.nextjs.json", 3 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "../utils/blitz-test-utils.tsx"], 4 | "compilerOptions": { 5 | "declaration": true, 6 | "declarationMap": true, 7 | "paths": { 8 | "react": ["./node_modules/@types/react"] 9 | } 10 | }, 11 | "exclude": ["node_modules"], 12 | "baseUrl": "." 13 | } 14 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/types.ts: -------------------------------------------------------------------------------- 1 | import {SimpleRolesIsAuthorized} from "@blitzjs/auth" 2 | import {User} from "./db" 3 | 4 | export type Role = "ADMIN" | "USER" 5 | 6 | declare module "@blitzjs/auth" { 7 | export interface Session { 8 | isAuthorized: SimpleRolesIsAuthorized 9 | PublicData: { 10 | userId: User["id"] 11 | role: Role 12 | views?: number 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/generator/templates/app/npmrc: -------------------------------------------------------------------------------- 1 | save-exact=true 2 | legacy-peer-deps=true 3 | strict-peer-dependencies=false 4 | side-effects-cache=false 5 | 6 | public-hoist-pattern[]=@tanstack/react-query 7 | public-hoist-pattern[]=next 8 | public-hoist-pattern[]=secure-password 9 | public-hoist-pattern[]=*jest* 10 | public-hoist-pattern[]=@testing-library/* 11 | # Needed for Blitz to work properly. Don't remove the lines above. 12 | -------------------------------------------------------------------------------- /packages/generator/templates/app/types.ts: -------------------------------------------------------------------------------- 1 | import { SimpleRolesIsAuthorized } from "@blitzjs/auth" 2 | import { User } from "db" 3 | 4 | export type Role = "ADMIN" | "USER" 5 | 6 | declare module "@blitzjs/auth" { 7 | export interface Session { 8 | isAuthorized: SimpleRolesIsAuthorized 9 | PublicData: { 10 | userId: User["id"] 11 | role: Role 12 | views?: number 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/npmrc: -------------------------------------------------------------------------------- 1 | save-exact=true 2 | legacy-peer-deps=true 3 | strict-peer-dependencies=false 4 | side-effects-cache=false 5 | 6 | public-hoist-pattern[]=@tanstack/react-query 7 | public-hoist-pattern[]=next 8 | public-hoist-pattern[]=secure-password 9 | public-hoist-pattern[]=*jest* 10 | public-hoist-pattern[]=@testing-library/* 11 | # Needed for Blitz to work properly. Don't remove the lines above. 12 | -------------------------------------------------------------------------------- /apps/toolkit-app/app/users/queries/getCurrentUser.ts: -------------------------------------------------------------------------------- 1 | import { Ctx } from "blitz" 2 | import db from "db" 3 | 4 | export default async function getCurrentUser(_ = null, { session }: Ctx) { 5 | if (!session.userId) return null 6 | 7 | const user = await db.user.findFirst({ 8 | where: { id: session.userId as number }, 9 | select: { id: true, name: true, email: true, role: true }, 10 | }) 11 | 12 | return user 13 | } 14 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/app/blitz-client.ts: -------------------------------------------------------------------------------- 1 | import {BlitzRpcPlugin} from "@blitzjs/rpc" 2 | import {setupBlitzClient} from "@blitzjs/next" 3 | import {AuthClientPlugin} from "@blitzjs/auth" 4 | 5 | const {withBlitz} = setupBlitzClient({ 6 | plugins: [ 7 | AuthClientPlugin({ 8 | cookiePrefix: "no-suspense-tests-cookie-prefix", 9 | }), 10 | BlitzRpcPlugin({}), 11 | ], 12 | }) 13 | 14 | export {withBlitz} 15 | -------------------------------------------------------------------------------- /packages/config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@blitzjs/config", 3 | "private": true, 4 | "version": "2.0.0-beta.1", 5 | "license": "MIT", 6 | "dependencies": { 7 | "@typescript-eslint/eslint-plugin": "5.9.1", 8 | "@typescript-eslint/parser": "5.9.1", 9 | "eslint-config-next": "12.2.0", 10 | "eslint-config-prettier": "8.5.0" 11 | }, 12 | "devDependencies": { 13 | "typescript": "^4.5.3" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Prisma issue? 4 | url: https://github.com/prisma/prisma/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc 5 | about: All Prisma issues should be opened in the Prisma Github 6 | - name: Question, Discussion, Idea? 7 | url: https://github.com/blitz-js/blitz/discussions/new 8 | about: Ask questions and discuss with other community members 9 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/app/blitz-client.ts: -------------------------------------------------------------------------------- 1 | import {BlitzRpcPlugin} from "@blitzjs/rpc" 2 | import {setupBlitzClient} from "@blitzjs/next" 3 | import {AuthClientPlugin} from "@blitzjs/auth" 4 | 5 | const {withBlitz} = setupBlitzClient({ 6 | plugins: [ 7 | AuthClientPlugin({ 8 | cookiePrefix: "trailing-slash-tests-cookie-prefix", 9 | }), 10 | BlitzRpcPlugin({}), 11 | ], 12 | }) 13 | 14 | export {withBlitz} 15 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-gsp.tsx: -------------------------------------------------------------------------------- 1 | import {gSP} from "app/blitz-server" 2 | 3 | export const getStaticProps = gSP<{data: {test: string}}>(async ({ctx}) => { 4 | return { 5 | props: { 6 | data: { 7 | test: "hello", 8 | date: new Date(), 9 | }, 10 | }, 11 | } 12 | }) 13 | 14 | function PageWithGsp({data}) { 15 | return
{JSON.stringify(data, null, 2)}
16 | } 17 | 18 | export default PageWithGsp 19 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/app/blitz-client.ts: -------------------------------------------------------------------------------- 1 | import {BlitzRpcPlugin} from "@blitzjs/rpc" 2 | import {setupBlitzClient} from "@blitzjs/next" 3 | import {AuthClientPlugin} from "@blitzjs/auth" 4 | 5 | const {withBlitz} = setupBlitzClient({ 6 | plugins: [ 7 | AuthClientPlugin({ 8 | cookiePrefix: "react-query-utils-tests-cookie-prefix", 9 | }), 10 | BlitzRpcPlugin({}), 11 | ], 12 | }) 13 | 14 | export {withBlitz} 15 | -------------------------------------------------------------------------------- /packages/blitz-next/jest/server/setup-after-env.js: -------------------------------------------------------------------------------- 1 | require("@testing-library/jest-dom") 2 | process.env.__BLITZ_SESSION_COOKIE_PREFIX = "blitz" 3 | 4 | jest.setTimeout(10000) 5 | 6 | afterAll(async () => { 7 | try { 8 | await global._blitz_prismaClient.$disconnect() 9 | // console.log("DISCONNECT") 10 | // await new Promise((resolve) => setTimeout(resolve, 500)) 11 | } catch (error) { 12 | // ignore error 13 | } 14 | }) 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature/change request 3 | about: Something new or better! 4 | title: "" 5 | labels: "status/triage" 6 | assignees: "" 7 | --- 8 | 9 | ### What do you want and why? 10 | 11 | The more information the better! 12 | 13 | ### Possible implementation(s) 14 | 15 | How might we do this? 16 | 17 | ### Additional context 18 | 19 | Add any other context or screenshots about the feature request here. 20 | -------------------------------------------------------------------------------- /integration-tests/auth/prisma/seed.ts: -------------------------------------------------------------------------------- 1 | import prisma from "./index" 2 | import {SecurePassword} from "@blitzjs/auth" 3 | 4 | const seed = async () => { 5 | await prisma.$reset() 6 | 7 | const hashedPassword = await SecurePassword.hash("abcd1234") 8 | 9 | await prisma.user.create({ 10 | data: { 11 | email: "test@test.com", 12 | hashedPassword, 13 | role: "user", 14 | }, 15 | }) 16 | } 17 | 18 | export default seed 19 | -------------------------------------------------------------------------------- /packages/generator/templates/app/app/users/queries/getCurrentUser.ts: -------------------------------------------------------------------------------- 1 | import { Ctx } from "blitz" 2 | import db from "db" 3 | 4 | export default async function getCurrentUser(_ = null, { session }: Ctx) { 5 | if (!session.userId) return null 6 | 7 | const user = await db.user.findFirst({ 8 | where: { id: session.userId as number }, 9 | select: { id: true, name: true, email: true, role: true }, 10 | }) 11 | 12 | return user 13 | } 14 | -------------------------------------------------------------------------------- /packages/generator/templates/app/app/blitz-client.ts: -------------------------------------------------------------------------------- 1 | import { AuthClientPlugin } from "@blitzjs/auth" 2 | import { setupBlitzClient } from "@blitzjs/next" 3 | import { BlitzRpcPlugin } from "@blitzjs/rpc" 4 | 5 | export const authConfig = { 6 | cookiePrefix: "__safeNameSlug__-cookie-prefix" 7 | } 8 | 9 | export const { withBlitz } = setupBlitzClient({ 10 | plugins: [ 11 | AuthClientPlugin(authConfig), 12 | BlitzRpcPlugin({}), 13 | ], 14 | }) 15 | -------------------------------------------------------------------------------- /packages/generator/templates/app/db/seeds.ts: -------------------------------------------------------------------------------- 1 | // import db from "./index" 2 | 3 | /* 4 | * This seed function is executed when you run `blitz db seed`. 5 | * 6 | * Probably you want to use a library like https://chancejs.com 7 | * to easily generate realistic data. 8 | */ 9 | const seed = async () => { 10 | // for (let i = 0; i < 5; i++) { 11 | // await db.project.create({ data: { name: "Project " + i } }) 12 | // } 13 | } 14 | 15 | export default seed 16 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-auth-redirect.tsx: -------------------------------------------------------------------------------- 1 | const PageWithAuthRedirect = () => { 2 | return ( 3 |
4 | {JSON.stringify( 5 | { 6 | message: 7 | "This is a page that will redirect you to the Home page if you are authenticated", 8 | }, 9 | null, 10 | 2, 11 | )} 12 |
13 | ) 14 | } 15 | 16 | PageWithAuthRedirect.redirectAuthenticatedTo = "/" 17 | 18 | export default PageWithAuthRedirect 19 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-redirect.tsx: -------------------------------------------------------------------------------- 1 | const PageWithRedirect = () => { 2 | return ( 3 |
4 | {JSON.stringify( 5 | { 6 | message: 7 | "This page requires authentication. It will redirect you to the Home page if you are NOT authenticated", 8 | }, 9 | null, 10 | 2, 11 | )} 12 |
13 | ) 14 | } 15 | 16 | PageWithRedirect.authenticate = {redirectTo: "/"} 17 | 18 | export default PageWithRedirect 19 | -------------------------------------------------------------------------------- /packages/generator/templates/app/.env.local: -------------------------------------------------------------------------------- 1 | # This env file should NOT be checked into source control 2 | # This is the place for values that changed for every developer 3 | 4 | # SQLite is ready to go out of the box, but you can switch to Postgres 5 | # by first changing the provider from "sqlite" to "postgres" in the Prisma 6 | # schema file and by second swapping the DATABASE_URL below. 7 | DATABASE_URL="file:./db.sqlite" 8 | # DATABASE_URL=postgresql://__username__@localhost:5432/__name__ -------------------------------------------------------------------------------- /apps/web/pages/users.tsx: -------------------------------------------------------------------------------- 1 | import {useQuery} from "@blitzjs/rpc" 2 | import getUsers from "app/queries/getUsers" 3 | 4 | function UsersPage() { 5 | const [users] = useQuery(getUsers, {}) 6 | return ( 7 |
8 | Users: 9 |
    10 | {users.map((user) => ( 11 |
  • 12 | {user.name} - {user.email} 13 |
  • 14 | ))} 15 |
16 |
17 | ) 18 | } 19 | 20 | export default UsersPage 21 | -------------------------------------------------------------------------------- /apps/toolkit-app/pages/auth/signup.tsx: -------------------------------------------------------------------------------- 1 | import { useRouter } from "next/router" 2 | import Layout from "app/core/layouts/Layout" 3 | import { SignupForm } from "app/auth/components/SignupForm" 4 | import { Routes } from "@blitzjs/next" 5 | 6 | const SignupPage = () => { 7 | const router = useRouter() 8 | 9 | return ( 10 | 11 | router.push(Routes.Home())} /> 12 | 13 | ) 14 | } 15 | 16 | export default SignupPage 17 | -------------------------------------------------------------------------------- /apps/toolkit-app/db/seeds.ts: -------------------------------------------------------------------------------- 1 | import db from "./index" 2 | 3 | /* 4 | * This seed function is executed when you run `blitz db seed`. 5 | * 6 | * Probably you want to use a library like https://chancejs.com 7 | * to easily generate realistic data. 8 | */ 9 | const seed = async () => { 10 | await db.$reset() 11 | 12 | for (let i = 0; i < 1; i++) { 13 | await db.user.create({ 14 | data: { 15 | email: "test@test.com", 16 | }, 17 | }) 18 | } 19 | } 20 | 21 | export default seed 22 | -------------------------------------------------------------------------------- /packages/generator/templates/app/pages/auth/signup.tsx: -------------------------------------------------------------------------------- 1 | import { useRouter } from "next/router" 2 | import Layout from "app/core/layouts/Layout" 3 | import { SignupForm } from "app/auth/components/SignupForm" 4 | import { Routes } from "@blitzjs/next" 5 | 6 | const SignupPage = () => { 7 | const router = useRouter() 8 | 9 | return ( 10 | 11 | router.push(Routes.Home())} /> 12 | 13 | ) 14 | } 15 | 16 | export default SignupPage 17 | -------------------------------------------------------------------------------- /apps/web/app/blitz-server.ts: -------------------------------------------------------------------------------- 1 | import {setupBlitzServer} from "@blitzjs/next" 2 | import {AuthServerPlugin, PrismaStorage} from "@blitzjs/auth" 3 | import db from "db" 4 | import {simpleRolesIsAuthorized} from "@blitzjs/auth" 5 | 6 | const {gSSP, gSP, api} = setupBlitzServer({ 7 | plugins: [ 8 | AuthServerPlugin({ 9 | cookiePrefix: "webapp-cookie-prefix", 10 | storage: PrismaStorage(db), 11 | isAuthorized: simpleRolesIsAuthorized, 12 | }), 13 | ], 14 | }) 15 | 16 | export {gSSP, gSP, api} 17 | -------------------------------------------------------------------------------- /packages/generator/templates/form/__ModelName__Form.tsx: -------------------------------------------------------------------------------- 1 | import {Form, FormProps} from "app/core/components/Form" 2 | import {LabeledTextField} from "app/core/components/LabeledTextField" 3 | import {z} from "zod" 4 | export {FORM_ERROR} from "app/core/components/Form" 5 | 6 | export function __ModelName__Form>(props: FormProps) { 7 | return ( 8 | {...props}> 9 | 10 | 11 | ) 12 | } 13 | 14 | -------------------------------------------------------------------------------- /apps/web/app/blitz-client.ts: -------------------------------------------------------------------------------- 1 | import {AuthClientPlugin} from "@blitzjs/auth" 2 | import {setupBlitzClient} from "@blitzjs/next" 3 | import {BlitzRpcPlugin} from "@blitzjs/rpc" 4 | 5 | const {withBlitz} = setupBlitzClient({ 6 | plugins: [ 7 | AuthClientPlugin({ 8 | cookiePrefix: "webapp-cookie-prefix", 9 | }), 10 | BlitzRpcPlugin({ 11 | reactQueryOptions: { 12 | queries: { 13 | staleTime: 7000, 14 | }, 15 | }, 16 | }), 17 | ], 18 | }) 19 | 20 | export {withBlitz} 21 | -------------------------------------------------------------------------------- /packages/generator/templates/app/app/core/layouts/Layout.tsx: -------------------------------------------------------------------------------- 1 | import Head from "next/head" 2 | import React, {FC} from "react" 3 | import {BlitzLayout} from "@blitzjs/next" 4 | 5 | const Layout: BlitzLayout<{title?: string; children?: React.ReactNode}> = ({title, children}) => { 6 | return ( 7 | <> 8 | 9 | {title || "__name__"} 10 | 11 | 12 | 13 | {children} 14 | 15 | ) 16 | } 17 | 18 | export default Layout 19 | -------------------------------------------------------------------------------- /apps/toolkit-app/app/blitz-server.ts: -------------------------------------------------------------------------------- 1 | import { setupBlitzServer } from "@blitzjs/next" 2 | import { AuthServerPlugin, PrismaStorage } from "@blitzjs/auth" 3 | import db from "db" 4 | import { simpleRolesIsAuthorized } from "@blitzjs/auth" 5 | 6 | const { gSSP, gSP, api } = setupBlitzServer({ 7 | plugins: [ 8 | AuthServerPlugin({ 9 | cookiePrefix: "web-cookie-prefix", 10 | storage: PrismaStorage(db), 11 | isAuthorized: simpleRolesIsAuthorized, 12 | }), 13 | ], 14 | }) 15 | 16 | export { gSSP, gSP, api } 17 | -------------------------------------------------------------------------------- /apps/toolkit-app/app/core/layouts/Layout.tsx: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import Head from "next/head" 3 | import { BlitzLayout } from "@blitzjs/next" 4 | 5 | const Layout: BlitzLayout<{ title?: string; children?: React.ReactNode }> = ({ 6 | title, 7 | children, 8 | }) => { 9 | return ( 10 | <> 11 | 12 | {title || "__name__"} 13 | 14 | 15 | 16 | {children} 17 | 18 | ) 19 | } 20 | 21 | export default Layout 22 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/pages/use-query.tsx: -------------------------------------------------------------------------------- 1 | import getBasic from "../app/queries/getBasic" 2 | import {useQuery} from "@blitzjs/rpc" 3 | import {Suspense} from "react" 4 | 5 | function Content() { 6 | const [result] = useQuery(getBasic, undefined) 7 | return
{result}
8 | } 9 | 10 | function Page() { 11 | return ( 12 |
13 | 14 | 15 | 16 |
17 | ) 18 | } 19 | 20 | export default Page 21 | -------------------------------------------------------------------------------- /packages/blitz-rpc/src/data-client/invokeWithCtx.ts: -------------------------------------------------------------------------------- 1 | import {FirstParam, PromiseReturnType, Ctx} from "blitz" 2 | 3 | export function invokeWithCtx any, TInput = FirstParam>( 4 | queryFn: T, 5 | params: TInput, 6 | ctx: Ctx, 7 | ): Promise> { 8 | if (typeof queryFn === "undefined") { 9 | throw new Error( 10 | "invokeWithCtx is missing the first argument - it must be a query or mutation function", 11 | ) 12 | } 13 | 14 | return queryFn(params, ctx) 15 | } 16 | -------------------------------------------------------------------------------- /packages/generator/test/prisma/__snapshots__/model.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Vitest Snapshot v1 2 | 3 | exports[`Prisma Model > generates a proper model 1`] = ` 4 | " 5 | model User { 6 | id Int @id @default(autoincrement()) 7 | createdAt DateTime @default(now()) 8 | updatedAt DateTime @updatedAt 9 | email String @unique 10 | updated DateTime @updatedAt 11 | recentLogins DateTime[] 12 | twoFactorEnabled Boolean 13 | twoFactorMethod String? 14 | } 15 | " 16 | `; 17 | -------------------------------------------------------------------------------- /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.changeset/mean-gorillas-reply.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/auth": patch 3 | "blitz": patch 4 | --- 5 | 6 | Fix a long-standing issue with occasional blitz auth flakiness 7 | 8 | This bug would sometimes cause users to be logged out or to experience an CSRFTokenMismatchError. This bug, when encountered, usually by lots of setPublicData or session.create calls, would not set the cookie headers correctly resulting in cookies being set to a previous state or in a possibly undefined state. 9 | 10 | There are no security concerns as far as I can tell. 11 | -------------------------------------------------------------------------------- /turbo.json: -------------------------------------------------------------------------------- 1 | { 2 | "pipeline": { 3 | "buildapp": { 4 | "dependsOn": ["^build"], 5 | "outputs": ["dist/**", ".next/**"] 6 | }, 7 | "build": { 8 | "dependsOn": ["^build"], 9 | "outputs": ["dist/**", ".next/**"] 10 | }, 11 | "test": { 12 | "outputs": ["coverage/**"], 13 | "dependsOn": ["^build"] 14 | }, 15 | "lint": { 16 | "outputs": [] 17 | }, 18 | "dev": { 19 | "cache": false 20 | }, 21 | "clean": { 22 | "cache": false 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /apps/web/pages/api/get-user.ts: -------------------------------------------------------------------------------- 1 | import {api} from "app/blitz-server" 2 | import db from "db" 3 | 4 | export default api(async (_req, res, ctx) => { 5 | const blitzContext = ctx 6 | 7 | const publicData = blitzContext.session.$publicData 8 | 9 | const sessions = await db.session.findMany({}) 10 | const sessionsCount = await db.session.count({}) 11 | 12 | res.status(200).json({ 13 | userId: blitzContext.session.userId, 14 | publicData: {...publicData}, 15 | activeSessions: sessions, 16 | sessionsCount, 17 | }) 18 | }) 19 | -------------------------------------------------------------------------------- /integration-tests/auth/app/blitz-server.ts: -------------------------------------------------------------------------------- 1 | import {setupBlitzServer} from "@blitzjs/next" 2 | import {AuthServerPlugin, PrismaStorage} from "@blitzjs/auth" 3 | import {simpleRolesIsAuthorized} from "@blitzjs/auth" 4 | import db from "../prisma/index" 5 | 6 | const {gSSP, gSP, api} = setupBlitzServer({ 7 | plugins: [ 8 | AuthServerPlugin({ 9 | cookiePrefix: "auth-tests-cookie-prefix", 10 | storage: PrismaStorage(db), 11 | isAuthorized: simpleRolesIsAuthorized, 12 | }), 13 | ], 14 | }) 15 | 16 | export {gSSP, gSP, api} 17 | -------------------------------------------------------------------------------- /packages/generator/templates/app/app/blitz-server.ts: -------------------------------------------------------------------------------- 1 | import { setupBlitzServer } from "@blitzjs/next" 2 | import { AuthServerPlugin, PrismaStorage } from "@blitzjs/auth" 3 | import { simpleRolesIsAuthorized } from "@blitzjs/auth" 4 | import db from "db" 5 | import { authConfig } from "./blitz-client" 6 | 7 | export const { gSSP, gSP, api } = setupBlitzServer({ 8 | plugins: [ 9 | AuthServerPlugin({ 10 | ...authConfig, 11 | storage: PrismaStorage(db), 12 | isAuthorized: simpleRolesIsAuthorized, 13 | }), 14 | ], 15 | }) 16 | 17 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/pages/use-query.tsx: -------------------------------------------------------------------------------- 1 | import getBasic from "../app/queries/getBasic" 2 | import {useQuery} from "@blitzjs/rpc" 3 | import React from "react" 4 | 5 | function Content() { 6 | const [result, {isFetching}] = useQuery(getBasic, undefined) 7 | 8 | if (isFetching) { 9 | return <>Loading... 10 | } else { 11 | return
{result}
12 | } 13 | } 14 | 15 | function Page() { 16 | return ( 17 |
18 | 19 |
20 | ) 21 | } 22 | 23 | export default Page 24 | -------------------------------------------------------------------------------- /integration-tests/trailing-slash/app/blitz-server.ts: -------------------------------------------------------------------------------- 1 | import {setupBlitzServer} from "@blitzjs/next" 2 | import {AuthServerPlugin, PrismaStorage} from "@blitzjs/auth" 3 | import {simpleRolesIsAuthorized} from "@blitzjs/auth" 4 | import db from "../db" 5 | 6 | const {gSSP, gSP, api} = setupBlitzServer({ 7 | plugins: [ 8 | AuthServerPlugin({ 9 | cookiePrefix: "trailing-slash-tests-cookie-prefix", 10 | storage: PrismaStorage(db), 11 | isAuthorized: simpleRolesIsAuthorized, 12 | }), 13 | ], 14 | }) 15 | 16 | export {gSSP, gSP, api} 17 | -------------------------------------------------------------------------------- /integration-tests/no-suspense/app/blitz-server.ts: -------------------------------------------------------------------------------- 1 | import {setupBlitzServer} from "@blitzjs/next" 2 | import {AuthServerPlugin, PrismaStorage} from "@blitzjs/auth" 3 | import {simpleRolesIsAuthorized} from "@blitzjs/auth" 4 | import db from "../prisma/index" 5 | 6 | const {gSSP, gSP, api} = setupBlitzServer({ 7 | plugins: [ 8 | AuthServerPlugin({ 9 | cookiePrefix: "no-suspense-tests-cookie-prefix", 10 | storage: PrismaStorage(db), 11 | isAuthorized: simpleRolesIsAuthorized, 12 | }), 13 | ], 14 | }) 15 | 16 | export {gSSP, gSP, api} 17 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/app/blitz-server.ts: -------------------------------------------------------------------------------- 1 | import {setupBlitzServer} from "@blitzjs/next" 2 | import {AuthServerPlugin, PrismaStorage} from "@blitzjs/auth" 3 | import {simpleRolesIsAuthorized} from "@blitzjs/auth" 4 | import db from "../db" 5 | 6 | const {gSSP, gSP, api} = setupBlitzServer({ 7 | plugins: [ 8 | AuthServerPlugin({ 9 | cookiePrefix: "react-query-utils-tests-cookie-prefix", 10 | storage: PrismaStorage(db), 11 | isAuthorized: simpleRolesIsAuthorized, 12 | }), 13 | ], 14 | }) 15 | 16 | export {gSSP, gSP, api} 17 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/pages/index.test.tsx: -------------------------------------------------------------------------------- 1 | import { render } from "test/utils" 2 | 3 | import Home from "./index" 4 | 5 | test.skip("renders blitz documentation link", () => { 6 | // This is an example of how to ensure a specific item is in the document 7 | // But it's disabled by default (by test.skip) so the test doesn't fail 8 | // when you remove the the default content from the page 9 | 10 | const { getByText } = render() 11 | const linkElement = getByText(/Documentation/i) 12 | expect(linkElement).toBeInTheDocument() 13 | }) 14 | -------------------------------------------------------------------------------- /packages/generator/templates/mutations/delete__ModelName__.ts: -------------------------------------------------------------------------------- 1 | import { resolver } from "@blitzjs/rpc" 2 | import db from "db" 3 | import {z} from "zod" 4 | 5 | const Delete__ModelName__ = z.object({ 6 | id: z.number(), 7 | }) 8 | 9 | export default resolver.pipe( 10 | resolver.zod(Delete__ModelName__), 11 | resolver.authorize(), 12 | async ({id}) => { 13 | // TODO: in multi-tenant app, you must add validation to ensure correct tenant 14 | const __modelName__ = await db.__modelName__.deleteMany({where: {id}}) 15 | 16 | return __modelName__ 17 | }, 18 | ) -------------------------------------------------------------------------------- /packages/blitz/src/cli/utils/helpers.ts: -------------------------------------------------------------------------------- 1 | import {readdirSync, existsSync} from "fs-extra" 2 | import {join} from "path" 3 | 4 | export function getPkgManager() { 5 | return readdirSync(process.cwd()).includes("pnpm-lock.yaml") 6 | ? "pnpm" 7 | : readdirSync(process.cwd()).includes("yarn-lock.yaml") 8 | ? "yarn" 9 | : "npm" 10 | } 11 | 12 | export const isInternalBlitzMonorepoDevelopment = 13 | existsSync(join(process.cwd(), "..", "..", "packages", "blitz", "dist", "chunks")) && 14 | existsSync(join(process.cwd(), "..", "..", "packages", "blitz-next", "dist", "chunks")) 15 | -------------------------------------------------------------------------------- /apps/toolkit-app/pages/auth/login.tsx: -------------------------------------------------------------------------------- 1 | import Layout from "app/core/layouts/Layout" 2 | import { LoginForm } from "app/auth/components/LoginForm" 3 | import { useRouter } from "next/router" 4 | 5 | const LoginPage = () => { 6 | const router = useRouter() 7 | 8 | return ( 9 | 10 | { 12 | const next = router.query.next ? decodeURIComponent(router.query.next as string) : "/" 13 | return router.push(next) 14 | }} 15 | /> 16 | 17 | ) 18 | } 19 | 20 | export default LoginPage 21 | -------------------------------------------------------------------------------- /apps/web/pages/api/multiply.ts: -------------------------------------------------------------------------------- 1 | import {NextApiRequest, NextApiResponse} from "next" 2 | import db from "db" 3 | 4 | export default async function handle(req: NextApiRequest, res: NextApiResponse) { 5 | const session = await db.session.findFirst({ 6 | where: { 7 | handle: "test", 8 | }, 9 | }) 10 | 11 | const isAuthorized = !!session 12 | 13 | if (!isAuthorized) { 14 | res.status(404).json({message: "No access"}) 15 | return 16 | } 17 | 18 | const x = parseInt(req.query.x as string) 19 | const y = parseInt(req.query.y as string) 20 | res.json({result: x * y}) 21 | } 22 | -------------------------------------------------------------------------------- /packages/blitz/src/cli/commands/prisma.ts: -------------------------------------------------------------------------------- 1 | import {CliCommand} from "../index" 2 | import arg from "arg" 3 | import {runPrisma} from "../../utils/run-prisma" 4 | 5 | export const runPrismaExitOnError = async (...args: Parameters) => { 6 | const result = await runPrisma(...args) 7 | 8 | if (!result.success) { 9 | process.exit(1) 10 | } 11 | } 12 | 13 | const prisma: CliCommand = async () => { 14 | const args = arg( 15 | {}, 16 | { 17 | permissive: true, 18 | }, 19 | ) 20 | 21 | await runPrismaExitOnError(args._.slice(1)) 22 | } 23 | 24 | export {prisma} 25 | -------------------------------------------------------------------------------- /packages/generator/templates/mutations/update__ModelName__.ts: -------------------------------------------------------------------------------- 1 | import { resolver } from "@blitzjs/rpc" 2 | import db from "db" 3 | import {z} from "zod" 4 | 5 | const Update__ModelName__ = z.object({ 6 | id: z.number(), 7 | name: z.string(), 8 | }) 9 | 10 | export default resolver.pipe( 11 | resolver.zod(Update__ModelName__), 12 | resolver.authorize(), 13 | async ({id, ... data}) => { 14 | // TODO: in multi-tenant app, you must add validation to ensure correct tenant 15 | const __modelName__ = await db.__modelName__.update({where: {id}, data}) 16 | 17 | return __modelName__ 18 | }, 19 | ) -------------------------------------------------------------------------------- /.changeset/sour-lemons-hunt.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@blitzjs/auth": patch 3 | "blitz": patch 4 | --- 5 | 6 | Fix auth issue where session token and publicData cookie were updated unnecessarily, leading to potential user logout 7 | 8 | - Previously, we were updating the session token each time public data changed. This is not needed, and it would cause race condition bugs where a user could be unexpectedly logged out because a request already in flight would not match the new session token. 9 | - Previously, we were updating the publicData cookie even when it hadn't changed. This may reduce unnecessary re-renders on the client. 10 | -------------------------------------------------------------------------------- /packages/blitz/src/cli/commands/next/build.ts: -------------------------------------------------------------------------------- 1 | import arg from "arg" 2 | import {CliCommand} from "../../index" 3 | import {ServerConfig} from "../../utils/config" 4 | 5 | const build: CliCommand = async () => { 6 | const nextArgs = arg( 7 | { 8 | "--inspect": Boolean, 9 | }, 10 | { 11 | permissive: true, 12 | }, 13 | ) 14 | 15 | const config: ServerConfig = { 16 | rootFolder: process.cwd(), 17 | inspect: nextArgs["--inspect"], 18 | env: "prod", 19 | } 20 | 21 | await import("../../utils/next-commands").then((i) => i.build(config)) 22 | } 23 | 24 | export {build} 25 | -------------------------------------------------------------------------------- /packages/blitz-rpc/build.config.ts: -------------------------------------------------------------------------------- 1 | import {BuildConfig} from "unbuild" 2 | 3 | const config: BuildConfig = { 4 | entries: [ 5 | "./src/index-browser", 6 | "./src/index-server", 7 | "./src/loader-server", 8 | "./src/loader-server-resolvers", 9 | "./src/loader-client", 10 | ], 11 | externals: [ 12 | "index-browser.cjs", 13 | "index-browser.mjs", 14 | "index-server.cjs", 15 | "index-server.mjs", 16 | "react", 17 | "blitz", 18 | "next", 19 | "zod", 20 | ], 21 | declaration: true, 22 | rollup: { 23 | emitCJS: true, 24 | }, 25 | } 26 | export default config 27 | -------------------------------------------------------------------------------- /packages/generator/templates/app/pages/auth/login.tsx: -------------------------------------------------------------------------------- 1 | import Layout from "app/core/layouts/Layout" 2 | import { LoginForm } from "app/auth/components/LoginForm" 3 | import { useRouter } from "next/router" 4 | 5 | const LoginPage = () => { 6 | const router = useRouter() 7 | 8 | return ( 9 | 10 | { 12 | const next = router.query.next ? decodeURIComponent(router.query.next as string) : "/" 13 | return router.push(next) 14 | }} 15 | /> 16 | 17 | ) 18 | } 19 | 20 | export default LoginPage 21 | -------------------------------------------------------------------------------- /packages/blitz-rpc/src/data-client/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./rpc" 2 | export {useQuery, usePaginatedQuery, useInfiniteQuery, useMutation} from "./react-query" 3 | export type {MutateFunction} from "./react-query" 4 | export { 5 | getQueryKey, 6 | getInfiniteQueryKey, 7 | invalidateQuery, 8 | setQueryData, 9 | getQueryClient, 10 | getQueryData, 11 | } from "./react-query-utils" 12 | export { 13 | useQueryErrorResetBoundary, 14 | QueryClientProvider, 15 | QueryClient, 16 | dehydrate, 17 | } from "@tanstack/react-query" 18 | export {invoke} from "./invoke" 19 | export {invokeWithCtx} from "./invokeWithCtx" 20 | -------------------------------------------------------------------------------- /packages/generator/src/utils/get-blitz-dependency-version.ts: -------------------------------------------------------------------------------- 1 | import {logFailedVersionFetch} from "./get-latest-version" 2 | import {fetchDistTags} from "./npm-fetch" 3 | 4 | const CURRENT_BLITZ_TAG = "latest" 5 | 6 | export const getBlitzDependencyVersion = async () => { 7 | try { 8 | const result = await fetchDistTags("blitz") 9 | 10 | if (CURRENT_BLITZ_TAG in result) { 11 | return {value: result[CURRENT_BLITZ_TAG]} 12 | } 13 | 14 | logFailedVersionFetch("blitz") 15 | return {value: ""} 16 | } catch (error) { 17 | logFailedVersionFetch("blitz") 18 | return {value: ""} 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/generator/templates/app/pages/_document.tsx: -------------------------------------------------------------------------------- 1 | import Document, { Html, Main, NextScript, Head } from 'next/document'; 2 | 3 | class MyDocument extends Document { 4 | // Only uncomment if you need to customize this behaviour 5 | // static async getInitialProps(ctx: DocumentContext) { 6 | // const initialProps = await Document.getInitialProps(ctx) 7 | // return {...initialProps} 8 | // } 9 | render() { 10 | return ( 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | ); 19 | } 20 | } 21 | 22 | export default MyDocument; 23 | -------------------------------------------------------------------------------- /apps/web/pages/api/set-public-data.ts: -------------------------------------------------------------------------------- 1 | import {setPublicDataForUser} from "@blitzjs/auth" 2 | import {api} from "app/blitz-server" 3 | import db from "db" 4 | 5 | export default api(async (req, res, ctx) => { 6 | if (ctx.session.$thisIsAuthorized()) { 7 | ctx.session.$publicData 8 | 9 | await db.user.update({ 10 | where: {id: ctx.session.userId as number}, 11 | data: {role: req.query.role as string}, 12 | }) 13 | await setPublicDataForUser(ctx.session.userId, {role: req.query.role as string}) 14 | } 15 | 16 | res.status(200).json({userId: ctx.session.userId, role: req.query.role as string}) 17 | }) 18 | -------------------------------------------------------------------------------- /integration-tests/rpc/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": false, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "incremental": true, 11 | "esModuleInterop": true, 12 | "module": "esnext", 13 | "moduleResolution": "node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "jsx": "preserve" 17 | }, 18 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "types"], 19 | "exclude": ["node_modules"] 20 | } 21 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/pages/_document.tsx: -------------------------------------------------------------------------------- 1 | import Document, { Html, Main, NextScript, Head } from 'next/document'; 2 | 3 | class MyDocument extends Document { 4 | // Only uncomment if you need to customize this behaviour 5 | // static async getInitialProps(ctx: DocumentContext) { 6 | // const initialProps = await Document.getInitialProps(ctx) 7 | // return {...initialProps} 8 | // } 9 | render() { 10 | return ( 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | ); 19 | } 20 | } 21 | 22 | export default MyDocument; 23 | -------------------------------------------------------------------------------- /apps/toolkit-app/pages/_document.tsx: -------------------------------------------------------------------------------- 1 | import Document, { Html, Main, NextScript, Head } from "next/document" 2 | 3 | class MyDocument extends Document { 4 | // Only uncomment if you need to customize this behaviour 5 | // static async getInitialProps(ctx: DocumentContext) { 6 | // const initialProps = await Document.getInitialProps(ctx) 7 | // return {...initialProps} 8 | // } 9 | render() { 10 | return ( 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | ) 19 | } 20 | } 21 | 22 | export default MyDocument 23 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-gssp.tsx: -------------------------------------------------------------------------------- 1 | import {SessionContext} from "@blitzjs/auth" 2 | import {gSSP} from "app/blitz-server" 3 | 4 | type Props = { 5 | userId: unknown 6 | publicData: SessionContext["$publicData"] 7 | } 8 | 9 | export const getServerSideProps = gSSP(async ({ctx}) => { 10 | const {session} = ctx 11 | return { 12 | props: { 13 | userId: session.userId, 14 | publicData: session.$publicData, 15 | publishedAt: new Date(0), 16 | }, 17 | } 18 | }) 19 | 20 | function PageWithGssp(props: Props) { 21 | return
{JSON.stringify(props, null, 2)}
22 | } 23 | 24 | export default PageWithGssp 25 | -------------------------------------------------------------------------------- /apps/toolkit-app/pages/404.tsx: -------------------------------------------------------------------------------- 1 | import Head from "next/head" 2 | import { ErrorComponent } from "@blitzjs/next" 3 | 4 | // ------------------------------------------------------ 5 | // This page is rendered if a route match is not found 6 | // ------------------------------------------------------ 7 | export default function Page404() { 8 | const statusCode = 404 9 | const title = "This page could not be found" 10 | return ( 11 | <> 12 | 13 | 14 | {statusCode}: {title} 15 | 16 | 17 | 18 | 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /packages/generator/templates/app/pages/404.tsx: -------------------------------------------------------------------------------- 1 | import Head from 'next/head' 2 | import {ErrorComponent} from "@blitzjs/next" 3 | 4 | // ------------------------------------------------------ 5 | // This page is rendered if a route match is not found 6 | // ------------------------------------------------------ 7 | export default function Page404() { 8 | const statusCode = 404 9 | const title = "This page could not be found" 10 | return ( 11 | <> 12 | 13 | 14 | {statusCode}: {title} 15 | 16 | 17 | 18 | 19 | ) 20 | } -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/pages/404.tsx: -------------------------------------------------------------------------------- 1 | import ErrorComponent from "next/error" 2 | import Head from "next/head" 3 | 4 | // ------------------------------------------------------ 5 | // This page is rendered if a route match is not found 6 | // ------------------------------------------------------ 7 | export default function Page404() { 8 | const statusCode = 404 9 | const title = "This page could not be found" 10 | return ( 11 | <> 12 | 13 | 14 | {statusCode}: {title} 15 | 16 | 17 | 18 | 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /packages/generator/src/utils/get-template-root.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs" 2 | import * as path from "path" 3 | import {SourceRootType} from "../generator.js" 4 | 5 | export const getTemplateRoot = ( 6 | templateDir: string | undefined, 7 | fallback: SourceRootType, 8 | ): SourceRootType => { 9 | if (!templateDir) { 10 | return fallback 11 | } 12 | const templatePath = path.join(templateDir, fallback.path) 13 | if (!fs.existsSync(templatePath)) { 14 | console.info( 15 | `Template path "${templatePath}" does not exist. Falling back to the default template.`, 16 | ) 17 | return fallback 18 | } 19 | 20 | return {path: templatePath, type: "absolute"} 21 | } 22 | -------------------------------------------------------------------------------- /packages/config/tsconfig.nextjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Next.js", 4 | "extends": "./tsconfig.base.json", 5 | "compilerOptions": { 6 | "target": "es5", 7 | "lib": ["dom", "dom.iterable", "esnext"], 8 | "allowJs": true, 9 | "skipLibCheck": true, 10 | "strict": false, 11 | "forceConsistentCasingInFileNames": true, 12 | "noEmit": true, 13 | "incremental": true, 14 | "esModuleInterop": true, 15 | "module": "esnext", 16 | "resolveJsonModule": true, 17 | "isolatedModules": true, 18 | "jsx": "preserve" 19 | }, 20 | "include": ["src", "next-env.d.ts"], 21 | "exclude": ["node_modules"] 22 | } 23 | -------------------------------------------------------------------------------- /packages/generator/test/prisma/model.test.ts: -------------------------------------------------------------------------------- 1 | import {describe, expect, it} from "vitest" 2 | import {Field} from "../../src/prisma/field" 3 | import {Model} from "../../src/prisma/model" 4 | 5 | describe("Prisma Model", () => { 6 | it("generates a proper model", () => { 7 | expect( 8 | new Model( 9 | "user", 10 | [ 11 | Field.parse("email:string:unique"), 12 | Field.parse("updated:dateTime:updatedAt"), 13 | Field.parse("recentLogins:dateTime[]"), 14 | Field.parse("twoFactorEnabled:boolean"), 15 | Field.parse("twoFactorMethod:string?"), 16 | ].flat(), 17 | ).toString(), 18 | ).toMatchSnapshot() 19 | }) 20 | }) 21 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import { ErrorFallbackProps, ErrorComponent, ErrorBoundary, AppProps } from "@blitzjs/next" 2 | import React from "react" 3 | import { withBlitz } from "app/blitz-client" 4 | 5 | function RootErrorFallback({ error }: ErrorFallbackProps) { 6 | return ( 7 | 11 | ) 12 | } 13 | 14 | function MyApp({ Component, pageProps }: AppProps) { 15 | return ( 16 | 17 | 18 | 19 | ) 20 | } 21 | 22 | export default withBlitz(MyApp) 23 | -------------------------------------------------------------------------------- /integration-tests/qm/test/__snapshots__/use-mutation.test.tsx.snap: -------------------------------------------------------------------------------- 1 | // Vitest Snapshot v1 2 | 3 | exports[`useMutation > useMutation calls the resolver with the argument > shouldn't work with query function 1`] = `"\\"useMutation\\" was expected to be called with a mutation but was called with a \\"query\\""`; 4 | 5 | exports[`useMutation > useMutation calls the resolver with the argument > shouldn't work with regular functions 1`] = `"Either the file path to your resolver is incorrect (must be in a \\"queries\\" or \\"mutations\\" folder that isn't nested inside \\"pages\\" or \\"api\\") or you are trying to use Blitz's useQuery to fetch from third-party APIs (to do that, import useQuery directly from \\"@tanstack/react-query\\")."`; 6 | -------------------------------------------------------------------------------- /packages/generator/templates/app/app/auth/mutations/signup.ts: -------------------------------------------------------------------------------- 1 | import { SecurePassword } from "@blitzjs/auth" 2 | import { resolver } from "@blitzjs/rpc" 3 | import db from "db" 4 | import { Role } from "types" 5 | import { Signup } from "../validations" 6 | 7 | export default resolver.pipe(resolver.zod(Signup), async ({ email, password }, ctx) => { 8 | const hashedPassword = await SecurePassword.hash(password.trim()) 9 | const user = await db.user.create({ 10 | data: { email: email.toLowerCase().trim(), hashedPassword, role: "USER" }, 11 | select: { id: true, name: true, email: true, role: true }, 12 | }) 13 | 14 | await ctx.session.$create({ userId: user.id, role: user.role as Role }) 15 | return user 16 | }) 17 | -------------------------------------------------------------------------------- /integration-tests/qm/test/__snapshots__/use-query.test.tsx.snap: -------------------------------------------------------------------------------- 1 | // Vitest Snapshot v1 2 | 3 | exports[`useQuery > a "query" that converts the string parameter to uppercase > shouldn't work with mutation function 1`] = `"\\"useQuery\\" was expected to be called with a query but was called with a \\"mutation\\""`; 4 | 5 | exports[`useQuery > a "query" that converts the string parameter to uppercase > shouldn't work with regular functions 1`] = `"Either the file path to your resolver is incorrect (must be in a \\"queries\\" or \\"mutations\\" folder that isn't nested inside \\"pages\\" or \\"api\\") or you are trying to use Blitz's useQuery to fetch from third-party APIs (to do that, import useQuery directly from \\"@tanstack/react-query\\")."`; 6 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-get-query-data.tsx: -------------------------------------------------------------------------------- 1 | import {getQueryData, useQuery} from "@blitzjs/rpc" 2 | import getBasic from "../app/queries/getBasic" 3 | import {useState} from "react" 4 | 5 | function PageWithGetQueryData() { 6 | const [data] = useQuery(getBasic, {}) 7 | const [newData, setNewData] = useState() 8 | return ( 9 |
10 |
{data}
11 | {newData &&
{newData}
} 12 | 20 |
21 | ) 22 | } 23 | 24 | export default PageWithGetQueryData 25 | -------------------------------------------------------------------------------- /packages/blitz-rpc/test/blitz-test-utils.ts: -------------------------------------------------------------------------------- 1 | // This enhance fn does what buildRpcFunction does during build time 2 | export function buildQueryRpc(fn: any) { 3 | const newFn = (...args: any) => { 4 | const [data, ...rest] = args 5 | return fn(data, ...rest) 6 | } 7 | newFn._isRpcClient = true 8 | newFn._resolverType = "query" 9 | newFn._routePath = "/api/test/url/" + Math.random() 10 | return newFn 11 | } 12 | 13 | // This enhance fn does what buildRpcFunction does during build time 14 | export function buildMutationRpc(fn: any) { 15 | const newFn = (...args: any) => fn(...args) 16 | newFn._isRpcClient = true 17 | newFn._resolverType = "mutation" 18 | newFn._routePath = "/api/test/url" 19 | return newFn 20 | } 21 | -------------------------------------------------------------------------------- /packages/generator/templates/mutations/create__ModelName__.ts: -------------------------------------------------------------------------------- 1 | import { resolver } from "@blitzjs/rpc" 2 | import db from "db" 3 | import {z} from "zod" 4 | 5 | if (process.env.parentModel) { 6 | const Create__ModelName__ = z.object({ 7 | name: z.string(), 8 | __parentModelId__: z.number() 9 | }) 10 | } else { 11 | const Create__ModelName__ = z.object({ 12 | name: z.string(), 13 | }) 14 | } 15 | 16 | export default resolver.pipe( 17 | resolver.zod(Create__ModelName__), 18 | resolver.authorize(), 19 | async (input) => { 20 | // TODO: in multi-tenant app, you must add validation to ensure correct tenant 21 | const __modelName__ = await db.__modelName__.create({data: input}) 22 | 23 | return __modelName__ 24 | }, 25 | ) -------------------------------------------------------------------------------- /packages/blitz-rpc/src/data-client/invoke.ts: -------------------------------------------------------------------------------- 1 | import {FirstParam, PromiseReturnType, isClient} from "blitz" 2 | import {RpcClient} from "./rpc" 3 | 4 | export function invoke any, TInput = FirstParam>( 5 | queryFn: T, 6 | params: TInput, 7 | ): Promise> { 8 | if (typeof queryFn === "undefined") { 9 | throw new Error( 10 | "invoke is missing the first argument - it must be a query or mutation function", 11 | ) 12 | } 13 | 14 | if (isClient) { 15 | const fn = queryFn as unknown as RpcClient 16 | return fn(params, {fromInvoke: true}) as ReturnType 17 | } else { 18 | const fn = queryFn as unknown as RpcClient 19 | return fn(params) as ReturnType 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /apps/web/app/queries/getInfiniteUsers.ts: -------------------------------------------------------------------------------- 1 | import {resolver} from "@blitzjs/rpc" 2 | import {paginate} from "blitz" 3 | import db, {Prisma} from "db" 4 | 5 | interface GetUsersInput 6 | extends Pick {} 7 | 8 | export default resolver.pipe(async ({where, orderBy, skip = 0, take = 100}: GetUsersInput) => { 9 | const { 10 | items: users, 11 | hasMore, 12 | nextPage, 13 | count, 14 | } = await paginate({ 15 | skip, 16 | take, 17 | count: () => db.user.count({where}), 18 | query: (paginateArgs) => db.user.findMany({...paginateArgs, where, orderBy}), 19 | }) 20 | 21 | return { 22 | users, 23 | nextPage, 24 | hasMore, 25 | count, 26 | } 27 | }) 28 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Default", 4 | "compilerOptions": { 5 | "composite": false, 6 | "declaration": true, 7 | "declarationMap": true, 8 | "esModuleInterop": true, 9 | "forceConsistentCasingInFileNames": true, 10 | "inlineSources": false, 11 | "isolatedModules": true, 12 | "moduleResolution": "node", 13 | "noUnusedLocals": false, 14 | "noUnusedParameters": false, 15 | "noUncheckedIndexedAccess": true, 16 | "preserveWatchOutput": true, 17 | "skipLibCheck": true, 18 | "strict": true, 19 | "strictNullChecks": true, 20 | "incremental": true, 21 | "tsBuildInfoFile": ".tsbuildinfo" 22 | }, 23 | "exclude": ["node_modules"] 24 | } 25 | -------------------------------------------------------------------------------- /packages/generator/templates/queries/get__ModelName__.ts: -------------------------------------------------------------------------------- 1 | import {NotFoundError} from "blitz" 2 | import { resolver } from "@blitzjs/rpc" 3 | import db from "db" 4 | import {z} from "zod" 5 | 6 | const Get__ModelName__ = z.object({ 7 | // This accepts type of undefined, but is required at runtime 8 | id: z.number().optional().refine(Boolean, 'Required'), 9 | }) 10 | 11 | export default resolver.pipe( 12 | resolver.zod(Get__ModelName__), 13 | resolver.authorize(), 14 | async ({ id }) => { 15 | // TODO: in multi-tenant app, you must add validation to ensure correct tenant 16 | const __modelName__ = await db.__modelName__.findFirst({where: {id}}) 17 | 18 | if (!__modelName__) throw new NotFoundError() 19 | 20 | return __modelName__ 21 | } 22 | ) -------------------------------------------------------------------------------- /apps/web/pages/page-with-gssp-redirect.tsx: -------------------------------------------------------------------------------- 1 | import {SessionContext} from "@blitzjs/auth" 2 | import {Routes} from "@blitzjs/next" 3 | import {gSSP} from "app/blitz-server" 4 | 5 | type Props = { 6 | userId: unknown 7 | publicData: SessionContext["$publicData"] 8 | } 9 | 10 | export const getServerSideProps = gSSP(async ({ctx}) => { 11 | const {session} = ctx 12 | 13 | return { 14 | redirect: {destination: Routes.Post({postId: "1"})}, 15 | props: { 16 | userId: session.userId, 17 | publicData: session.$publicData, 18 | publishedAt: new Date(0), 19 | }, 20 | } 21 | }) 22 | 23 | function PageWithGsspRedirect(props: Props) { 24 | return
{JSON.stringify(props, null, 2)}
25 | } 26 | 27 | export default PageWithGsspRedirect 28 | -------------------------------------------------------------------------------- /packages/config/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Default", 4 | "compilerOptions": { 5 | "composite": false, 6 | "declaration": true, 7 | "declarationMap": true, 8 | "esModuleInterop": true, 9 | "forceConsistentCasingInFileNames": true, 10 | "inlineSources": false, 11 | "isolatedModules": true, 12 | "moduleResolution": "node", 13 | "noUnusedLocals": false, 14 | "noUnusedParameters": false, 15 | "noUncheckedIndexedAccess": true, 16 | "preserveWatchOutput": true, 17 | "skipLibCheck": true, 18 | "strict": true, 19 | "strictNullChecks": true, 20 | "incremental": true, 21 | "tsBuildInfoFile": ".tsbuildinfo" 22 | }, 23 | "exclude": ["node_modules"] 24 | } 25 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-prefetch.tsx: -------------------------------------------------------------------------------- 1 | import {useQuery} from "@blitzjs/rpc" 2 | import {gSSP} from "app/blitz-server" 3 | import getUsers from "app/queries/getUsers" 4 | 5 | export const getServerSideProps = gSSP(async ({ctx}) => { 6 | const {prefetchQuery} = ctx 7 | 8 | await prefetchQuery(getUsers, {}, {}) 9 | return {props: {}} 10 | }) 11 | 12 | function PageWithPrefetch(props) { 13 | const [users] = useQuery(getUsers, {}) 14 | return ( 15 |
16 | {users.map((u) => ( 17 |
18 |

name: {u.name}

19 |

role: {u.role}

20 |

email: {u.email}

21 |
22 |
23 | ))} 24 |
25 | ) 26 | } 27 | 28 | export default PageWithPrefetch 29 | -------------------------------------------------------------------------------- /apps/toolkit-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "baseUrl": ".", 6 | "allowJs": true, 7 | "skipLibCheck": true, 8 | "strict": false, 9 | "strictNullChecks": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "noEmit": true, 12 | "noUncheckedIndexedAccess": true, 13 | "esModuleInterop": true, 14 | "module": "esnext", 15 | "moduleResolution": "node", 16 | "resolveJsonModule": true, 17 | "isolatedModules": true, 18 | "jsx": "preserve", 19 | "incremental": true, 20 | "tsBuildInfoFile": ".tsbuildinfo" 21 | }, 22 | "exclude": ["node_modules", "**/*.e2e.ts", "cypress"], 23 | "include": ["blitz-env.d.ts", "**/*.ts", "**/*.tsx", "types"] 24 | } 25 | -------------------------------------------------------------------------------- /apps/toolkit-app/app/auth/mutations/signup.ts: -------------------------------------------------------------------------------- 1 | import db from "db" 2 | import { SecurePassword } from "@blitzjs/auth" 3 | import { Role } from "types" 4 | 5 | export default async function signup(input, ctx) { 6 | const blitzContext = ctx 7 | 8 | const hashedPassword = await SecurePassword.hash((input.password as string) || "test-password") 9 | const email = (input.email as string) || "test" + Math.random() + "@test.com" 10 | const user = await db.user.create({ 11 | data: { email, hashedPassword, role: "user" }, 12 | select: { id: true, name: true, email: true, role: true }, 13 | }) 14 | 15 | await blitzContext.session.$create({ 16 | userId: user.id, 17 | role: user.role as Role, 18 | }) 19 | 20 | return { userId: blitzContext.session.userId, ...user, email: input.email } 21 | } 22 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "baseUrl": ".", 6 | "allowJs": true, 7 | "skipLibCheck": true, 8 | "strict": false, 9 | "strictNullChecks": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "noEmit": true, 12 | "noUncheckedIndexedAccess": true, 13 | "esModuleInterop": true, 14 | "module": "esnext", 15 | "moduleResolution": "node", 16 | "resolveJsonModule": true, 17 | "isolatedModules": true, 18 | "jsx": "preserve", 19 | "incremental": true, 20 | "tsBuildInfoFile": ".tsbuildinfo" 21 | }, 22 | "exclude": ["node_modules", "**/*.e2e.ts", "cypress"], 23 | "include": ["blitz-env.d.ts", "**/*.ts", "**/*.tsx"] 24 | } 25 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | Closes: ? 9 | 10 | ### What are the changes and their implications? 11 | 12 | ## Bug Checklist 13 | 14 | - [ ] Integration test added (see [test docs](https://blitzjs.com/docs/contributing#running-tests) if needed) 15 | 16 | ## Feature Checklist 17 | 18 | - [ ] Integration test added (see [test docs](https://blitzjs.com/docs/contributing#running-tests) if needed) 19 | - [ ] Documentation added/updated (submit PR to [blitzjs.com repo `canary` branch](https://github.com/blitz-js/blitzjs.com/tree/canary)) 20 | -------------------------------------------------------------------------------- /packages/blitz/src/utils/run-prisma.ts: -------------------------------------------------------------------------------- 1 | import which from "npm-which" 2 | import pEvent from "p-event" 3 | import {Readable} from "stream" 4 | import {spawn} from "cross-spawn" 5 | 6 | export const runPrisma = async (args: string[], silent = false) => { 7 | const prismaBin = which(process.cwd()).sync("prisma") 8 | 9 | const cp = spawn(prismaBin, args, { 10 | stdio: silent ? "pipe" : "inherit", 11 | env: process.env, 12 | }) 13 | 14 | const cp_stderr: string[] = [] 15 | if (silent) { 16 | cp?.stderr?.on("data", (chunk: Readable) => { 17 | cp_stderr.push(chunk.toString()) 18 | }) 19 | } 20 | 21 | const code = await pEvent(cp, "exit", {rejectionEvents: []}) 22 | 23 | return { 24 | success: code === 0, 25 | stderr: silent ? cp_stderr.join("") : undefined, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/generator/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./generators/app-generator" 2 | export * from "./generators/model-generator" 3 | export * from "./generators/mutations-generator" 4 | export * from "./generators/mutation-generator" 5 | export * from "./generators/page-generator" 6 | export * from "./generators/queries-generator" 7 | export * from "./generators/query-generator" 8 | export * from "./generators/form-generator" 9 | export * from "./generator" 10 | export * from "./conflict-checker" 11 | export {getLatestVersion} from "./utils/get-latest-version" 12 | export * from "./utils/npm-fetch" 13 | export * from "./utils/get-blitz-dependency-version" 14 | export { 15 | singleCamel, 16 | singlePascal, 17 | pluralCamel, 18 | pluralPascal, 19 | capitalize, 20 | uncapitalize, 21 | } from "./utils/inflector" 22 | -------------------------------------------------------------------------------- /packages/generator/templates/app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "baseUrl": ".", 6 | "allowJs": true, 7 | "skipLibCheck": true, 8 | "strict": false, 9 | "strictNullChecks": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "noEmit": true, 12 | "noUncheckedIndexedAccess": true, 13 | "esModuleInterop": true, 14 | "module": "esnext", 15 | "moduleResolution": "node", 16 | "resolveJsonModule": true, 17 | "isolatedModules": true, 18 | "jsx": "preserve", 19 | "incremental": true, 20 | "tsBuildInfoFile": ".tsbuildinfo" 21 | }, 22 | "exclude": ["node_modules", "**/*.e2e.ts", "cypress"], 23 | "include": ["blitz-env.d.ts", "**/*.ts", "**/*.tsx", "types"] 24 | } 25 | -------------------------------------------------------------------------------- /apps/web/pages/api/signup.ts: -------------------------------------------------------------------------------- 1 | import {api} from "app/blitz-server" 2 | import db from "db" 3 | import {SecurePassword} from "@blitzjs/auth" 4 | 5 | export default api(async (req, res, ctx) => { 6 | const blitzContext = ctx 7 | 8 | const hashedPassword = await SecurePassword.hash( 9 | (req.query.password as string) || "test-password", 10 | ) 11 | const email = (req.query.email as string) || "test" + Math.random() + "@test.com" 12 | const user = await db.user.create({ 13 | data: {email, hashedPassword, role: "user"}, 14 | select: {id: true, name: true, email: true, role: true}, 15 | }) 16 | 17 | await blitzContext.session.$create({ 18 | userId: user.id, 19 | role: "USER", 20 | }) 21 | 22 | res.status(200).json({userId: blitzContext.session.userId, ...user, email: req.query.email}) 23 | }) 24 | -------------------------------------------------------------------------------- /packages/generator/src/utils/readdir-recursive.ts: -------------------------------------------------------------------------------- 1 | import {promises as fs} from "fs" 2 | import path from "path" 3 | 4 | type Filter = (name: string, dir: string) => boolean 5 | 6 | export async function readdirRecursive(root: string, filter?: Filter, dir = ""): Promise { 7 | const absoluteDir = path.resolve(root, dir) 8 | const dirStats = await fs.stat(absoluteDir) 9 | 10 | if (dirStats.isDirectory()) { 11 | let entries = await fs.readdir(absoluteDir) 12 | 13 | if (filter) { 14 | entries = entries.filter((name) => filter(name, dir)) 15 | } 16 | 17 | const recursiveList = await Promise.all( 18 | entries.map((name) => readdirRecursive(root, filter, path.join(dir, name))), 19 | ) 20 | return recursiveList.flat(Infinity) as string[] 21 | } else { 22 | return [dir] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/generator/templates/minimalapp/gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules 3 | .yarn/cache 4 | .yarn/unplugged 5 | .yarn/build-state.yml 6 | .pnp.* 7 | .npm 8 | web_modules/ 9 | 10 | # blitz 11 | /.blitz/ 12 | /.next/ 13 | *.sqlite 14 | *.sqlite-journal 15 | .now 16 | .blitz** 17 | blitz-log.log 18 | 19 | # misc 20 | .DS_Store 21 | 22 | # local env files 23 | .env.local 24 | .env.*.local 25 | .envrc 26 | 27 | # Logs 28 | logs 29 | *.log 30 | 31 | # Runtime data 32 | pids 33 | *.pid 34 | *.seed 35 | *.pid.lock 36 | 37 | # Testing 38 | .coverage 39 | *.lcov 40 | .nyc_output 41 | lib-cov 42 | 43 | # Caches 44 | *.tsbuildinfo 45 | .eslintcache 46 | .node_repl_history 47 | .yarn-integrity 48 | 49 | # Serverless directories 50 | .serverless/ 51 | 52 | # Stores VSCode versions used for testing VSCode extensions 53 | .vscode-test 54 | -------------------------------------------------------------------------------- /packages/blitz/src/cli/commands/next/dev.ts: -------------------------------------------------------------------------------- 1 | import arg from "arg" 2 | import {CliCommand} from "../../index" 3 | import {ServerConfig} from "../../utils/config" 4 | 5 | const dev: CliCommand = async () => { 6 | const nextArgs = arg( 7 | { 8 | "--port": Number, 9 | "--hostname": String, 10 | "--inspect": Boolean, 11 | 12 | "-p": "--port", 13 | "-H": "--hostname", 14 | }, 15 | { 16 | permissive: true, 17 | }, 18 | ) 19 | 20 | const config: ServerConfig = { 21 | rootFolder: process.cwd(), 22 | port: nextArgs["--port"], 23 | hostname: nextArgs["--hostname"], 24 | inspect: nextArgs["--inspect"], 25 | env: process.env.NODE_ENV === "production" ? "prod" : "dev", 26 | } 27 | 28 | await import("../../utils/next-commands").then((i) => i.dev(config)) 29 | } 30 | 31 | export {dev} 32 | -------------------------------------------------------------------------------- /apps/toolkit-app/.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules 3 | .yarn/* 4 | !.yarn/patches 5 | !.yarn/plugins 6 | !.yarn/releases 7 | !.yarn/sdks 8 | !.yarn/versions 9 | .pnp.* 10 | .npm 11 | web_modules/ 12 | 13 | # blitz 14 | /.blitz/ 15 | /.next/ 16 | *.sqlite 17 | *.sqlite-journal 18 | .now 19 | .blitz** 20 | blitz-log.log 21 | 22 | # misc 23 | .DS_Store 24 | 25 | # local env files 26 | .env.local 27 | .env.*.local 28 | .envrc 29 | 30 | # Logs 31 | logs 32 | *.log 33 | 34 | # Runtime data 35 | pids 36 | *.pid 37 | *.seed 38 | *.pid.lock 39 | 40 | # Testing 41 | .coverage 42 | *.lcov 43 | .nyc_output 44 | lib-cov 45 | 46 | # Caches 47 | *.tsbuildinfo 48 | .eslintcache 49 | .node_repl_history 50 | .yarn-integrity 51 | 52 | # Serverless directories 53 | .serverless/ 54 | 55 | # Stores VSCode versions used for testing VSCode extensions 56 | .vscode-test 57 | -------------------------------------------------------------------------------- /packages/blitz/src/cli/commands/next/start.ts: -------------------------------------------------------------------------------- 1 | import arg from "arg" 2 | import {CliCommand} from "../../index" 3 | import {ServerConfig} from "../../utils/config" 4 | 5 | const start: CliCommand = async () => { 6 | const nextArgs = arg( 7 | { 8 | "--port": Number, 9 | "--hostname": String, 10 | "--inspect": Boolean, 11 | 12 | "-p": "--port", 13 | "-H": "--hostname", 14 | }, 15 | { 16 | permissive: true, 17 | }, 18 | ) 19 | 20 | const config: ServerConfig = { 21 | rootFolder: process.cwd(), 22 | port: nextArgs["--port"], 23 | hostname: nextArgs["--hostname"], 24 | inspect: nextArgs["--inspect"], 25 | env: process.env.NODE_ENV === "production" ? "prod" : "dev", 26 | } 27 | 28 | await import("../../utils/next-commands").then((i) => i.prod(config)) 29 | } 30 | 31 | export {start} 32 | -------------------------------------------------------------------------------- /packages/config/eslint.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ["eslint-config-next", "prettier"], 3 | ignorePatterns: ["*.d.ts"], 4 | settings: { 5 | next: { 6 | rootDir: ["./apps/*/", "./packages/*/"], 7 | }, 8 | }, 9 | rules: { 10 | "@next/next/no-html-link-for-pages": "off", 11 | }, 12 | overrides: [ 13 | { 14 | files: ["**/*.ts?(x)"], 15 | plugins: ["@typescript-eslint"], 16 | parserOptions: { 17 | project: "./tsconfig.json", 18 | }, 19 | rules: { 20 | "@typescript-eslint/no-floating-promises": "error", 21 | "no-use-before-define": "off", 22 | "@typescript-eslint/no-use-before-define": ["off"], 23 | "no-redeclare": "off", 24 | "@typescript-eslint/no-redeclare": ["error"], 25 | "react/display-name": "off", 26 | }, 27 | }, 28 | ], 29 | } 30 | -------------------------------------------------------------------------------- /packages/blitz-next/eslint.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ["eslint-config-next", "prettier"], 3 | ignorePatterns: ["*.d.ts"], 4 | settings: { 5 | next: { 6 | rootDir: ["./apps/*/", "./packages/*/"], 7 | }, 8 | }, 9 | rules: { 10 | "@next/next/no-html-link-for-pages": "off", 11 | }, 12 | overrides: [ 13 | { 14 | files: ["**/*.ts?(x)"], 15 | plugins: ["@typescript-eslint"], 16 | parserOptions: { 17 | project: "./tsconfig.json", 18 | }, 19 | rules: { 20 | "@typescript-eslint/no-floating-promises": "error", 21 | "no-use-before-define": "off", 22 | "@typescript-eslint/no-use-before-define": ["off"], 23 | "no-redeclare": "off", 24 | "@typescript-eslint/no-redeclare": ["error"], 25 | "react/display-name": "off", 26 | }, 27 | }, 28 | ], 29 | } 30 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-invoke-ctx.tsx: -------------------------------------------------------------------------------- 1 | import {SessionContext} from "@blitzjs/auth" 2 | import {invokeWithCtx} from "@blitzjs/rpc" 3 | import {gSSP} from "app/blitz-server" 4 | import getUsersAuth from "app/queries/getUsersAuth" 5 | 6 | type Props = { 7 | userId: unknown 8 | publicData: SessionContext["$publicData"] 9 | } 10 | 11 | export const getServerSideProps = gSSP(async ({ctx}) => { 12 | const {session} = ctx 13 | 14 | const users = await invokeWithCtx(getUsersAuth, {}, ctx) 15 | 16 | console.log({users}) 17 | 18 | return { 19 | props: { 20 | userId: session.userId, 21 | publicData: session.$publicData, 22 | publishedAt: new Date(0), 23 | }, 24 | } 25 | }) 26 | 27 | function PageWithInvokeCtx(props: Props) { 28 | return
{JSON.stringify(props, null, 2)}
29 | } 30 | 31 | export default PageWithInvokeCtx 32 | -------------------------------------------------------------------------------- /packages/generator/templates/app/gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules 3 | .yarn/* 4 | !.yarn/patches 5 | !.yarn/plugins 6 | !.yarn/releases 7 | !.yarn/sdks 8 | !.yarn/versions 9 | .pnp.* 10 | .npm 11 | web_modules/ 12 | 13 | # blitz 14 | /.blitz/ 15 | /.next/ 16 | *.sqlite 17 | *.sqlite-journal 18 | .now 19 | .blitz** 20 | blitz-log.log 21 | 22 | # misc 23 | .DS_Store 24 | 25 | # local env files 26 | .env.local 27 | .env.*.local 28 | .envrc 29 | 30 | # Logs 31 | logs 32 | *.log 33 | 34 | # Runtime data 35 | pids 36 | *.pid 37 | *.seed 38 | *.pid.lock 39 | 40 | # Testing 41 | .coverage 42 | *.lcov 43 | .nyc_output 44 | lib-cov 45 | 46 | # Caches 47 | *.tsbuildinfo 48 | .eslintcache 49 | .node_repl_history 50 | .yarn-integrity 51 | 52 | # Serverless directories 53 | .serverless/ 54 | 55 | # Stores VSCode versions used for testing VSCode extensions 56 | .vscode-test 57 | -------------------------------------------------------------------------------- /packages/codemod/src/index.ts: -------------------------------------------------------------------------------- 1 | import arg from "arg" 2 | 3 | const commonArgs = { 4 | // Types 5 | "--help": Boolean, 6 | 7 | // Aliases 8 | "-h": "--help", 9 | } 10 | 11 | const args = arg(commonArgs, { 12 | permissive: true, 13 | }) 14 | 15 | const commands: {[command: string]: () => Promise<() => void>} = { 16 | "upgrade-legacy": () => import("./upgrade-legacy").then((i) => i.upgradeLegacy), 17 | } 18 | 19 | const foundCommand = Boolean(commands[args._[0] as string]) 20 | const forwardedArgs = foundCommand ? args._.slice(1) : args._ 21 | 22 | if (foundCommand) { 23 | commands[args["_"][0] as string]?.() 24 | .then((exec: any) => exec(forwardedArgs)) 25 | .catch((err) => { 26 | console.log(err) 27 | }) 28 | } else { 29 | console.log("Codemod not found. Try one of these:") 30 | console.log(`${Object.keys(commands).map((c) => c)}`) 31 | } 32 | -------------------------------------------------------------------------------- /integration-tests/rpc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-rpc", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "test": "vitest --config ./vitest.config.ts run", 7 | "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf .next" 8 | }, 9 | "dependencies": { 10 | "@blitzjs/auth": "workspace:*", 11 | "@blitzjs/config": "workspace:*", 12 | "@blitzjs/next": "workspace:*", 13 | "@blitzjs/rpc": "workspace:*", 14 | "blitz": "workspace:*", 15 | "next": "12.2.0", 16 | "react": "18.0.0", 17 | "react-dom": "18.0.0" 18 | }, 19 | "devDependencies": { 20 | "@types/express": "4.17.13", 21 | "@types/fs-extra": "9.0.13", 22 | "@types/node-fetch": "2.6.1", 23 | "@types/react": "18.0.1", 24 | "b64-lite": "1.4.0", 25 | "eslint": "7.32.0", 26 | "fs-extra": "10.0.1", 27 | "typescript": "^4.5.3" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /apps/toolkit-app/app/auth/mutations/changePassword.ts: -------------------------------------------------------------------------------- 1 | import { NotFoundError } from "blitz" 2 | import db from "db" 3 | import { authenticateUser } from "./login" 4 | import { ChangePassword } from "../validations" 5 | import { resolver } from "@blitzjs/rpc" 6 | import { SecurePassword } from "@blitzjs/auth" 7 | 8 | export default resolver.pipe( 9 | resolver.zod(ChangePassword), 10 | resolver.authorize(), 11 | async ({ currentPassword, newPassword }, ctx) => { 12 | const user = await db.user.findFirst({ where: { id: ctx.session.userId as number } }) 13 | if (!user) throw new NotFoundError() 14 | 15 | await authenticateUser(user.email, currentPassword) 16 | 17 | const hashedPassword = await SecurePassword.hash(newPassword.trim()) 18 | await db.user.update({ 19 | where: { id: user.id }, 20 | data: { hashedPassword }, 21 | }) 22 | 23 | return true 24 | } 25 | ) 26 | -------------------------------------------------------------------------------- /packages/generator/templates/queries/get__ModelNames__.ts: -------------------------------------------------------------------------------- 1 | import {paginate} from "blitz" 2 | import { resolver } from "@blitzjs/rpc" 3 | import db, {Prisma} from "db" 4 | 5 | interface Get__ModelNames__Input 6 | extends Pick {} 7 | 8 | export default resolver.pipe( 9 | resolver.authorize(), 10 | async ({where, orderBy, skip = 0, take = 100}: Get__ModelNames__Input) => { 11 | // TODO: in multi-tenant app, you must add validation to ensure correct tenant 12 | const {items: __modelNames__, hasMore, nextPage, count} = await paginate({ 13 | skip, 14 | take, 15 | count: () => db.__modelName__.count({where}), 16 | query: (paginateArgs) => db.__modelName__.findMany({...paginateArgs, where, orderBy}), 17 | }) 18 | 19 | return { 20 | __modelNames__, 21 | nextPage, 22 | hasMore, 23 | count, 24 | } 25 | } 26 | ) -------------------------------------------------------------------------------- /packages/blitz-rpc/src/loader-utils.test.ts: -------------------------------------------------------------------------------- 1 | import {describe, expect, it} from "vitest" 2 | import {convertPageFilePathToRoutePath} from "./loader-utils" 3 | 4 | const FILE_PATH = "app/queries/getData.ts" 5 | 6 | describe("convertPageFilePathToRoutePath", () => { 7 | it("should return the full path when resolverBasePath is set to root", () => { 8 | const res = convertPageFilePathToRoutePath(FILE_PATH, "root") 9 | 10 | expect(res).toEqual("app/queries/getData") 11 | }) 12 | 13 | it("should return the relative path when resolverBasePath is set to queries|mutations", () => { 14 | const res = convertPageFilePathToRoutePath(FILE_PATH, "queries|mutations") 15 | 16 | expect(res).toEqual("/getData") 17 | }) 18 | 19 | it("should return the relative path when resolverBasePath is set to undefined", () => { 20 | const res = convertPageFilePathToRoutePath(FILE_PATH, undefined) 21 | 22 | expect(res).toEqual("/getData") 23 | }) 24 | }) 25 | -------------------------------------------------------------------------------- /packages/generator/src/utils/npm-fetch.ts: -------------------------------------------------------------------------------- 1 | import got from "got" 2 | 3 | type PackageInformation = any 4 | export type NpmDepResponse = {versions: Record} 5 | 6 | export const fetchAllVersions = async (dependency: string) => { 7 | const res = (await got(`https://registry.npmjs.org/${dependency}`, { 8 | retry: {limit: 3}, 9 | timeout: 3000, 10 | responseType: "json", 11 | }).json()) as unknown as NpmDepResponse 12 | return Object.keys(res.versions) 13 | } 14 | 15 | export const fetchDistTags = async (dependency: string) => { 16 | const res = (await got(`https://registry.npmjs.org/-/package/${dependency}/dist-tags`, { 17 | retry: {limit: 3}, 18 | timeout: 3000, 19 | responseType: "json", 20 | }).json()) as unknown as Record 21 | return res 22 | } 23 | 24 | export const fetchLatestDistVersion = async (dependency: string) => { 25 | const res = await fetchDistTags(dependency) 26 | return res.latest 27 | } 28 | -------------------------------------------------------------------------------- /integration-tests/react-query-utils/pages/page-with-get-query-data.tsx: -------------------------------------------------------------------------------- 1 | import {getQueryData, useQuery} from "@blitzjs/rpc" 2 | import {Suspense, useState} from "react" 3 | import getBasic from "../app/queries/getBasic" 4 | 5 | function Content() { 6 | const [data] = useQuery(getBasic, undefined) 7 | const [newData, setNewData] = useState() 8 | return ( 9 |
10 |
{data}
11 | {newData &&
{newData}
} 12 | 21 |
22 | ) 23 | } 24 | 25 | function PageWithGetQueryData() { 26 | return ( 27 |
28 | 29 | 30 | 31 |
32 | ) 33 | } 34 | 35 | export default PageWithGetQueryData 36 | -------------------------------------------------------------------------------- /apps/toolkit-app/app/auth/validations.ts: -------------------------------------------------------------------------------- 1 | import { z } from "zod" 2 | 3 | export const email = z 4 | .string() 5 | .email() 6 | .transform((str) => str.toLowerCase().trim()) 7 | 8 | export const password = z 9 | .string() 10 | .min(10) 11 | .max(100) 12 | .transform((str) => str.trim()) 13 | 14 | export const Signup = z.object({ 15 | email, 16 | password, 17 | }) 18 | 19 | export const Login = z.object({ 20 | email, 21 | password: z.string(), 22 | }) 23 | 24 | export const ForgotPassword = z.object({ 25 | email, 26 | }) 27 | 28 | export const ResetPassword = z 29 | .object({ 30 | password: password, 31 | passwordConfirmation: password, 32 | token: z.string(), 33 | }) 34 | .refine((data) => data.password === data.passwordConfirmation, { 35 | message: "Passwords don't match", 36 | path: ["passwordConfirmation"], // set the path of the error 37 | }) 38 | 39 | export const ChangePassword = z.object({ 40 | currentPassword: z.string(), 41 | newPassword: password, 42 | }) 43 | -------------------------------------------------------------------------------- /integration-tests/utils/next-webdriver.d.ts: -------------------------------------------------------------------------------- 1 | import {BrowserInterface} from "./browsers/base" 2 | export declare const USE_SELENIUM: boolean 3 | /** 4 | * 5 | * @param appPortOrUrl can either be the port or the full URL 6 | * @param url the path/query to append when using appPort 7 | * @param options.waitHydration whether to wait for react hydration to finish 8 | * @param options.retryWaitHydration allow retrying hydration wait if reload occurs 9 | * @param options.disableCache disable cache for page load 10 | * @param options.beforePageLoad the callback receiving page instance before loading page 11 | * @returns thenable browser instance 12 | */ 13 | export default function webdriver( 14 | appPortOrUrl: string | number, 15 | url: string, 16 | options?: { 17 | waitHydration?: boolean 18 | retryWaitHydration?: boolean 19 | disableCache?: boolean 20 | beforePageLoad?: (page: any) => void 21 | locale?: string 22 | }, 23 | ): Promise 24 | //# sourceMappingURL=next-webdriver.d.ts.map 25 | -------------------------------------------------------------------------------- /integration-tests/middleware/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-middleware", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start:dev": "next dev", 7 | "test": "vitest run", 8 | "test-watch": "vitest", 9 | "start": "next start", 10 | "lint": "next lint", 11 | "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf .next" 12 | }, 13 | "dependencies": { 14 | "@blitzjs/config": "workspace:*", 15 | "@blitzjs/next": "workspace:*", 16 | "@blitzjs/rpc": "workspace:*", 17 | "blitz": "workspace:*", 18 | "next": "12.2.0", 19 | "react": "18.0.0", 20 | "react-dom": "18.0.0" 21 | }, 22 | "devDependencies": { 23 | "@next/bundle-analyzer": "12.0.8", 24 | "@types/express": "4.17.13", 25 | "@types/fs-extra": "9.0.13", 26 | "@types/node-fetch": "2.6.1", 27 | "@types/react": "18.0.1", 28 | "eslint": "7.32.0", 29 | "fs-extra": "10.0.1", 30 | "get-port": "6.1.2", 31 | "node-fetch": "3.2.3", 32 | "typescript": "^4.5.3" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /integration-tests/qm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-qm", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "test": "vitest run", 7 | "test-watch": "vitest", 8 | "clean": "rm -rf .turbo && rm -rf node_modules" 9 | }, 10 | "dependencies": { 11 | "@blitzjs/auth": "workspace:*", 12 | "@blitzjs/config": "workspace:*", 13 | "@blitzjs/next": "workspace:*", 14 | "@blitzjs/rpc": "workspace:*", 15 | "@prisma/client": "4.0.0", 16 | "@tanstack/react-query": "4.0.10", 17 | "blitz": "workspace:*", 18 | "next": "12.2.0", 19 | "prisma": "4.0.0", 20 | "react": "18.0.0", 21 | "react-dom": "18.0.0" 22 | }, 23 | "devDependencies": { 24 | "@testing-library/react": "13.0.0", 25 | "@types/react": "18.0.1", 26 | "@vitejs/plugin-react": "1.3.0", 27 | "delay": "5.0.0", 28 | "eslint": "7.32.0", 29 | "eslint-config-next": "latest", 30 | "eslint-plugin-testing-library": "5.0.1", 31 | "jsdom": "^19.0.0", 32 | "typescript": "^4.5.3" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/generator/templates/app/app/auth/validations.ts: -------------------------------------------------------------------------------- 1 | import { z } from "zod" 2 | 3 | export const email = z 4 | .string() 5 | .email() 6 | .transform((str) => str.toLowerCase().trim()) 7 | 8 | export const password = z 9 | .string() 10 | .min(10) 11 | .max(100) 12 | .transform((str) => str.trim()) 13 | 14 | export const Signup = z.object({ 15 | email, 16 | password, 17 | }) 18 | 19 | export const Login = z.object({ 20 | email, 21 | password: z.string(), 22 | }) 23 | 24 | export const ForgotPassword = z.object({ 25 | email, 26 | }) 27 | 28 | export const ResetPassword = z 29 | .object({ 30 | password: password, 31 | passwordConfirmation: password, 32 | token: z.string(), 33 | }) 34 | .refine((data) => data.password === data.passwordConfirmation, { 35 | message: "Passwords don't match", 36 | path: ["passwordConfirmation"], // set the path of the error 37 | }) 38 | 39 | export const ChangePassword = z.object({ 40 | currentPassword: z.string(), 41 | newPassword: password, 42 | }) 43 | -------------------------------------------------------------------------------- /packages/generator/src/utils/inflector.ts: -------------------------------------------------------------------------------- 1 | import pluralize from "pluralize" 2 | import {pipe} from "./pipe" 3 | 4 | export function plural(input: string): string { 5 | return pluralize.isPlural(input) ? input : pluralize.plural(input) 6 | } 7 | 8 | export function singular(input: string): string { 9 | return pluralize.isSingular(input) ? input : pluralize.singular(input) 10 | } 11 | 12 | export function capitalize(input: string): string { 13 | return `${input.slice(0, 1).toUpperCase()}${input.slice(1)}` 14 | } 15 | 16 | export function uncapitalize(input: string): string { 17 | return `${input.slice(0, 1).toLowerCase()}${input.slice(1)}` 18 | } 19 | 20 | export const singlePascal = pipe(singular, capitalize) 21 | export const singleCamel = pipe(singular, uncapitalize) 22 | export const pluralPascal = pipe(plural, capitalize) 23 | export const pluralCamel = pipe(plural, uncapitalize) 24 | 25 | export function camelCaseToKebabCase(transformString: string) { 26 | return transformString.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase() 27 | } 28 | -------------------------------------------------------------------------------- /apps/web/pages/page-with-inf-prefetch.tsx: -------------------------------------------------------------------------------- 1 | import {useInfiniteQuery} from "@blitzjs/rpc" 2 | import {gSSP} from "app/blitz-server" 3 | import getInfiniteUsers from "app/queries/getInfiniteUsers" 4 | 5 | export const getServerSideProps = gSSP(async ({ctx}) => { 6 | const {prefetchInfiniteQuery} = ctx 7 | 8 | await prefetchInfiniteQuery(getInfiniteUsers, {}, {}) 9 | return {props: {}} 10 | }) 11 | 12 | function PageWithPrefetchInfiniteQuery(props) { 13 | const [usersPages] = useInfiniteQuery(getInfiniteUsers, (page = {take: 3, skip: 0}) => page, { 14 | getNextPageParam: (lastPage) => lastPage.nextPage, 15 | }) 16 | return ( 17 |
18 | {usersPages.map((usersPage) => 19 | usersPage?.users.map((u) => ( 20 |
21 |

name: {u.name}

22 |

role: {u.role}

23 |

email: {u.email}

24 |
25 |
26 | )), 27 | )} 28 |
29 | ) 30 | } 31 | 32 | export default PageWithPrefetchInfiniteQuery 33 | -------------------------------------------------------------------------------- /packages/generator/src/generators/query-generator.ts: -------------------------------------------------------------------------------- 1 | import {Generator, GeneratorOptions, SourceRootType} from "../generator" 2 | import {getTemplateRoot} from "../utils/get-template-root" 3 | import {camelCaseToKebabCase} from "../utils/inflector" 4 | 5 | export interface QueryGeneratorOptions extends GeneratorOptions { 6 | name: string 7 | Name: string 8 | } 9 | 10 | export class QueryGenerator extends Generator { 11 | sourceRoot: SourceRootType 12 | constructor(options: QueryGeneratorOptions) { 13 | super(options) 14 | this.sourceRoot = getTemplateRoot(options.templateDir, {type: "template", path: "query"}) 15 | } 16 | static subdirectory = "query" 17 | 18 | // eslint-disable-next-line require-await 19 | async getTemplateValues() { 20 | return { 21 | name: this.options.name, 22 | Name: this.options.Name, 23 | } 24 | } 25 | 26 | getTargetDirectory() { 27 | const context = this.options.context ? `${camelCaseToKebabCase(this.options.context)}` : "" 28 | return `app/${context}/queries` 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /integration-tests/utils/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-utils", 3 | "version": "0.0.0", 4 | "private": true, 5 | "devDependencies": { 6 | "@blitzjs/config": "workspace: *", 7 | "@blitzjs/rpc": "workspace: *", 8 | "@tanstack/react-query": "4.0.10", 9 | "@testing-library/react": "13.0.0", 10 | "@types/express": "4.17.13", 11 | "@types/fs-extra": "9.0.13", 12 | "@types/node-fetch": "2.6.1", 13 | "@types/react": "18.0.1", 14 | "@types/rimraf": "3.0.2", 15 | "@types/selenium-webdriver": "4.0.18", 16 | "chromedriver": "100.0.0", 17 | "cross-spawn": "7.0.3", 18 | "eslint": "7.32.0", 19 | "express": "4.17.3", 20 | "fs-extra": "10.0.1", 21 | "get-port": "6.1.2", 22 | "node-fetch": "3.2.3", 23 | "pkg-dir": "5.0.0", 24 | "playwright-chromium": "1.14.1", 25 | "react": "18.0.0", 26 | "react-dom": "18.0.0", 27 | "resolve-cwd": "3.0.0", 28 | "resolve-from": "5.0.0", 29 | "rimraf": "3.0.2", 30 | "selenium-webdriver": "4.1.1", 31 | "tree-kill": "1.2.2", 32 | "typescript": "^4.5.3" 33 | } 34 | } 35 | --------------------------------------------------------------------------------