github blitz-js/blitz v0.30.0-canary.0

latest releases: v2.0.8, blitz@2.0.8, @blitzjs/rpc@2.0.8...
pre-release3 years ago

Ok y'all, this is a big release with a lot of changes. The good news is that this is the last known breaking changes for foreseeable future!

💥 Breaking Changes

  • You must use the new enhancePrisma() utility: #1720, #1762
    • This allows importing Prisma enum's into your client build
    • It ensures a single prisma instance in your app
    • It adds db.$reset() for use in testing
    • Read the docs
+import { enhancePrisma } from "blitz"
import { PrismaClient } from "@prisma/client"
export * from "@prisma/client"

-let prisma: PrismaClient
-if (serverEnv.isProduction) {
-  prisma = new PrismaClient()
-} else {
-  // Ensure the prisma instance is re-used during hot-reloading
-  // Otherwise, a new client will be created on every reload
-  globalThis["prisma"] = globalThis["prisma"] || new PrismaClient()
-  prisma = globalThis["prisma"]
-}
-export default prisma
+const EnhancedPrisma = enhancePrisma(PrismaClient)
+export default new EnhancedPrisma()
  • Prefix all ctx.session methods with $ and move publicData fields to top level of ctx.session: #1779
-ctx.session.authorize()
+ctx.session.$authorize()
const userId = ctx.session.userId
-const orgId = ctx.session.publicData.orgId
+const orgId = ctx.session.orgId
  • Simplify type definition for PublicData AND add strong typing for $isAuthorized() and $authorize(): #1806, #1796
-import { DefaultCtx, SessionContext, DefaultPublicData } from "blitz"
+import { DefaultCtx, SessionContext } from "blitz"
+import { simpleRolesIsAuthorized } from "@blitzjs/server"
import { User } from "db"

declare module "blitz" {
  export interface Ctx extends DefaultCtx {
    session: SessionContext
  }
-  export interface PublicData extends DefaultPublicData {
-    userId: User["id"]
-  }
+  export interface Session {
+    isAuthorized: typeof simpleRolesIsAuthorized
+    PublicData: {
+      userId: User["id"]
+      roles: string[]  // NOTE: you now need to explicitly specify this field
+    }
+  }
}
  • Change session cookies to have a unique prefixed based on package.json name field: #1743
    • This is not a breaking code change, but it will force all users to be logged out (they can simply log back in and continue on)

🔥 Major New Features

  • 🎉 Add Forgot Password code to new app template: #1127
    • You can add this to existing apps like this:
      • Upgrade global blitz install to this version
      • Run blitz new your-existing-app. It will add new files and for existing files, it will show changes and ask what you want to do
  • Add pipe.resolver(), pipe.zod(), pipe.authorize(), and pipe.authorizeIf() for queries/mutations: #1801
import {pipe} from "blitz"
import db from "db"
import * as z from "zod"

export const CreateProject = z.object({
  name: z.string(),
  dueDate: z.date().optional(),
  orgId: z.number().optional(),
})

export default pipe.resolver(
  pipe.zod(CreateProject),
  pipe.authorize(),
  // Set default orgId
  (input, {session}) => ({...input, orgId: input.orgId ?? session.orgId}),
  async (input, ctx) => {
    return await db.project.create({data: input})
  },
)
  • Add blitz/babel preset which includes babel-plugin-superjson-next for getServerSideProps Date serialization: #1771
// babel.config.js
module.exports = {
-  presets: ["next/babel"],
+  presets: ["blitz/babel"],
  plugins: [],
}
  • Drastically simplify eslint integration with new eslint-config-blitz package: #1749
// .eslintrc.js
module.exports = {
-   env: {
-     es2020: true,
-   },
-   extends: ['react-app', 'plugin:jsx-a11y/recommended'],
-   plugins: ['jsx-a11y'],
-   rules: {
-     "import/no-anonymous-default-export": "error",
-     'import/no-webpack-loader-syntax': 'off',
-     'react/react-in-jsx-scope': 'off', // React is always in scope with Blitz
-     'jsx-a11y/anchor-is-valid': 'off', //Doesn't play well with Blitz/Next <Link> usage
-   },
+   extends: ["blitz"],
 }

// package.json
-     "@typescript-eslint/eslint-plugin": "4.x",
-     "@typescript-eslint/parser": "4.x",
-     "babel-eslint": "10.x",
-     "eslint-config-react-app": "6.x",
-     "eslint-plugin-flowtype": "5.x",
-     "eslint-plugin-import": "2.x",
-     "eslint-plugin-jsx-a11y": "6.x",
-     "eslint-plugin-react": "7.x",
-     "eslint-plugin-react-hooks": "4.x",
  • Drastically simplify Jest integration with a Blitz jest preset and by moving test dependencies into blitz.: #1725
    • You can remove import "@testing-library/jest-dom/extend-expect" from test/setup.ts
    • You can remove test/__mocks__/fileMock.js
// jest.config.js
-const { pathsToModuleNameMapper } = require("ts-jest/utils")
-const { compilerOptions } = require("./tsconfig")
 module.exports = {
-   // Test setup file
-   setupFilesAfterEnv: ["<rootDir>/test/setup.ts"],
-  // ... LOTS of stuff
-   collectCoverageFrom: ["**/*.{js,jsx,ts,tsx}", "!**/*.d.ts", "!**/node_modules/**"],
+   preset: "blitz",
 }

// package.json
-     "@testing-library/jest-dom": "5.x",
-     "@testing-library/react": "11.x",
-     "@testing-library/react-hooks": "3.x",
-     "@types/jest": "26.x",
-     "jest": "26.x",
-     "jest-environment-jsdom-fourteen": "1.x",
-     "jest-watch-typeahead": "0.x",
-     "react-test-renderer": "17.x",
-     "ts-jest": "26.x"
  • Change blitz generate to generate all pages in app/pages/ instead of app/modelName/pages/: #1719
  • Improvements to isAuthorized adapters: #1796
    • Ability to strongly type
    • Change first arg to have ctx
    • Allow multiple params
    • Read the docs

🚀 New Features

  • Add generateToken() and hash256() utilities: #1721
  • Add db.$reset() prisma method for use in tests (added by enhancePrisma()): #1762
  • Update blitz generate templates for Prisma 2.15: #1759
  • Change normal resolver logging to log serializer duration: #1778
  • Add if arg to ctx.session.$authorize(): #1796
    • Example: ctx.session.$authorize("admin", {if: inputUserId !== currentUserId})
    • Read the docs

🐞 Patches

  • Major improvement to blitz install UX: #1782
  • Fix blitz generate bug when model name ends with number: #1727
  • Add .yalc folder to ignore paths: #1734
  • Automatically disable useQuery suspense when not using concurrent mode: #1735
  • Fix all queries not being refetched on login: #1748
  • Update dependencies (2021-01-19): #1736
  • Fix logging issues: Update tslog: 3.0.5 → 3.1.0: #1760
  • Fix relative imports from within API routes: #1761
  • Fix prisma errors missing code & meta properties: #1766
  • Add missing type exports like GetStaticPropsContext: #1772
  • Fix not all folder names kebab-case from blitz generate: #1790
  • Fix blitz console not working in vanilla JS projects: #1686

⚡️ Changes to the New App Template

  • 🎉 Add Forgot Password code to new app template: #1127
  • Use new blitz/babel preset: #1771
  • Use new blitz eslint preset: #1749
  • Use new blitz jest preset.: #1725
  • Update app structure to use app/core/: #1719
  • Update to Prisma 2.15: #1759
  • Remove app/auth/auth-utils.ts by moving code into the login mutation: #1740
  • Add changePassword mutation: #1741
  • Update &lt;Form&gt; to easily hide default submit button by making submitText optional: #1800

👩‍🍳 Recipes

  • Remove console.log from reflexjs recipe: #1722
  • Add Quirrel recipe: #1764
  • Rename chakra recipe to chakra-ui: #1775

Internal Meta Changes

  • Add @malkomalko as L1 Maintainer: #1728
  • Docs: add tarunama as a contributor: #1739
  • Docs: add bacongravy as a contributor: #1742
  • Add @mikeesto as a contributor: 04ed495
  • Add @marina-ki as a contributor: e5baf8c
  • Lori retires as L1 maintainer: 817b760
  • fix some code formatting: d69ca33
  • Change package.json engines version 12.20 to 12: #1773
  • Retry example e2e tests one time if they fail: f61ae6e
  • Docs: Add READMEs to packages that were missing them: #1780
  • Add prisma issue to new issue page: 25811cf
  • Change all references/links to Slack over to our new Discord: bbec590
  • Add @jonasthiesen as a contributor: 8d2e7ab
  • Update all dependencies (2021-01-25): #1792
  • Docs: add marina-ki as a contributor: #1797
  • Docs: add thakkaryash94 as a contributor: #1798
  • Chore: unify spell of TypeScript: #1731

Credits

Huge thanks to @koolii, @malkomalko, @bacongravy, @hasparus, @marina-ki, @Flavyoo, @scisteffan, @Skn0tt, @nitaking, @MrLeebo, and @tarunama for helping!

Don't miss a new blitz release

NewReleases is sending notifications on new releases.