Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
auto-install-peers=true
git-checks=false
node-linker=hoisted
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenstack-monorepo",
"version": "2.3.3",
"version": "2.4.0",
"description": "",
"scripts": {
"build": "pnpm -r build",
Expand Down
2 changes: 1 addition & 1 deletion packages/ide/jetbrains/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "dev.zenstack"
version = "2.3.3"
version = "2.4.0"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion packages/ide/jetbrains/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jetbrains",
"version": "2.3.3",
"version": "2.4.0",
"displayName": "ZenStack JetBrains IDE Plugin",
"description": "ZenStack JetBrains IDE plugin",
"homepage": "https://zenstack.dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/language/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/language",
"version": "2.3.3",
"version": "2.4.0",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
9 changes: 5 additions & 4 deletions packages/misc/redwood/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/redwood",
"displayName": "ZenStack RedwoodJS Integration",
"version": "2.3.3",
"version": "2.4.0",
"description": "CLI and runtime for integrating ZenStack with RedwoodJS projects.",
"repository": {
"type": "git",
Expand Down 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/plugins/openapi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/openapi",
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
"version": "2.3.3",
"version": "2.4.0",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/swr/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/swr",
"displayName": "ZenStack plugin for generating SWR hooks",
"version": "2.3.3",
"version": "2.4.0",
"description": "ZenStack plugin for generating SWR hooks",
"main": "index.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/tanstack-query/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/tanstack-query",
"displayName": "ZenStack plugin for generating tanstack-query hooks",
"version": "2.3.3",
"version": "2.4.0",
"description": "ZenStack plugin for generating tanstack-query hooks",
"main": "index.js",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/trpc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/trpc",
"displayName": "ZenStack plugin for tRPC",
"version": "2.3.3",
"version": "2.4.0",
"description": "ZenStack plugin for tRPC",
"main": "index.js",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/trpc/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const compilerOptions: CompilerOptions = {
emitDecoratorMetadata: true,
experimentalDecorators: true,
esModuleInterop: true,
skipLibCheck: true,
};

export const project = new Project({
Expand Down
1 change: 1 addition & 0 deletions packages/runtime/jest.config.ts
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/runtime",
"displayName": "ZenStack Runtime Library",
"version": "2.3.3",
"version": "2.4.0",
"description": "Runtime of ZenStack for both client-side and server-side environments.",
"repository": {
"type": "git",
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';
5 changes: 5 additions & 0 deletions packages/runtime/src/cross/model-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ export type ModelMeta = {
* Name of model that backs the `auth()` function
*/
authModel?: string;

/**
* Optional map from full names to shortened names, used for extra fields/relations generated by ZenStack
*/
shortNameMap?: Record<string, string>;
};

/**
Expand Down
19 changes: 15 additions & 4 deletions packages/runtime/src/enhancements/default-auth.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */

import { FieldInfo, NestedWriteVisitor, PrismaWriteActionType, enumerate, getFields, requireField } from '../cross';
import { clone } from '../cross';
import {
FieldInfo,
NestedWriteVisitor,
PrismaWriteActionType,
clone,
enumerate,
getFields,
requireField,
} from '../cross';
import { DbClientContract } from '../types';
import { EnhancementContext, InternalEnhancementOptions } from './create-enhancement';
import { DefaultPrismaProxyHandler, PrismaProxyActions, makeProxy } from './proxy';
import { isUnsafeMutate } from './utils';
import { isUnsafeMutate, prismaClientValidationError } from './utils';

/**
* Gets an enhanced Prisma client that supports `@default(auth())` attribute.
Expand Down Expand Up @@ -143,7 +150,11 @@ class DefaultAuthHandler extends DefaultPrismaProxyHandler {

private getDefaultValueFromAuth(fieldInfo: FieldInfo) {
if (!this.userContext) {
throw new Error(`Evaluating default value of field \`${fieldInfo.name}\` requires a user context`);
throw prismaClientValidationError(
this.prisma,
this.options.prismaModule,
`Evaluating default value of field \`${fieldInfo.name}\` requires a user context`
);
}
return fieldInfo.defaultValueProvider?.(this.userContext);
}
Expand Down
5 changes: 4 additions & 1 deletion packages/runtime/src/enhancements/delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,10 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
}

private makeAuxRelationName(model: ModelInfo) {
return `${DELEGATE_AUX_RELATION_PREFIX}_${lowerCaseFirst(model.name)}`;
const name = `${DELEGATE_AUX_RELATION_PREFIX}_${lowerCaseFirst(model.name)}`;
// make sure we look up into short name map to see if it's truncated
const shortName = this.options.modelMeta.shortNameMap?.[name];
return shortName ?? name;
}

private getModelName(model: string) {
Expand Down
Loading