Skip to content

merge dev to main (v2.13.1) #2068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 4, 2025
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
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.13.0",
"version": "2.13.1",
"description": "",
"scripts": {
"build": "pnpm -r --filter=\"!./packages/ide/*\" build",
Expand Down
6 changes: 6 additions & 0 deletions packages/ide/jetbrains/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

- Support `@default` for `@json` fields.

### Fixed

## 2.12.1

### Added

- Validating regex patterns in ZModel.
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.13.0"
version = "2.13.1"

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.13.0",
"version": "2.13.1",
"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.13.0",
"version": "2.13.1",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
2 changes: 1 addition & 1 deletion 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.13.0",
"version": "2.13.1",
"description": "CLI and runtime for integrating ZenStack with RedwoodJS projects.",
"repository": {
"type": "git",
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.13.0",
"version": "2.13.1",
"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.13.0",
"version": "2.13.1",
"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.13.0",
"version": "2.13.1",
"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.13.0",
"version": "2.13.1",
"description": "ZenStack plugin for tRPC",
"main": "index.js",
"repository": {
Expand Down
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.13.0",
"version": "2.13.1",
"description": "Runtime of ZenStack for both client-side and server-side environments.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publisher": "zenstack",
"displayName": "ZenStack Language Tools",
"description": "FullStack enhancement for Prisma ORM: seamless integration from database to UI",
"version": "2.13.0",
"version": "2.13.1",
"author": {
"name": "ZenStack Team"
},
Expand Down
36 changes: 24 additions & 12 deletions packages/schema/src/plugins/enhancer/enhance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ ${

${
prismaTypesFixed
? this.createLogicalPrismaImports(prismaImport, resultPrismaImport)
: this.createSimplePrismaImports(prismaImport)
? this.createLogicalPrismaImports(prismaImport, resultPrismaImport, target)
: this.createSimplePrismaImports(prismaImport, target)
}

${authTypes}
Expand Down Expand Up @@ -206,8 +206,10 @@ ${
return normalizedRelative(this.outDir, zodAbsPath);
}

private createSimplePrismaImports(prismaImport: string) {
return `import { Prisma, type PrismaClient } from '${prismaImport}';
private createSimplePrismaImports(prismaImport: string, target: string) {
const prismaTargetImport = target === 'edge' ? `${prismaImport}/edge` : prismaImport;

return `import { Prisma, type PrismaClient } from '${prismaTargetImport}';
import type * as _P from '${prismaImport}';
export type { PrismaClient };

Expand Down Expand Up @@ -235,8 +237,9 @@ export function enhance<DbClient extends object>(prisma: DbClient, context?: Enh
`;
}

private createLogicalPrismaImports(prismaImport: string, prismaClientImport: string) {
return `import { Prisma as _Prisma, PrismaClient as _PrismaClient } from '${prismaImport}';
private createLogicalPrismaImports(prismaImport: string, prismaClientImport: string, target: string) {
const prismaTargetImport = target === 'edge' ? `${prismaImport}/edge` : prismaImport;
return `import { Prisma as _Prisma, PrismaClient as _PrismaClient } from '${prismaTargetImport}';
import type { InternalArgs, DynamicClientExtensionThis } from '${prismaImport}/runtime/library';
import type * as _P from '${prismaClientImport}';
import type { Prisma, PrismaClient } from '${prismaClientImport}';
Expand Down Expand Up @@ -824,12 +827,21 @@ export type Enhanced<Client> =
};

const replacePrismaJson = (source: string, field: DataModelField) => {
return source.replace(
new RegExp(`(${field.name}\\??\\s*):[^\\n]+`),
`$1: ${field.type.reference!.$refText}${field.type.array ? '[]' : ''}${
field.type.optional ? ' | null' : ''
}`
);
let replaceValue = `$1: ${field.type.reference!.$refText}`;
if (field.type.array) {
replaceValue += '[]';
}
if (field.type.optional) {
replaceValue += ' | null';
}

// Check if the field in the source is optional (has a `?`)
const isOptionalInSource = new RegExp(`(${field.name}\\?\\s*):`).test(source);
if (isOptionalInSource) {
replaceValue += ' | $Types.Skip';
}

return source.replace(new RegExp(`(${field.name}\\??\\s*):[^\\n]+`), replaceValue);
};

// fix "$[Model]Payload" type
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/sdk",
"version": "2.13.0",
"version": "2.13.1",
"description": "ZenStack plugin development SDK",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/server",
"version": "2.13.0",
"version": "2.13.1",
"displayName": "ZenStack Server-side Adapters",
"description": "ZenStack server-side adapters",
"homepage": "https://zenstack.dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,6 @@ class RequestHandler extends APIHandlerBase {
}

const items: any[] = [];
let currType = typeInfo;

for (const [key, value] of Object.entries(query)) {
if (!value) {
Expand All @@ -1554,6 +1553,7 @@ class RequestHandler extends APIHandlerBase {

const item: any = {};
let curr = item;
let currType = typeInfo;

for (const filterValue of enumerate(value)) {
for (let i = 0; i < filterKeys.length; i++) {
Expand Down
20 changes: 20 additions & 0 deletions packages/server/tests/api/rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,26 @@ describe('REST server tests', () => {
prisma,
});
expect(r.body.data).toHaveLength(0);
r = await handler({
method: 'get',
path: '/post',
query: {
['filter[author][email]']: '[email protected]',
['filter[title]']: 'Post1',
},
prisma,
});
expect(r.body.data).toHaveLength(1);
r = await handler({
method: 'get',
path: '/post',
query: {
['filter[author][email]']: '[email protected]',
['filter[title]']: 'Post2',
},
prisma,
});
expect(r.body.data).toHaveLength(0);

// to-one relation filter
r = await handler({
Expand Down
2 changes: 1 addition & 1 deletion packages/testtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/testtools",
"version": "2.13.0",
"version": "2.13.1",
"description": "ZenStack Test Tools",
"main": "index.js",
"private": true,
Expand Down
62 changes: 62 additions & 0 deletions tests/integration/tests/enhancements/json/crud.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,66 @@ describe('Json field CRUD', () => {

await expect(post.content.content[0].content[0].text).toBe('hello');
});

it('works with Prisma.skip', async () => {
const params = await loadSchema(
`
type Profile {
foo Int
bar String
}

model User {
id Int @id @default(autoincrement())
name String
profile Profile @json
@@allow('all', true)
}
`,
{
provider: 'postgresql',
dbUrl,
compile: true,
extraSourceFiles: [
{
name: 'main.ts',
content: `
import { enhance } from '.zenstack/enhance';
import { Prisma, PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const db = enhance(prisma);

async function main() {
// @ts-expect-error Non optional JSON fields should not be skippable in the create call
db.user.create({ data: { name: 'test', profile: Prisma.skip } });

const u = await db.user.create({ data: { name: 'test', profile: { foo: 18, bar: 'test' } } });
await db.user.update({ where: { id: u.id }, data: { profile: Prisma.skip } });
}
`,
},
],
}
);

prisma = params.prisma;
const skip = params.prismaModule.Prisma.skip;
const db = params.enhance();

const user = await db.user.create({ data: { name: 'test', profile: { foo: 18, bar: 'test' } } });

await expect(
db.user.update({
where: { id: user.id },
data: { profile: skip },
})
).resolves.toMatchObject({
id: user.id,
name: 'test',
profile: {
foo: 18,
bar: 'test',
},
});
});
});
Loading