Skip to content

Commit aacc8e2

Browse files
committed
addressing PR comments
1 parent 98afd0e commit aacc8e2

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

packages/runtime/src/client/contract.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ export interface ClientConstructor {
213213
*/
214214
export type CRUD = 'create' | 'read' | 'update' | 'delete';
215215

216+
/**
217+
* CRUD operations.
218+
*/
219+
export const CRUD = ['create', 'read', 'update', 'delete'] as const;
220+
216221
//#region Model operations
217222

218223
export type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = {

packages/runtime/src/plugins/policy/functions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { invariant } from '@zenstackhq/common-helpers';
12
import { ExpressionWrapper, ValueNode, type Expression, type ExpressionBuilder } from 'kysely';
3+
import { CRUD } from '../../client/contract';
4+
import { extractFieldName } from '../../client/kysely-utils';
25
import type { ZModelFunction, ZModelFunctionContext } from '../../client/options';
3-
import { invariant } from '@zenstackhq/common-helpers';
46
import { buildJoinPairs, requireField } from '../../client/query-utils';
57
import { PolicyHandler } from './policy-handler';
6-
import type { CRUD } from '../../client/contract';
7-
import { extractFieldName } from '../../client/kysely-utils';
88

99
/**
1010
* Relation checker implementation.
@@ -25,7 +25,7 @@ export const check: ZModelFunction<any> = (
2525
'"operation" parameter must be a string literal when provided',
2626
);
2727
invariant(
28-
['create', 'read', 'update', 'delete'].includes(arg2Node.value),
28+
CRUD.includes(arg2Node.value as CRUD),
2929
'"operation" parameter must be one of "create", "read", "update", "delete"',
3030
);
3131
}

samples/blog/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ async function main() {
88
dialect: new SqliteDialect({ database: new SQLite('./zenstack/dev.db') }),
99
computedFields: {
1010
User: {
11-
postCount: (eb, { currentModel }) =>
11+
postCount: (eb, { modelAlias }) =>
1212
eb
1313
.selectFrom('Post')
14-
.whereRef('Post.authorId', '=', sql.ref(`${currentModel}.id`))
14+
.whereRef('Post.authorId', '=', sql.ref(`${modelAlias}.id`))
1515
.select(({ fn }) => fn.countAll<number>().as('postCount')),
1616
},
1717
},

0 commit comments

Comments
 (0)