⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
"test-integration": "pnpm run --filter=integration test --silent --forceExit",
"test-regression": "pnpm run --filter=regression test --silent --forceExit",
"test-scaffold": "tsx script/test-scaffold.ts",
"publish-all": "pnpm --filter \"./packages/**\" -r publish --access public",
"publish-all": "pnpm --filter \"./packages/**\" -r publish --access public --tag v2",
"publish-preview": "pnpm --filter \"./packages/**\" -r publish --force --registry https://preview.registry.zenstack.dev/",
"unpublish-preview": "pnpm --recursive --shell-mode exec -- npm unpublish -f --registry https://preview.registry.zenstack.dev/ \"\\$PNPM_PACKAGE_NAME\"",
"publish-next": "pnpm --filter \"./packages/**\" -r publish --access public --tag next",
"publish-preview-next": "pnpm --filter \"./packages/**\" -r publish --force --registry https://preview.registry.zenstack.dev/ --tag next",
"unpublish-preview-next": "pnpm --recursive --shell-mode exec -- npm unpublish -f --registry https://preview.registry.zenstack.dev/ --tag next \"\\$PNPM_PACKAGE_NAME\"",
"publish-test": "pnpm --filter \"./packages/**\" -r publish --access public --tag test"
Expand Down
17 changes: 13 additions & 4 deletions packages/runtime/src/enhancements/node/policy/policy-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import deepmerge from 'deepmerge';
import { z, type ZodError, type ZodObject, type ZodSchema } from 'zod';
import type { z, ZodError, ZodObject, ZodSchema } from 'zod';
import { z as zod3 } from 'zod/v3';
import { z as zod4 } from 'zod/v4';
import { CrudFailureReason, PrismaErrorCode } from '../../../constants';
import {
clone,
Expand Down Expand Up @@ -1376,17 +1378,19 @@ export class PolicyUtil extends QueryUtils {
let schema: ZodObject<any> | undefined;

const overridePasswordFields = (schema: z.ZodObject<any>) => {
const useZod: any = schema._def ? zod3 : zod4;

let result = schema;
const modelFields = this.modelMeta.models[lowerCaseFirst(model)]?.fields;
if (modelFields) {
for (const [key, field] of Object.entries(modelFields)) {
if (field.attributes?.some((attr) => attr.name === '@password')) {
// override `@password` field schema with a string schema
let pwFieldSchema: ZodSchema = z.string();
let pwFieldSchema: ZodSchema = useZod.string();
if (field.isOptional) {
pwFieldSchema = pwFieldSchema.nullish();
}
result = result.merge(z.object({ [key]: pwFieldSchema }));
result = result.merge(useZod.object({ [key]: pwFieldSchema }));
}
}
}
Expand Down Expand Up @@ -1540,7 +1544,12 @@ export class PolicyUtil extends QueryUtils {
continue;
}

if (fieldInfo.isDataModel && queryArgs?.include && typeof queryArgs.include === 'object' && !queryArgs.include[field]) {
if (
fieldInfo.isDataModel &&
queryArgs?.include &&
typeof queryArgs.include === 'object' &&
!queryArgs.include[field]
) {
// respect include
delete entityData[field];
continue;
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/validation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod';
import type { z } from 'zod';
import { getZodErrorMessage } from './local-helpers';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/zod-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { z as Z } from 'zod';
import type { z as Z } from 'zod';

/**
* A smarter version of `z.union` that decide which candidate to use based on how few unrecognized keys it has.
Expand Down
Loading