Skip to content
Closed
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
16 changes: 8 additions & 8 deletions .github/release/.release-manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
".": "2.0.0-alpha.1",
".": "2.0.0-alpha.2",
"packages/ide/jetbrains": "2.0.0-alpha.2",
"packages/language": "2.0.0-alpha.2",
"packages/misc/redwood": "2.0.0-alpha.2",
"packages/plugins/openapi": "2.0.0-alpha.2",
"packages/plugins/swr": "2.0.0-alpha.2",
"packages/plugins/tanstack-query": "2.0.0-alpha.2",
"packages/plugins/trpc": "2.0.0-alpha.2",
"packages/runtime": "2.0.0-alpha.2",
"packages/sdk": "2.0.0-alpha.2",
"packages/plugins/openapi": "2.0.0-alpha.3",
"packages/plugins/swr": "2.0.0-alpha.3",
"packages/plugins/tanstack-query": "2.0.0-alpha.3",
"packages/plugins/trpc": "2.0.0-alpha.3",
"packages/runtime": "2.0.0-alpha.3",
"packages/sdk": "2.0.0-alpha.3",
"packages/server": "2.0.0-alpha.2",
"packages/testtools": "2.0.0-alpha.2"
"packages/testtools": "2.0.0-alpha.3"
}
25 changes: 21 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# 0.5.0 (2022-12-15)
# Changelog

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92))
* default auth without user context ([#1015](https://github.com/zenstackhq/zenstack/issues/1015)) ([e5b5a0f](https://github.com/zenstackhq/zenstack/commit/e5b5a0fee34e46bee5557229f6f5894629c6ad96))
* foreign key constraint ambiguity in generated delegate prisma schema ([#1060](https://github.com/zenstackhq/zenstack/issues/1060)) ([ca2a314](https://github.com/zenstackhq/zenstack/commit/ca2a314a927053703e4dbc76542499159b8bf6a8))
* **polymorphism:** support `orderBy` with base fields ([d345b80](https://github.com/zenstackhq/zenstack/commit/d345b80846974355ee55cc4e5c806d53f144e89a))


### Performance Improvements

* improve polymorphism code generation speed ([#1073](https://github.com/zenstackhq/zenstack/issues/1073)) ([5b103ba](https://github.com/zenstackhq/zenstack/commit/5b103badea7876b7dfc1da91c26eca3213ddd413))

## 0.5.0 (2022-12-15)

### Features

Expand All @@ -12,7 +29,7 @@

- Next-auth adapter and helper are moved to a separate package `@zenstackhq/next-auth`.

# 0.4.0 (2022-12-01)
## 0.4.0 (2022-12-01)

### Features

Expand Down Expand Up @@ -50,7 +67,7 @@

Use @zenstackhq/runtime/types for type definitions shared between client and server, @zenstackhq/runtime/client for client-specific libaries (like React hooks), and @zenstackhq/runtime/server for server-specific libraries.

# 0.3.0 (2022-11-08)
## 0.3.0 (2022-11-08)

### Features

Expand All @@ -70,7 +87,7 @@

- Better overall documentation

# 0.2.0 (2022-10-29)
## 0.2.0 (2022-10-29)

### Features

Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/openapi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92))

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21)


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.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/swr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92))

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21)


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.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "ZenStack plugin for generating SWR hooks",
"main": "index.js",
"repository": {
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/tanstack-query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92))

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21)


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.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "ZenStack plugin for generating tanstack-query hooks",
"main": "index.js",
"exports": {
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/trpc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92))

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21)


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.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "ZenStack plugin for tRPC",
"main": "index.js",
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions packages/runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92))
* default auth without user context ([#1015](https://github.com/zenstackhq/zenstack/issues/1015)) ([e5b5a0f](https://github.com/zenstackhq/zenstack/commit/e5b5a0fee34e46bee5557229f6f5894629c6ad96))
* **polymorphism:** support `orderBy` with base fields ([d345b80](https://github.com/zenstackhq/zenstack/commit/d345b80846974355ee55cc4e5c806d53f144e89a))

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21)


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.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "Runtime of ZenStack for both client-side and server-side environments.",
"repository": {
"type": "git",
Expand Down
34 changes: 22 additions & 12 deletions packages/runtime/src/enhancements/delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
this.injectWhereHierarchy(model, args?.where);
this.injectSelectIncludeHierarchy(model, args);

if (args.orderBy) {
// `orderBy` may contain fields from base types
args.orderBy = this.buildWhereHierarchy(this.model, args.orderBy);
}

if (this.options.logPrismaQuery) {
this.logger.info(`[delegate] \`${method}\` ${this.getModelName(model)}: ${formatObject(args)}`);
}
Expand Down Expand Up @@ -126,19 +131,19 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
});
}

private buildWhereHierarchy(where: any) {
private buildWhereHierarchy(model: string, where: any) {
if (!where) {
return undefined;
}

where = deepcopy(where);
Object.entries(where).forEach(([field, value]) => {
const fieldInfo = resolveField(this.options.modelMeta, this.model, field);
const fieldInfo = resolveField(this.options.modelMeta, model, field);
if (!fieldInfo?.inheritedFrom) {
return;
}

let base = this.getBaseModel(this.model);
let base = this.getBaseModel(model);
let target = where;

while (base) {
Expand Down Expand Up @@ -173,12 +178,17 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {

for (const kind of ['select', 'include'] as const) {
if (args[kind] && typeof args[kind] === 'object') {
for (const [field, value] of Object.entries(args[kind])) {
if (value !== undefined) {
for (const [field, value] of Object.entries<any>(args[kind])) {
const fieldInfo = resolveField(this.options.modelMeta, model, field);
if (fieldInfo && value !== undefined) {
if (value?.orderBy) {
// `orderBy` may contain fields from base types
value.orderBy = this.buildWhereHierarchy(fieldInfo.type, value.orderBy);
}

if (this.injectBaseFieldSelect(model, field, value, args, kind)) {
delete args[kind][field];
} else {
const fieldInfo = resolveField(this.options.modelMeta, model, field);
if (fieldInfo && this.isDelegateOrDescendantOfDelegate(fieldInfo.type)) {
let nextValue = value;
if (nextValue === true) {
Expand Down Expand Up @@ -847,15 +857,15 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
args = deepcopy(args);

if (args.cursor) {
args.cursor = this.buildWhereHierarchy(args.cursor);
args.cursor = this.buildWhereHierarchy(this.model, args.cursor);
}

if (args.orderBy) {
args.orderBy = this.buildWhereHierarchy(args.orderBy);
args.orderBy = this.buildWhereHierarchy(this.model, args.orderBy);
}

if (args.where) {
args.where = this.buildWhereHierarchy(args.where);
args.where = this.buildWhereHierarchy(this.model, args.where);
}

if (this.options.logPrismaQuery) {
Expand All @@ -875,11 +885,11 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
args = deepcopy(args);

if (args?.cursor) {
args.cursor = this.buildWhereHierarchy(args.cursor);
args.cursor = this.buildWhereHierarchy(this.model, args.cursor);
}

if (args?.where) {
args.where = this.buildWhereHierarchy(args.where);
args.where = this.buildWhereHierarchy(this.model, args.where);
}

if (this.options.logPrismaQuery) {
Expand Down Expand Up @@ -915,7 +925,7 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
args = deepcopy(args);

if (args.where) {
args.where = this.buildWhereHierarchy(args.where);
args.where = this.buildWhereHierarchy(this.model, args.where);
}

if (this.options.logPrismaQuery) {
Expand Down
7 changes: 7 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92))

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21)


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.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "ZenStack plugin development SDK",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions packages/testtools/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-06)


### Bug Fixes

* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92))

## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21)


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.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "ZenStack Test Tools",
"main": "index.js",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,41 @@ describe('Polymorphism Test', () => {
expect(imgAsset.owner).toMatchObject(user);
});

it('order by base fields', async () => {
const { db, user } = await setup();

await expect(
db.video.findMany({
orderBy: { viewCount: 'desc' },
})
).resolves.toHaveLength(1);

await expect(
db.ratedVideo.findMany({
orderBy: { duration: 'asc' },
})
).resolves.toHaveLength(1);

await expect(
db.user.findMany({
orderBy: { assets: { _count: 'desc' } },
})
).resolves.toHaveLength(1);

await expect(
db.user.findUnique({
where: { id: user.id },
include: {
ratedVideos: {
orderBy: {
viewCount: 'desc',
},
},
},
})
).toResolveTruthy();
});

it('update simple', async () => {
const { db, videoWithOwner: video } = await setup();

Expand Down