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
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": "1.6.1",
"version": "1.6.2",
"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 @@ -5,7 +5,7 @@ plugins {
}

group = "dev.zenstack"
version = "1.6.1"
version = "1.6.2"

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": "1.6.1",
"version": "1.6.2",
"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": "1.6.1",
"version": "1.6.2",
"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": "1.6.1",
"version": "1.6.2",
"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": "1.6.1",
"version": "1.6.2",
"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": "1.6.1",
"version": "1.6.2",
"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": "1.6.1",
"version": "1.6.2",
"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": "1.6.1",
"version": "1.6.2",
"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": "1.6.1",
"version": "1.6.2",
"description": "Runtime of ZenStack for both client-side and server-side environments.",
"repository": {
"type": "git",
Expand Down
5 changes: 0 additions & 5 deletions packages/runtime/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ export enum PrismaErrorCode {
DEPEND_ON_RECORD_NOT_FOUND = 'P2025',
}

/**
* Field name for storing in-transaction flag
*/
export const PRISMA_TX_FLAG = '$__zenstack_tx';

/**
* Field name for getting current enhancer
*/
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime/src/enhancements/omit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export interface WithOmitOptions extends CommonEnhancementOptions {
}

/**
* Gets an enhanced Prisma client that supports @omit attribute.
* Gets an enhanced Prisma client that supports "@omit" attribute.
*
* @deprecated Use {@link enhance} instead
*/
export function withOmit<DbClient extends object>(prisma: DbClient, options?: WithOmitOptions): DbClient {
const _modelMeta = options?.modelMeta ?? getDefaultModelMeta(options?.loadPath);
Expand Down
2 changes: 2 additions & 0 deletions packages/runtime/src/enhancements/password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface WithPasswordOptions extends CommonEnhancementOptions {

/**
* Gets an enhanced Prisma client that supports @password attribute.
*
* @deprecated Use {@link enhance} instead
*/
export function withPassword<DbClient extends object = any>(prisma: DbClient, options?: WithPasswordOptions): DbClient {
const _modelMeta = options?.modelMeta ?? getDefaultModelMeta(options?.loadPath);
Expand Down
8 changes: 4 additions & 4 deletions packages/runtime/src/enhancements/policy/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { lowerCaseFirst } from 'lower-case-first';
import invariant from 'tiny-invariant';
import { upperCaseFirst } from 'upper-case-first';
import { fromZodError } from 'zod-validation-error';
import { CrudFailureReason, PRISMA_TX_FLAG } from '../../constants';
import { CrudFailureReason } from '../../constants';
import {
ModelDataVisitor,
NestedWriteVisitor,
Expand Down Expand Up @@ -1232,11 +1232,11 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
}

private transaction(action: (tx: Record<string, DbOperations>) => Promise<any>) {
if (this.prisma[PRISMA_TX_FLAG]) {
if (this.prisma['$transaction']) {
return this.prisma.$transaction((tx) => action(tx), { maxWait: 100000, timeout: 100000 });
} else {
// already in transaction, don't nest
return action(this.prisma);
} else {
return this.prisma.$transaction((tx) => action(tx), { maxWait: 100000, timeout: 100000 });
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/runtime/src/enhancements/policy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export interface WithPolicyOptions extends CommonEnhancementOptions {
* @param context The policy evaluation context
* @param policy The policy definition, will be loaded from default location if not provided
* @param modelMeta The model metadata, will be loaded from default location if not provided
*
* @deprecated Use {@link enhance} instead
*/
export function withPolicy<DbClient extends object>(
prisma: DbClient,
Expand Down
2 changes: 2 additions & 0 deletions packages/runtime/src/enhancements/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { WithPolicyContext } from './policy';
* @param prisma The Prisma client to enhance.
* @param context The context to for evaluating access policies.
* @param options Options.
*
* @deprecated Use {@link enhance} instead
*/
export function withPresets<DbClient extends object>(
prisma: DbClient,
Expand Down
9 changes: 6 additions & 3 deletions packages/runtime/src/enhancements/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { PRISMA_PROXY_ENHANCER, PRISMA_TX_FLAG } from '../constants';
import { PRISMA_PROXY_ENHANCER } from '../constants';
import type { ModelMeta } from '../cross';
import type { DbClientContract } from '../types';
import { createDeferredPromise } from './policy/promise';
Expand Down Expand Up @@ -183,6 +183,7 @@ export function makeProxy<T extends PrismaProxyHandler>(
errorTransformer?: ErrorTransformer
) {
const models = Object.keys(modelMeta.fields).map((k) => k.toLowerCase());

const proxy = new Proxy(prisma, {
get: (target: any, prop: string | symbol, receiver: any) => {
// enhancer metadata
Expand All @@ -191,7 +192,7 @@ export function makeProxy<T extends PrismaProxyHandler>(
}

if (prop === 'toString') {
return () => `$zenstack_${name}[${target.toString()}]`;
return () => `$zenstack_prisma_${prisma._clientVersion}`;
}

if (prop === '$transaction') {
Expand All @@ -213,8 +214,10 @@ export function makeProxy<T extends PrismaProxyHandler>(

const txFunc = input;
return $transaction.bind(target)((tx: any) => {
// create a proxy for the transaction function
const txProxy = makeProxy(tx, modelMeta, makeHandler, name + '$tx');
txProxy[PRISMA_TX_FLAG] = true;

// call the transaction function with the proxy
return txFunc(txProxy);
}, ...rest);
};
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": "Build scalable web apps with minimum code by defining authorization and validation rules inside the data schema that closer to the database",
"version": "1.6.1",
"version": "1.6.2",
"author": {
"name": "ZenStack Team"
},
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": "1.6.1",
"version": "1.6.2",
"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": "1.6.1",
"version": "1.6.2",
"displayName": "ZenStack Server-side Adapters",
"description": "ZenStack server-side adapters",
"homepage": "https://zenstack.dev",
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": "1.6.1",
"version": "1.6.2",
"description": "ZenStack Test Tools",
"main": "index.js",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ describe('With Policy: with postgres', () => {

beforeEach(async () => {
dbUrl = await createPostgresDb(DB_NAME);
const { prisma: _prisma, withPolicy } = await loadSchemaFromFile(
const { prisma: _prisma, enhance } = await loadSchemaFromFile(
path.join(__dirname, '../../schema/todo-pg.zmodel'),
{
provider: 'postgresql',
dbUrl,
}
);
getDb = withPolicy;
getDb = enhance;
prisma = _prisma;
});

Expand Down