Skip to content

Commit

Permalink
chore(perm-checker): rename filter clause to where (#1413)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored May 7, 2024
1 parent 0aa6ee9 commit 00250ea
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 78 deletions.
6 changes: 3 additions & 3 deletions packages/runtime/src/enhancements/policy/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type FindOperations = 'findUnique' | 'findUniqueOrThrow' | 'findFirst' | 'findFi
// input arg type for `check` API
type PermissionCheckArgs = {
operation: PolicyCrudKind;
filter?: Record<string, number | string | boolean>;
where?: Record<string, number | string | boolean>;
};

/**
Expand Down Expand Up @@ -1466,11 +1466,11 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
return constraint;
}

if (args.filter) {
if (args.where) {
// combine runtime filters with generated constraints

const extraConstraints: CheckerConstraint[] = [];
for (const [field, value] of Object.entries(args.filter)) {
for (const [field, value] of Object.entries(args.where)) {
if (value === undefined) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ModelCheckers {

function generateDataModelChecker(dataModel: DataModel) {
return `{
check(args: { operation: PolicyCrudKind, filter?: ${generateDataModelArgs(dataModel)} }): Promise<boolean>
check(args: { operation: PolicyCrudKind, where?: ${generateDataModelArgs(dataModel)} }): Promise<boolean>
}`;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/server/tests/api/rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('RPC API Handler Tests', () => {
r = await handleRequest({
method: 'get',
path: '/post/check',
query: { q: JSON.stringify({ operation: 'read', filter: { published: false } }) },
query: { q: JSON.stringify({ operation: 'read', where: { published: false } }) },
prisma: enhance(),
});
expect(r.status).toBe(200);
Expand All @@ -155,7 +155,7 @@ describe('RPC API Handler Tests', () => {
r = await handleRequest({
method: 'get',
path: '/post/check',
query: { q: JSON.stringify({ operation: 'read', filter: { authorId: '1', published: false } }) },
query: { q: JSON.stringify({ operation: 'read', where: { authorId: '1', published: false } }) },
prisma: enhance({ id: '1' }),
});
expect(r.status).toBe(200);
Expand Down
Loading

0 comments on commit 00250ea

Please sign in to comment.