-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add types to JSON columns in prisma schema (#318)
### TL;DR Added the `prisma-json-types-generator` module to the project and associated it with the JSON columns in the Prisma schema. This enables the usage of strongly typed JSON columns in the database. ### What changed? - Added `prisma-json-types-generator` version `^3.0.4` to `package.json` and `package-lock.json`. - Updated `schema.prisma` to include a new generator for `prisma-json-types-generator`. - Added type annotations for JSON fields in various models. - Created a new `types.ts` file to define types for the JSON columns. - Updated various parts of the codebase to use the new strongly typed JSON fields. ### How to test? 1. Install the new dependencies by running `npm install`. 2. Verify that the Prisma client is generated with the new JSON types by running `npx prisma generate`. 3. Run the existing tests to ensure that no functionality is broken. 4. Perform manual testing on forms that deal with JSON fields to ensure they are working correctly. ### Why make this change? This change enhances type safety and developer experience by enabling strongly typed JSON columns in the database. It also prepares the project for more advanced features that rely on typed JSON data. ---
- Loading branch information
Showing
17 changed files
with
302 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* This type file is used by prisma-json-types-generator to generate typecasts for | ||
* Json columns in the database to use in the applications. | ||
* This is further used by the `kysely` and `kysely-prisma` libraries to generate | ||
* types for the query builder. | ||
*/ | ||
|
||
import type { | ||
IsomerPageSchemaType as _IsomerPageSchemaType, | ||
IsomerSchema as _IsomerSchema, | ||
IsomerSiteConfigProps as _IsomerSiteConfigProps, | ||
IsomerSiteWideComponentsProps as _IsomerSiteWideComponentsProps, | ||
} from "@opengovsg/isomer-components" | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace PrismaJson { | ||
type SiteJsonConfig = _IsomerSiteConfigProps | ||
type BlobJsonContent = _IsomerSchema | ||
type NavbarJsonContent = _IsomerSiteWideComponentsProps["navBarItems"] | ||
type FooterJsonContent = _IsomerSiteWideComponentsProps["footerItems"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { ZodTypeAny } from "zod" | ||
import { useRouter } from "next/router" | ||
|
||
export const useQueryParse = <T extends ZodTypeAny>(schema: T) => { | ||
const { query } = useRouter() | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return schema.parse(query) as T["_output"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
apps/studio/src/pages/sites/[siteId]/pages/[pageId]/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.