Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/misc/redwood/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@
"homepage": "https://zenstack.dev",
"license": "MIT",
"dependencies": {
"@redwoodjs/cli-helpers": "^7.7.3",
"@zenstackhq/runtime": "workspace:*",
"colors": "1.4.0",
"ts-morph": "^16.0.0",
"@redwoodjs/cli-helpers": "^6.6.0",
"execa": "^5.0.0",
"listr2": "^6.0.0",
"semver": "^7.5.2",
"terminal-link": "^2.0.0",
"ts-morph": "^16.0.0",
"yargs": "^17.7.2"
},
"devDependencies": {
"@redwoodjs/graphql-server": "^6.6.0",
"@redwoodjs/graphql-server": "^7.7.3",
"@types/yargs": "^17.0.32",
"graphql-yoga": "^5.0.2"
}
Expand Down
22 changes: 17 additions & 5 deletions packages/misc/redwood/src/commands/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getPaths, updateTomlConfig } from '@redwoodjs/cli-helpers';
import { getInstalledRedwoodVersion, getPaths, updateTomlConfig } from '@redwoodjs/cli-helpers';
import colors from 'colors';
import execa from 'execa';
import fs from 'fs';
import { Listr, ListrTask } from 'listr2';
import path from 'path';
import semver from 'semver';
import terminalLink from 'terminal-link';
import { Project, SyntaxKind, type PropertyAssignment } from 'ts-morph';
import type { CommandModule } from 'yargs';
Expand Down Expand Up @@ -47,8 +48,8 @@ function bootstrapSchema() {
const pkg = JSON.parse(content);
if (!pkg.zenstack) {
pkg.zenstack = {
schema: path.relative(apiPaths.base, zmodel),
prisma: path.relative(apiPaths.base, apiPaths.dbSchema),
schema: normalizePath(path.relative(apiPaths.base, zmodel)),
prisma: normalizePath(path.relative(apiPaths.base, apiPaths.dbSchema)),
};
fs.writeFileSync(pkgJson, JSON.stringify(pkg, null, 4));
}
Expand All @@ -57,6 +58,11 @@ function bootstrapSchema() {
};
}

// ensures posix path separators are used in package.json
function normalizePath(_path: string) {
return _path.replaceAll(path.sep, path.posix.sep);
}

// install ZenStack GraphQLYoga plugin
function installGraphQLPlugin() {
return {
Expand Down Expand Up @@ -144,11 +150,17 @@ function installGraphQLPlugin() {
if (graphQlSourcePath.endsWith('.ts')) {
const typeDefPath = path.join(getPaths().api.src, 'zenstack.d.ts');
if (!fs.existsSync(typeDefPath)) {
const rwVersion: string = getInstalledRedwoodVersion();
const contextModule =
rwVersion && semver.lt(rwVersion, '7.0.0')
? '@redwoodjs/graphql-server' // pre v7
: '@redwoodjs/context'; // v7+

const typeDefSourceFile = project.createSourceFile(
typeDefPath,
`import type { PrismaClient } from '@prisma/client'
`import type { PrismaClient } from '@zenstackhq/runtime'

declare module '@redwoodjs/graphql-server' {
declare module '${contextModule}' {
interface GlobalContext {
db: PrismaClient
}
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/res/enhance.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { auth, enhance } from '.zenstack/enhance';
export { auth, enhance, type PrismaClient } from '.zenstack/enhance';
4 changes: 3 additions & 1 deletion packages/schema/src/plugins/enhancer/enhance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ ${
}

private createSimplePrismaImports(prismaImport: string) {
return `import { Prisma } from '${prismaImport}';
return `import { Prisma, type PrismaClient } from '${prismaImport}';
import type * as _P from '${prismaImport}';
export type { PrismaClient };
`;
}

Expand All @@ -152,6 +153,7 @@ export function enhance<DbClient extends object>(prisma: DbClient, context?: Enh
import type { InternalArgs, DynamicClientExtensionThis } from '${prismaImport}/runtime/library';
import type * as _P from '${logicalPrismaClientDir}/index-fixed';
import type { Prisma, PrismaClient } from '${logicalPrismaClientDir}/index-fixed';
export type { PrismaClient };
`;
}

Expand Down
Loading